1 / 18

Introduction ABAP Fields and Variables

Introduction ABAP Fields and Variables. 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

Download Presentation

Introduction ABAP Fields and Variables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction ABAP Fields and Variables

  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. 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. Fields (Characteristics) • They nave a name • A defined length • And a data type • And possibly a length • And possibly an initial value

  5. Fields (Primary Data Types)

  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. 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. 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. 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. Packed Numbers (Example) DATA packed16 TYPE P LENGTH 7 DECIMALS 2.packed16 = '12121219.12'.WRITE packed16. • Produces

  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. 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. 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. Type Coercion (1) • The following produces “1” because the result is rounded to an int

  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. Numeric Overflow Outcome

  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. Constants • The CONSTANTS statement declares a constant CONSTANTS pi TYPE P LENGTH 15 DECIMALS 14 VALUE '3.14159'.

More Related