Chapter 4 (Data Objects Variables)
Chapter 4 (Data Objects Variables)
(Variables)
Variables
• Variable are named data objects that refers to the memory location allocated during
the program execution for processing. Variable contains data and act as a referring
name for the data.
• We can modify data, change data, clear data or apply operations on the data with help
of the variable. Each variable should declare with a data type along with size in ABAP.
• A variable must be declared before using it. A variable memory always allocated
before the program execution and destroys once the program execution completed.
No permanent memory allocated to a variable.
Variable Declaration
• Syntax
DATA: Variable-name TYPE data-type [VALUE data-value].
Variable-name - Specifies the variable name. Variable name length can be up to
30 characters.
Data-type - Specifies the data type. We have discussed data types in the
previous chapter.
Data-value - Value that initially assigned to the variable during the declaration.
Variable Naming Convention
• Variable naming convention standard is project dependentant and may vary
from project to project. Below is one of the standard ABAP variable naming
convention
• Syntax
• {Visibility_character}{data_type_character}_{Remaining_field_name}
Variable Types
Variable Types Description
Local Variables Local variables are very local to the program or
function or include etc,.
Static variables are initialized only once and carries
Static Variables out the data until the end of the program
execution.
Reference Variables Reference variables contain the references of other
variables to perform data manupulations.
System Variables System variables are predefined variables and
accessed by all the programs in SAP environment.
Structured Variables Structure variable is variable that declared of
structure data type.
Local Variables
• Local variables meaning is self-explanatory. These variables are
very local to the program or function or include etc,. The variables
life time is until end of the program or function or include etc,
execution where the variable was originally defined.
• Reference variable contain references (i.e. pointing to the memory location of the
another variable). ABAP supports data references and object references.
• The actual contents of the reference variable are not visible in the ABAP program.
The contents of the reference variable are the address of memory location.
• Reference variables can be handled as other data objects that are defined as an
elementary data type. Reference variable can be defined as a complex data object
component such as a structure or internal table.
System Variables
• ABAP System variables are predefined by the SAP system. These variables can
accessed by all the programs in SAP environment. These variables always
filled by the SAP runtime environment.
• The system variables contain the values that describes about the current state
of the system at any point of time (i.e. runtime). The complete list of system
variable found in SYST table.
• Individual fields of the SYST table can be accessed either using "SYST-" or
"ST-". Below are the list of system variables available for usage -
Commonly Used System Variables
System Variable Description
This system variable contains the current loop
SY-INDEX index when iterating through internal tables using
loops like LOOP or READ TABLE.
SY-SUBRC is set to zero if the last ABAP statement
SY-SUBRC executed successfully, and it is set to a non-zero
value if there was an error. It's often used in error
handling.
SY-DATUM This system variable is used for determining the
current date
SY-UZEIT This system variable is used for determining the
current time
SY-TABIX Contains the current index when looping through
internal tables
Structured Variables
• ABAP supports the structured variable declared as a structured data type. Structured variable can
be defined by using BEGIN OF and END OF keywords.
• A structure variable can be declared by using another structure variable with LIKE. Each individual
field in the structure can be accessed using hyphen (-).
Syntax:
DATA: BEGIN OF {structure-name},
{local variables declaration}
END OF {structure-name}.