Declarations
Declaration Contexts
Data types and data objects are declared for one of the following contexts using declarative statements or inline declarations:
-
ABAP programs:
Declarative statements in the global declaration section define data types and data objects that are valid during the runtime of the program and visible in the entire program.
-
Classes:
Declarative statements in the declaration section of a class define data types and data objects (attributes) of a class and define their visibility.
-
Instance attributes are valid during the lifetime of an instance of the class (object).
-
Static attributes are valid from the first time the class is accessed until the end of the program.
-
-
Procedures:
Declarative statements in a procedure define local data types and data objects that are valid during the runtime of the procedure and only visible there. Inline declarations declare data objects in operand positions within a procedure.
Declarative Statements and Inline Declarations
The most important declarative statements for data types and data objects (with virtually identical syntax) are:
-
TYPES for data types
-
DATA for variables
-
CONSTANTS for constants
Furthermore, inline declarations using the operator DATA(…) are available, which are used to declare data objects in specific operand positions.
Example
Defines an elementary type t_dec2 for decimal numbers with two decimal places and declares data objects with this type.
TYPES t_dec2 TYPE p LENGTH 8 DECIMALS 2.
DATA: distance TYPE t_dec2,
weight TYPE t_dec2.
Example
Inline declaration of a target area wa when reading from an internal table itab.
DATA itab TYPE TABLE OF line_type.
LOOP AT itab INTO DATA(wa).
...
ENDLOOP.