Summary -
In this topic, we described about the below sections -
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 -
Name | Type | Length | Content |
---|---|---|---|
sy-abcde | c | 26 | Contains the Latin alphabet. Used to access individual letters directly by specifying the offset/length. |
sy-batch | c | 1 | Contains "X" in an ABAP program running in the background; otherwise initial. |
sy-binpt | c | 1 | Contains "X" when processing batch input sessions in ABAP programs called by CALL TRANSACTION USING; otherwise initial. These defaults can overridden using the addition OPTIONS FROM of the statement CALL TRANSACTION ... USING. |
sy-calld | c | 1 | Contains blank in the first program of a call sequence; otherwise "X". Set to "X" after calls using CALL TRANSACTION, CALL DIALOG, or SUBMIT ... AND RETURN. Empty if the program was started using LEAVE TO TRANSACTION or by a transaction code entered on the screen. A call using SUBMIT (without AND RETURN) takes the value of the calling program. |
sy-callr | c | 8 | Contains a value that indicates where spooling was started when spooling lists. |
sy-colno | i | Contains current position when a list is created in the list buffer; set whenever an output statement is used. Counting begins at 1. This position corresponding to the column in the displayed list and list is only guaranteed for the lower and upper output limits. | |
sy-cpage | i | Contains page number of the top page in the list display where a list event was raised. Counting begins at 1. | |
sy-cprog | c | 40 | Contains the name of the calling program in externally called procedures; otherwise, the name of the current program. If an externally called procedure calls another external procedure, it contains the name of the master program, and is not set to the name of the master program of the subsequent calling program. |
sy-cucol | i | Contains horizontal cursor position on the dynpro screen. Counting begins at column 2. Set after the event PAI. | |
sy-curow | i | Contains vertical cursor position on the dynpro screen. Counting begins at row 1. Set after the event PAI. | |
sy-datar | c | 1 | Contains "X" for PAI, if at least one input field of a screen was changed by a user or some other data being passed. |
sy-datlo | d | Contains user date in the format "YYYYMMDD". | |
sy-datum | d | Contains system date. | |
sy-dayst | c | 1 | Contains "X" in summer time in the system time zone; otherwise initial. |
sy-dbcnt | i | Contains number of table rows processed. SQL statements set the content of sy-dbcnt to the number of table rows processed. | |
sy-dbnam | c | 20 | Contains name of associated logical database for executable programs. |
sy-dbsys | c | 10 | Contains name of central database system. |
sy-dyngr | c | 4 | Contains name of screen group of the current dynpro. In Screen Painter, multiple dynpros can be assigned to the same screen group. |
sy-dynnr | c | 4 | Contains number of the current dynpro. In selection screen processing, the current selection screen. In list processing, the number of the subscreen dynpro. When processing a subscreen dynpro (including in tabstrips), the number of this dynpro. |
sy-fdayw | b | Contains factory calendar weekday in the system time zone; Monday = 1, ..., Friday = 5. | |
sy-fdpos | i | Contains occurrence after certain operations on character-like or byte-like data objects. | |
sy-host | c | 32 | Contains network name of the computer on which the current application server is instantiated. |
sy-index | i | Contains loop index. In DO and WHILE loops, contains the number of previous loop passes, including the current pass. | |
sy-langu | c | 1 | Contains single-character language key. Set by the logon language of the user or by the statement SET LOCALE. |
sy-ldbpg | c | 40 | Contains the database program of the associated logical database in executable programs. |
sy-lilli | i | Contains list line on which a list event was raised. Counting begins at 1 and includes the page header. | |
sy-linct | i | Contains page length of the current list when the list is created. sy-linct is 0 for a standard list of any length and has a value not equal to 0 for lists with fixed page lengths. Set by the introductory program statement or by SUBMIT. | |
sy-linno | i | Contains current list line when the list is created. Counting begins at 1 and includes the page header. Set by output statements. | |
sy-linsz | i | Contains row width of the current list in the list buffer when the list is created. By default, the value is set as follows - If sy-scols is greater than or equal to 84, sy-linsz is equal to sy-scols; otherwise sy-linsz has the value 84. This can be overridden by the introductory program statement or by SUBMIT. | |
sy-lisel | c | 255 | Contains content of the list line in the list buffer where the cursor was placed in the displayed list when a list event was raised (limited to the first 255 characters). |
sy-listi | i | Contains list level of the list in which a list event was raised. | |
sy-loopc | i | Contains number of currently displayed rows in a table control. Set after the event PAI. | |
sy-lsind | i | Contains list level of the list that is currently being created (basic list: 0, details lists: greater than 0). For every interactive list event, sy-lsind is automatically increased by an increment of 1. sy-lsind can be changed in ABAP programs when navigating between details lists. Any changes made to sy-lsind are ignored until the end of a list event. | |
sy-macol | i | Contains number of columns on the left margin when spooling lists. Set by the statement SET MARGIN. | |
sy-mandt | c | 3 | Contains client ID used by the current user to log on. |
sy-marow | i | Contains number of rows on the top margin when spooling lists. Set by the statement SET MARGIN. | |
sy-modno | i | Contains indexing of the ABAP sessions. Contains the value 0 in the first session. In new sessions that are opened using the Create Session function or by calling a transaction with /o in the command field of the standard toolbar, this value is increased by 1. If previous sessions were deleted, only the free numbers are allocated again. Sessions opened with CALL FUNCTION ... STARTING NEW TASK start at 0 again. | |
sy-msgid | c | 20 | Contains the message class after the statement MESSAGE. Also set in the calling program after MESSAGE ... RAISING, if it handles the exception (the same applies to RFC exceptions). |
sy-msgno | n | 3 | Contains the message number after the statement MESSAGE. Also set in the calling program after MESSAGE ... RAISING, if it handles the exception (the same applies to RFC exceptions). |
sy-msgty | c | 1 | Contains the message type after the statement MESSAGE. Also set in the calling program after MESSAGE ... RAISING, if it handles the exception (the same applies to RFC exceptions). |
sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4 | c | 50 | Contain the field content used for the placeholders of the message after the statement MESSAGE. Also set in the calling program after MESSAGE ... RAISING, if it handles the exception (the same applies to RFC exceptions). If a database lock is requested using an ENQUEUE function module, sym-sgv1 contains the name of the user holding the lock after the exception FOREIGN_LOCK. |
sy-opsys | c | 10 | Contains operating system of the current application server. |
sy-pagno | i | Contains current page when the list is created. Set by output statements. | |
sy-pfkey | c | 20 | Contains GUI status of the current dynpro. |
sy-repid | c | 40 | Contains name of the current ABAP program In procedures called externally, the name of the master program of the procedure. If sy-repid is passed to an external procedure as an actual parameter, the formal parameter is set to the name of the caller. |
sy-saprl | c | 4 | Contains ABAP release. |
sy-scols | i | Contains number of columns in the current screen layout. Set after the event PAI. | |
sy-slset | c | 14 | Contains variant used to fill a selection screen. The associated program name can be seen in sy-cprog. |
sy-spono | n | 10 | Contains the name of the spool number when spooling lists. |
sy-srows | i | Contains number of rows in the current screen layout. Set after the event PAI. | |
sy-staco | i | Contains number of the first displayed column of the list in which a list event was raised. Counting begins at 1. | |
sy-staro | i | Contains number of the top displayed list line of the top displayed page of the list where a list event was raised. Counting begins at 1 and does not include the page header. | |
sy-stepl | i | Contains index of the current row in a table control. This is set for every loop pass. Outside of a loop, for example after the event POV or POH for a table row, the content of sy-stepl is undefined. | |
sy-subrc | i | Contains return code set by many ABAP statements. In general, the value 0 means that the statement was executed with no problems. Depending on which statement set sy-subrc, the cause of an error can be derived from this value. sy-subrc keeps its previous value or its content is undefined after statements where the setting of sy-subrc is not documented explicitly. | |
sy-sysid | c | 8 | Contains name of AS ABAP. |
sy-tabix | i | Contains row number in the table index of an internal table. Contains the last row accessed using a primary or secondary table index. Is set to 0 when accessed using a hash algorithm. | |
sy-tcode | c | 20 | Contains name of the current transaction code. Initial in background processing, unless a transaction was called during background processing. |
sy-tfill | i | sy-tfill is given the number of rows of the accessed internal table in the statements DESCRIBE TABLE, LOOP AT, and READ TABLE. | |
sy-timlo | t | Contains user time. | |
sy-title | c | 70 | Contains text that appears in the title bar of the dynpro. |
sy-tleng | i | sy-tleng is given the row size of the accessed internal table in the statements DESCRIBE TABLE, LOOP AT, and READ TABLE. | |
sy-tvar0, sy-tvar1, sy-tvar2, sy-tvar3, sy-tvar4, sy-tvar5, sy-tvar6, sy-tvar7, sy-tvar8, sy-tvar9 | c | 20 | Contains values can be assigned to these system fields in the program. In the event TOP-OF-PAGE, the content of sy-tvar0 through sy-tvar9 replaces the placeholders "&0" through "&9" in the list headers and column headers of the text elements of the program. |
sy-tzone | i | Contains time difference of the system time to the UTC reference time in seconds. | |
sy-ucomm | c | 70 | Contains function code that raised the event PAI. This function code is usually has a unique association with a function. Only Enter can pass assorted function codes to sy-ucomm in accordance with the following hierarchy: Content of the command field in the system toolbar, then associated function code; the content is not affected. |
sy-uline | c | 255 | Contains 255 "-" characters for displaying lines in lists. In the case of displaying sy-uline with the statement WRITE, the same applies as for the statement ULINE. In other words, every "-" character is replaced by a line element. |
sy-uname | c | 12 | Contains logon name of the user. |
sy-uzeit | t | Contains system time. | |
sy-vline | c | 1 | Contains a vertical bar (|) for displays in lists. |
sy-wtitl | c | 1 | Set to "N" in the statements REPORT, PROGRAM, and FUNCTION-POOL, if the addition NO STANDARD PAGE HEADING is used; otherwise initial. The statement NEW-PAGE does not set sy-wtitl. |
sy-zonlo | c | 6 | Contains user time zone. |
Example -
Write a simple program to display some of the system variables.
Code -
*&---------------------------------------------------------------------*
*& Report Z_SYSTEM_VARIABLE
*&---------------------------------------------------------------------*
*& Program Written by TUTORIALSCAMPUS
*&---------------------------------------------------------------------*
REPORT Z_SYSTEM_VARIABLE.
* Displaying some of the system variables
WRITE:/'SY-ABCDE', SY-ABCDE,
/'SY-DATUM', SY-DATUM,
/'SY-DBSYS', SY-DBSYS,
/'SY-LANGU', SY-LANGU,
/'SY-MANDT', SY-MANDT,
/'SY-OPSYS', SY-OPSYS,
/'SY-SAPRL', SY-SAPRL,
/'SY-TCODE', SY-TCODE.
Output -
Explaining Example -
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear picture of example code.
SY-ABCDE displays the Latin alphabets. SY-DATUM displays the system date (i.e program run date). SY-DBSYS displays the system central database name. SY-LANGU displays the system language. SY-MANDT displays the current client ID used to logon. SY-OPSYS displays the operating system of the current application server. SY-SAPRL displays the running ABAP release. SY-TCODE displays the current running transaction code of ABAP editor.