Preface – This post is part of the ABAP Beginner series.
Table of Contents
SAP System Variables
ABAP has given some predefined types of variables used to query system statuses. These variables are called SAP system variables. We use these variables to check whether a given command works properly. These are filled during runtime. They can store numeric, char, integer, date or time values. There is a field SY-SUBRC which is always zero ‘0’ in case of the correct program run.
There is a table/structure in ABAP Dictionary (SE11) where you can find all the lists of these variables with descriptions. They can be accessed using the keyword “SYST-” or “SY-”.
Following are some of the SAP System Variables:
|SY-SUBRC||i||–||Returns value 0 in case of no error of above statement|
|SY-INDEX||i||–||Loop Index: Contains previous loop passes with the current one|
|SY-TABIX||i||–||Row number in the table index of Internal Table|
|SY-UCOMM||c||70||Function Code that has raised the event PAI|
- It is recommended not to define a local variable starting with “SYST-” or “SY-” ( although not forbidden).
- Do not use obsolete system fields. Here is a list of obsolete ABAP system fields.
- Use System Fields at the right position. It means using an SY-SUBRC check after a mathematical expression will never change its value.
Implementation of System Variables:
WRITE: / “ABAP SYSTEM VARIABLES”. WRITE: / ‘DATE:’ SY-DATUM. WRITE: / ‘TIME:’ SY-UZEIT.
The output for the above code is:
ABAP SYSTEM VARIALBES 27-06-2018 11:34:00
To view the complete list of ABAP System Variables, visit here.