In SAP ABAP, system variables are predefined variables that hold system-related information. Here are some commonly used system variables in ABAP:
1. SY-DATUM: This variable holds the current system date in the format YYYYMMDD.
2. SY-UZEIT: This variable holds the current system time in the format HHMMSS.
3. SY-UNAME: This variable holds the name of the current user.
4. SY-SYSID: This variable holds the name of the current system.
5. SY-MANDT: This variable holds the current client number.
6. SY-INDEX: This variable holds the current loop index value within a loop.
7. SY-SUBRC: This variable holds the return code of the last executed ABAP statement.
8. SY-DBCNT: This variable holds the number of rows affected by the last executed database operation.
9. SY-LANGU: This variable holds the current user's language.
10. SY-MSGTY: This variable holds the message type of the last executed ABAP statement.
You can use these system variables in your ABAP programs to perform various tasks, such as date and time calculations, user and system validation, and message handling. You can also define your own custom system variables using the SYST structure.
For example, you can define a custom system variable like SY-<variable_name> and assign a value to it using the SYST-<variable_name> statement.
CODE FOR THE SAME GIVEN BELOW:
*********************************************************************
PARAMETERS : P_X TYPE I DEFAULT 20 OBLIGATORY,
P_Y TYPE I DEFAULT 10 OBLIGATORY,
P_STR TYPE STRING LOWER CASE DEFAULT 'HELLO WORLD'.
DATA : V_Z TYPE I. " VARIABLE DECLARED NORMALLY USING V_ AND THIS VARIBLE IS USED TO STORE USER INPUT
V_Z = P_X + P_Y.
WRITE :/ 'SUM OF TWO NUMBERS IS :', V_Z COLOR 2 LEFT-JUSTIFIED.
*WRITE :/ 'ENTERED STRING IS :', P_STR COLOR 2 LEFT-JUSTIFIED. "(OR )
FORMAT COLOR 6.
WRITE :/ 'ENTERED STRING IS :', P_STR.
FORMAT COLOR off.
WRITE :/ 'CURRENT DATE IS ', SY-datum.
WRITE :/ 'CURRENT TIME IS ', SY-uzeit.
WRITE :/ 'CURRENT TIME IS ', SY-UNAME.
WRITE :/ 'CURRENT TIME IS ', SY-REPID.
WRITE :/ 'CURRENT TIME IS ', SY-PAGNO.
*******************************************************************
OUTPUT FOR THE ABOVE CODE :
*******************************************************************
Follow me for more on LinkedIn : 👍 (432) LinkedIn
