Elementary Data Types There are 10 pre-defined or “built-in” data types in ABAP. Numeric Data: P suitable for amounts of money, lengths and weights ; I suitable for counters and quantities ; F suitable for calculations involving very large values .
Elementary Data Types The data statement is used to define variables in an ABAP program. Variable names can be 1 to 30 characters long. Character or text fields are type c. This is the default type when no type is specified. The city and flag fields both default to type c. Fields of type n (numeric text) are appropriate for numbers used for identification. E.g. Postcodes, account numbers, student numbers . Type n fields pad the left side with zeros What would be the output of the write statement in the slide? 0006980 Numbers: Integers (type i) mainly used for counting Packed numbers (type p) used for values with a constant number of decimal places, such as prices.
User-defined Data Types The first approach on the slide uses the like for referencing a variable. The variable vendor_name inherits all attributes (type c and length 25) from the variable customer_name . Changes to the definition of the customer_name automatically cause the same changes in the definition of vendor_name . Where does the variable carridcode gets its attributes from? (Data Dictionary) You can refer to fields in the ABAP Dictionary that come with the R/3 system. What is the advantage of this? (Consistency and efficiency) The Dictionary’s active integration ensures that all changes to the definitions of fields are automatically forwarded to all programs using those fields, so your references will always access the most current information. Using the Dictionary is highly recommended - it allows large program systems to be developed using correct consistent information. The second approach on the slide makes reference to the types statement. The definition used for type t_name is applied to both the customer_name and vendor_names fields, and any change to the t_ name definition automatically causes the same change in the definitions of both fields. The last example: carridcode type s_carr_id illustrates that type can reference the DD via naming a data element.
Structure (was referred to as a Field Strings in previous versions) In the above example the field string customer contains 3 variables - id fname and l name. Information has been added for each of the fields. What is the output from the write statements? Can you see an application for field strings? (dates) To make variables reusable in other programs (global) you can define them as structures in the Dictionary, making them automatically available in all ABAP programs. Have you used any variables in your workshop exercises that were not defined in your program ? (system variables - these have been defined in an object called a structure in the Dictionary and are available to all programs. )
Lecture04 abap on line
Lecture 4 Local Data Types and Definitions BCO5647 Applications Programming Techniques (ABAP)
Readings & Objectives <ul><li>Readings </li></ul><ul><li>Keller & Kruger Chapter 4 Pages 87 – 103 </li></ul><ul><li>Objectives This lecture will </li></ul><ul><li>Introduce Local Data Types in ABAP </li></ul><ul><li>Identify the ten Elementary Data Types in ABAP </li></ul><ul><li>Examine User-defined Data Types </li></ul><ul><li>Introduce the Structure concept with local and global definitions. </li></ul>
Local Data - Data Type <ul><li>A data field in ABAP is a variable which cannot be broken up into smaller parts. </li></ul><ul><li>All data fields that are to be used in a program must be defined before their first use. </li></ul><ul><li>Data fields in an ABAP program have a type . </li></ul><ul><li>E.g. You can define a data field student_name of type character and length 25 as: data student_name(25) type c. </li></ul>
Local Data : Elementary Data Types <ul><li>There are ten “built-in” data types in ABAP. </li></ul>Since SAP R/3 4.6 ABAP offers two variable length built-in elementary data types STRING and XSTRING : DATA: text-string TYPE string text-string = ‘ABAP programming is FUN!’ XSTRING can contain the hexadecimal content of a byte sequence.
Elementary Data Types <ul><li>data: name(25) type c, city(25) , flag. </li></ul><ul><li>data: student_id(7) type n value ‘6980’. </li></ul><ul><li>write student_id. </li></ul><ul><li>data: book_price type p decimals 2. </li></ul>
User-defined Data Types <ul><li>You can make reference to an existing variable using like . data: customer_name(25) type c, vendor_name like customer_name, carridcode like spfli-carrid. </li></ul><ul><li>You can create your own data types and apply them to variables. types: t_name(25) type c. data: customer_name type t_name, vendor_name type t_name, carridcode type s_carr_id. </li></ul>
Structure <ul><li>Structures consist of a series of variables grouped together under a common name. </li></ul><ul><li>Structures are defined using the keywords begin of and end of . data: begin of customer, id(8) type n, f name( 1 2), lname(15), end of customer. customer-id = ‘12345678’. customer- f name = ‘ Christain ’. customer- l name = ‘ Wong ’. write / customer. write: / customer-id, customer-fname, customer-lname. </li></ul>
Structure <ul><li>You can define a structure type locally using the TYPE statement. </li></ul><ul><li>Structures can be used to set up a work area to store database table record. </li></ul>