7/23/2018 - 7:48 PM

Declare fields, constants, work area (DATA, CONSTANTS, TYPE)

Used to declare variables. TYPE statement is used to indicate which data type the variable has. The DECIMALS statement is used with packed decimal data types to indicate how many decimals a variable has. Can also use LIKE statement to declare variables based on other variables or fields of tables. Copies their data type. Makes sure the new variable/field has exactly the same properties defined for the variable/field after the LIKE statement. Saves time: let's you automatically update multiple variables/fields at once by only having to update the variable/field after the LIKE statement. Add VALUE statement to give the variable an initial value (initialization). Packed data types need to have the value between within single quotes, because ABAP statements are terminated at periods and packed values need periods to mark a decimal. When specifying decimals use quotes. Constants are fixed-value data objects, used a lot in ABAP. Constants are declared using the CONSTANTS statement, and do not change during the course of the entire program but can be referenced. When you declare a constant you must assign a VALUE to that field. Trying to change a constant creates a runtime error. You cannot define constants for data types XSTRINGS, for references, internal tables or structures containing internal tables

Data types: Elementary (have a fixed length, so do not need to declare how long the variable will be) integer = i packed = p (can store up to 14 decimal places) Character string elementary/generic types: alphanumeric = c (1-65535 length of characters), default value = 1, so do not necessarily need to type the length (long form), system default type = c, so you can even omit the type

CONSTANTS (declared the same way as a variable, but must contain a VALUE)

DATA variablename TYPE datatype.

DATA variablename TYPE datatype VALUE initialvalue.

DATA packed_decimal01 TYPE p DECIMALS 2.

DATA packed_decimal01 TYPE p DECIMALS 2 VALUE '5.5'.

DATA packed_decimal02 LIKE packed_decimal01.
DATA packed_decimal03 LIKE packed_decimal01.

DATA new_tablefield LIKE ztable-oldtablefield.

*Declare a work area
DATA wa_tablename LIKE ztablename.