Download presentation
Presentation is loading. Please wait.
Published byPrimrose Hamilton Modified over 9 years ago
1
MIS 3020 ABAP Programming Lecture 2 Elementary & User Defined Types Domains, Elements, Variables/Fields
2
Objectives To introduce : ABAP elementary and user defined data types keywords used to declare data items complex record structures the use of internal tables in ABAP declaring an internal table populating fields of an internal table the ABAP data dictionary domains, elements & tables integrity constraints
3
ABAP Data Types Elementary Data Types User Defined Types
4
ABAP Data Types & Structures Elementary Types supported by ABAP characters numbers Date Time Hexadecimal Non- Elementary Types ( User Defined Structures) records internal tables
5
Character Types c character default type when none is specified used for regular text information pads right end with spaces n numeric text contains strings of digits used for numbers that are used for identification and as sort criteria for internal tables house numbers, postcodes, phone numbers,... pads left end with zeros
6
Number Types iintegers fixed length of 4 bytes possible values range from 2 -31 to 2 31 -1 ppacked numbers stored in compressed formats, ie, 2 digits per byte of storage. can be used for all types of calculations ffloating point possible range from 1E-307 to 1E307 can be used in all types of calculations but beware of rounding errors. (Don’t use in eq condition tests)
7
Date Type ddate fixed length of 8 and internal representation of YYYYMMDD several output formats supported set default output format in your User Profile/Defaults can specify different/specific output format when writing value out supports date arithmetic
8
Time Type ttime fixed length of 6 and format HHMMSS several output formats supported can specify different/specific output format when writing value out supports time arithmetic
9
Hexadecimal Type xhexadecimal values in hexadecimal fields are stored in binary (bit stream) format eg ‘F089’ would be stored as 1111000010001001 2 hex digits are stored in 1 storage byte
10
Elementary Types & Default Lengths and Values TypeLengthInitial Value c 1space n 1‘0’ i 4 0 p 8 0 f 8 0.0 d 8‘00000000’ t 6‘000000’ x 1X’00’
11
The ABAP Statement most ABAP statements begins with a reserved keyword, e.g. data, types, select all end with a period (.) can combine a sequence of statements starting with the same keywords into a single statement using colon and comma (for most keywords)
12
The data keyword variables are declared using the data keyword data varname[(len)] type typedef [value val]. data postcode(4) type n value ‘4001’. data counter type i value 1. data price type p decimals 2. data varname like objname [value val]. where objname is a previously declared item (or database object) data DOB like sy-datum.
13
The data statement multiple variable declarations can be made in the same data statement by using data: data: DOB like sy-datum, counter type i.
14
The parameters keyword PARAMETERS: P1 TYPE P, P2(6) TYPE C DEFAULT ‘ITB255’. PARAMETERS TYPE [DEFAULT ]. X P1 P2 ITB255 Selection Screen
15
The constants keyword Constants are declared like fields with the addition of the value clause. constants: max_counter type i value 9999. A constant cannot be changed trying to change the value of a constant will result in a runtime error (if the change can only be detected at runtime, ie, if the constant is used as an actual parameter)
16
Records (or Structures) records consist of a fixed number of data objects called components of the record declared using data begin of and data end of data: begin of student, stnum(8)type n, stname(25)type c, stDOBlike sy-datum, stphone(12)type n, end of student.
17
Working With Records components of records are referenced by recordname-componentname data IT_student like student. student-stnum = ‘12345678’. student-stname = ‘F.Jones’. student-stDOB = ‘19790623’. student-stphone = ‘3221 1278’. move student to IT_student.
18
The types keyword used to create a user defined type types: begin of student_type, stnum(8)type n, stname(25)type c, stDOBlike sy-datum, stphone(12)type n, end of student_type. data: student_rec type student_type, student_tab type student_type occurs 0.
19
The tables keyword tables, e.g. tables spfli Creates a structure in the program work area with the same: name row structure field names, datatype, sequence as the referenced database table, structure or view
20
Internal Tables used as snapshots of database tables containers for volatile data exist only at runtime, (unlike database tables) consist of any number of records declared using occurs n data student_tab like student occurs 0. data student_tab like student occurs 0 with header line. note that it is not necessary to declare the exact size of the table: SAP’s memory management allows the table to be ‘infinitely’ extensible.
21
Internal Tables – with header line Program Work Area R/3 Database a record structure of the same name is automatically created
22
Internal Tables – without header line Program Work Area R/3 Database need to define a record structure explicitly in your abap program
23
Internal Tables - header lines advantages of header lines convenient declaration table and header line structure declared in same statement ease of use don’t have to explicitly move data into the work area structure and then append the work area structure to the table some statements require a table with header line disadvantages of header lines performance - I/O is faster for tables without header line cannot use in embedded structure
24
Internal Tables - header lines default declaration is without a header line to declare a table with a header line data: itab {type tabtype | like objname} occurs n with header line data book_tab like sbook occurs 0 with header line.
25
More Complex Structures It is possible to create nested structures a structure can contain another structure a record can contain an internal table as one of its components a table can contain another table, etc types: begin of addr_type, city(25), street(30), end of addr_type, begin of person, name(25), address type addr_type, end of person. data: emp type person. emp-address-city = ‘Sydney’.
26
The Data Dictionary Domains Data Elements Tables & Structures
27
3 Levels of the Dictionary Tables or Structures composed of one or more fields Data Elements each field refers to a data element that describes the meaning of the field Domain determines the technical properties of the field data type and size (including number of decimal places) allowed data values output characteristics
28
Elements and Domains Domain provides the technical description Element determines the role played create a domain called ID_Number create elements Student_ID and Staff_ID based on the ID_Number domain
29
Data Element Definition Referential Integrity Check Data Element Definition Referential Integrity Check
30
Field Information
31
Define the text to be displayed on screen or report Domain Definition
32
Range/Value Integrity Check
33
Integrity Checking Domain Range/Value Integrity Checks value table only values contained in the value table can be entered in fields referring to this domain fixed values only values that match a value in the user specified list of admissible values can be entered in fields referring to this domain
34
Integrity Checking Referential Integrity Checking check table foreign key values must match an entry in the specified check table check tables bound to input fields on data entry screens position the cursor on input field and press F4 to get a list of permissible values the default check table for a field is the value table of the underlying domain from the “Dictionary: Table/Structure: Display Fields” screen, Select GoTo…Foreign Keys (F8)
35
Foreign Key value must match Primary Key value of the check table Cardinality Ratio of Foreign Key Scroll Through Other Defined Foreign Keys
36
Viewing the Contents of a Database Table From the Data Dictionary Click on the Table Radio Button & enter the Table Name From the Dictionary Table: Table/Structure: Display Fields screen choose Utilities…Table Contents Data Browser (from main menu item Overview) Enter the Table Name Choose Table…Table Contents or press Enter Fill in the appropriate Selection Screen entries Click on the Execute icon on the application toolbar, (or press F8)
37
Table Name Number of Rows Selected Sort Buttons
38
Conclusion This lecture covered aspects of defining identifiers in an ABAP program the data dictionary In particular we covered the basic data types supported by ABAP character, number, integer, float, packed, date, time, hexadecimal We also discussed user defined structures records, tables
39
Conclusion User defined structures are declared using the types keyword. Identifiers are declared using the data keyword the parameters keyword Constants are declared using the constants keyword. The datatype of an identifier can be specified using type specific type like previously defined identifier/dictionary object
40
Conclusion Structures records defined by data begin of / data end of internal tables defined using occurs complex structures can be created by nesting records and internal tables
41
Conclusion The second half of the lecture covered Data Dictionary Organization of Data in the Dictionary Domain Elements Tables/Structures Using the Dictionary to see the definitions of Domains, Elements, Tables the contents of Tables How the Dictionary maintains Value and Referential Integrity
42
Related Reading Online Help R/3 Library...Basis Components... ABAP Workbench BC ABAP Users Guide The ABAP Programming Language … Basic Statements … Declaring Data … Creating Data Objects and Data Types The DATA Statement BC ABAP Dictionary …Tables BC ABAP Dictionary … Data Elements BC ABAP Dictionary … Domains
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.