0% found this document useful (0 votes)
14 views

Chapter 4 (Data Objects Variables)

The document discusses different types of variables in ABAP including local variables, static variables, reference variables, system variables, and structured variables. It describes how each variable type is declared and initialized as well as common guidelines for naming variables in ABAP projects. Key details include that variables must be declared before use, have a limited lifetime within a program or function, and system variables contain runtime information accessible to all programs.

Uploaded by

Cleo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Chapter 4 (Data Objects Variables)

The document discusses different types of variables in ABAP including local variables, static variables, reference variables, system variables, and structured variables. It describes how each variable type is declared and initialized as well as common guidelines for naming variables in ABAP projects. Key details include that variables must be declared before use, have a limited lifetime within a program or function, and system variables contain runtime information accessible to all programs.

Uploaded by

Cleo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 4:Data Objects

(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.

Guidelines in declaring a Variable


• Hyphens should be avoided in variable declaration.
• Any ABAP keyword or clause name should not be used.
• User can't use special characters like 't', ','.
Static Variables
• Static variable initialized only once when the program or function or include etc, execution started
and doesn't initialize until the end of the program or function or include etc,. The value assigned
to the static variable retain until the end of the program or function or include etc, execution.
• Static variable is a global variable. Static variables are declared in subroutines, function modules
and static methods. Static variable life time is linked to the context of declaration.
• The "DATA" statement used to declare variables whose lifetime is linked to the context of the
declaration.
• The "STATICS" statement used to declare variables with static validity in procedures.
• The "CLASS-DATA" statement used to declare static variables within classes.
• The "PARAMETERS" statement used to declare elementary data objects that are linked to an input
field on a selection screen.
• The "SELECT-OPTIONS" used to declare an internal table that is linked to input fields on a
selection screen.
Reference Variables

• 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}.

You might also like