Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Similar presentations


Presentation on theme: "Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store."— Presentation transcript:

1 Introduction ABAP Fields and Variables

2 Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store data that might change Constants store data that does not change As before, fields are declared with the DATA keyword KEEP IN MIND THAT ABAP IS A ‘BUSINESS’ PROGRAMMING LANGUAGE

3 Slide 3 Field Naming Field names must begin with a letter or underscore character Subsequent characters can be digits 30 character maximum variable length Avoid special characters Don’t use anything but an underscore Don’t use a dash for reasons you will discover shortly Cannot be reserved words

4 Slide 4 Fields (Characteristics) They nave a name A defined length And a data type And possibly a length And possibly an initial value

5 Slide 5 Fields (Primary Data Types)

6 Slide 6 Data Types and the ABAP Dictionary ABAP data types and ABAP dictionary data types are not exactly the same Dictionary types map to more simple ABAP types See handout

7 Slide 7 Numeric Data Types (1) Integer numbers are whole number having a value range between -2**31 to 2**31-1 Results are rounded not truncated Floating point numbers (data type F) are similar to IEEE floating point numbers They are converted to a binary value and are subject to rounding error

8 Slide 8 Numeric Data Types (2) Packed numbers (data type P) use an internal SAP format The size is program defined between 1 and 16 bits Each digit occupies 4 bits So two decimal digits are packed into one byte Up to 14 digits allowed after the decimal point Make sure that fixed-point arithmetic is set. otherwise values are treated as integers P fields are slow

9 Slide 9 Declaring Variables (1) The DATA statement declares a variable Syntax: DATA VARNAME TYPE DATATYPE [VALUE INITIALVALUE]. Example: Declare an integer having an initial value of 5. DATA IntValue1 TYPE I VALUE 5.

10 Slide 10 Packed Numbers (Example) DATA packed16 TYPE P LENGTH 7 DECIMALS 2. packed16 = '12121219.12'. WRITE packed16. Produces

11 Slide 11 LIKE Declare a variable having the dame data type as another variable Makes it easier to change data types DATA demo16instance1 LIKE packed16. DATA demo16instance2 LIKE packed16.

12 Slide 12 Arithmetic Operators are as usual +, -, /, * Use DIV for integer division and MOD for integer remainder THERE MUST BE A BLANK CHARACTER BEFORE AND AFTER THE ‘=‘ SIGN AND BETWEEN ARITHMETIC OPERATORS AND PARENTHESIS

13 Slide 13 Arithmetic (Type Conversion) Looks like any other arithmetic expression (plus the space requirements) SAP calls this compatible and convertible data types Compatible types have the same data type, field type, … Comparable types are converted using conversion rules (See handout)

14 Slide 14 Type Coercion (1) The following produces “1” because the result is rounded to an int

15 Slide 15 Type Coercion (2) Floating point data (F, P) are rounded and converted to integers Floating point numbers are rounded when converted to packed values When converting character fields to numbers, the source field must contain a valid number More about dates later

16 Slide 16 Numeric Overflow Outcome

17 Slide 17 System Fields System fields are constants defined by the system SY-SUBRC – return code of a procedure SY-UNAME – logon name of the user SY-DATUM – current date SY-UZEIT – current type SY-TCODE – current transaction code

18 Slide 18 Constants The CONSTANTS statement declares a constant CONSTANTS pi TYPE P LENGTH 15 DECIM ALS 14 VALUE '3.14159'.


Download ppt "Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store."

Similar presentations


Ads by Google