ABAP Tutorial
Chapter IV Appendix
1 ABAP System Fields
Standard ABAP
URL
ABAP - Help > ABAP - Programming Language > Built-In Types, Data Objects, Functions, and Constructors > Built-In Data Objects > ABAP System Fields
System fields are filled by the ABAP runtime environment and can be used in an ABAP program to query system states. With one exception (sy-repid), the system fields are variables, but they should only be used for reads. Otherwise, important information for further program execution may be lost. System fields in ABAP programs might only be overwritten in rare cases to control system behavior.
The data types of the system fields -except for sy-repid- are defined in the structure SYST in the ABAP Dictionary and are instantiated as components of the built-in structure sy in ABAP programs. The structure sy exists only once in an internal session and is used by all programs in this internal session.
The structure sy can also be addressed using syst. There is also a built-in data type sy, which can be used instead of the data type SYST of the ABAP Dictionary.
The following table shows the system fields that can be used in ABAP programs. All other components of the structure sy are either intended only for internal use by the ABAP runtime environment or are obsolete.
Name Type Length Content
- sy-abcde
-
c 26 Contains the Latin alphabet. Can be used to access individual letters directly by specifying the offset/length, regardless of the code page.
- sy-batch
-
c 1 Set to ’ X” in an ABAP program that runs in the background; otherwise initial.
- sy-binpt
-
c 1 Set to ”X” when processing batch input sessions and in ABAP programs called by CALL TRANSACTION USING; otherwise initial. These default values can be overridden using the addition OPTIONS FROM of the statement CALL TRANSACTION ... USING.
- sy-calld
-
c 1 Contains a blank in the first program of a call sequence; otherwise the value ”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 from the screen. A call using SUBMIT (without AND RETURN) takes over the value of the calling program.
- sy-callr
-
c 8 When spooling lists, contains a value that indicates where spooling was started, for example NEW-PAGE for program-driven spooling or RSDBRUNT for spooling from the selection screen.
- sy-colno
-
i - Current position during list creation in the list buffer, is set for each output statement is used. Counting begins at 1. It is only guaranteed that this position matches the column in the displayed list only for the lower and upper output limits of each output, since one character may occupy more columns in the list than there are places in the list buffer. See also Lists - System Fields.
- sy-cpage
-
i - Page number of the top page in the list display where a list event was raised. Counting begins at 1. See also Lists - System Fields.
- sy-cprog
-
description c 40 In externally called procedures, the name of the calling program; otherwise the name of the current program. If an externally called procedure calls another external procedure, sy-cprog contains the name of the compilation unit and is not set to the name of the compilation unit of the subsequent calling program.
- sy-cucol
-
i - Horizontal cursor position on the screen of a dynpro. Counting begins at column 2. Set after the event PAI.
- sy-curow
-
i - Vertical cursor position on the screen of a dynpro. Counting begins at line 1. Set after the event PAI.
- sy-datar
-
c 1 Contains ”X” at PAI, if at least one input field of a screen was changed by a user or by another data transfer, otherwise initial.
- sy-datlo
-
d - User date, such as ”19990723”.
- sy-datum
-
d - System date.
- sy-dayst
-
c 1 ”X” during daylight saving time in the system time zone; otherwise initial.
- sy-dbcnt
-
i - SQL statements set the content of sy-dbcnt to the number of processed table lines.
- sy-dbnam
-
c 20 In executable programs, the associated logical database.
- sy-dbsys
-
c 10 Database system of the standard database, such as HDB” or ”ADABAS”. See also CL_DB_SYS.
- sy-dyngr
-
c 4 Screen group of the current dynpro. In the Screen Painter, multiple dynpros can be assigned to a common screen group, which can be used, for example, to make modifications to all screens in the group at once.
- sy-dynnr
-
c 4 Number of the current dynpro. During selection screen processing, this is the current selection screen. During list processing, this is the number of the subscreen dynpro. During processing of a subscreen dynpro (including in tabstrips), this is its dynpro number.
- sy-fdayw
-
b - Factory calendar weekday in the system time zone; Monday = 1, ..., Friday = 5.
- sy-fdpos
-
i - Found position for specific operations on character-like or byte-like data objects (for example comparisons or the obsolete statement SEARCH).
- sy-host
-
c 32 Network name of the host computer on which the current AS instance is instantiated, for example ”KSAP0001” or ”HS01234”.
- sy-index
-
i - Loop index. In DO and WHILE loops, this contains the number of previous loop passes, including the current pass.
- sy-langu
-
c 1 Single-character language key (such as ”E”, ”D”, or ”F”) for the locale language of the current internal session. The logon language or the language set by the statement SET LOCALE LANGUAGE is the default.
- sy-ldbpg
-
c 40 In executable programs, the database program of the associated logical database.
- sy-lilli
-
i - List line for which a list event was raised. Counting begins at 1 and includes the page header. See also Lists - System Fields.
- sy-linct
-
i - Page length of the current list during list creation. sy-linct is 0 for a standard list of any length and is not equal to 0 for lists with fixed page lengths. Set by The program-initiating statement or by SUBMIT. See also Lists - System Fields.
- sy-linno
-
i - Current list line during list creation. Counting begins at 1 and includes the page header. Set by output statements. See also Lists - System Fields.
- sy-linsz
-
i - Line width of the current list in the list buffer during list creation. By default, the value is set as follows: If sy-scols is greater than or equal to 84, sy-linsz matches sy-scols, otherwise sy-linsz has the value 84. This can be overridden by the program-initiating statement or using SUBMIT. See also Lists - System Fields.
- sy-lisel
-
c 255 Content of the list line in the list buffer, on which the cursor was positioned in the displayed list while a list event was raised (limited to the first 255 characters). See also Lists - System Fields.
- sy-listi
-
i - List level of the list for which a list event was raised.
- sy-loopc
-
i - Number of currently displayed lines in a table control. Set after the event PAI.
- sy-lsind
-
i - List level of the list that is currently being created (basic list: 0; detail lists: greater than 0). For every interactive list event, sy-lsind is increased automatically by 1. sy-lsind can be modified in the ABAP program to navigate between detail lists. Any changes made to sy-lsind are ignored until the end of a list event. See also Lists - System Fields.
- sy-macol
-
i - Contains the number of columns on the left edge when spooling lists. Set by the statement SET MARGIN.
- sy-mandt
-
c 3 Client ID with which the current user has logged on, for example ”401” or ”800”.
- sy-marow
-
i - Contains the number of lines on the top margin when spooling lists. Set by the statement SET MARGIN.
- sy-modno
-
i - 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 using /o in the command field of the standard toolbar, this value is increased by 1. If previous sessions have been deleted, the free numbers are set again first. Sessions opened with CALL FUNCTION ... STARTING NEW TASK restart at 0.
- sy-msgid
-
c 20 After the statement MESSAGE, contains the message class. After MESSAGE ... RAISING, is also set in the calling program if it handles the exception (the same applies to RFC exceptions) .
- sy-msgno
-
n 3 After the statement MESSAGE, contains the message number. After MESSAGE ... RAISING, is also set in the calling program if it handles the exception (the same applies to RFC exceptions) .
- sy-msgty
-
c 1 After the statement MESSAGE, contains the message type. After MESSAGE ... RAISING, is also set in the calling program if it handles the exception (the same applies to RFC exceptions) .
- sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4
-
c 50 After the statement MESSAGE, contains the field content used as placeholders of the message. After MESSAGE ... RAISING, is also set in the calling program if it handles the exception (the same applies to RFC exceptions) . When 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 Operating system of the host computer of the current AS instance, for example ”SOLARIS” or ”HP-UX”.
- sy-pagno
-
i - Current page during list creation. Set by output statements. See also Lists - System Fields.
- sy-pfkey
-
c 20 GUI status of the current dynpro. Set after the event PAI.
- sy-saprl
-
c 4 Release status of AS ABAP, for example ”702” or ”740”.
- sy-scols
-
i - Number of columns in the current screen layout. Set after the event PAI.
- sy-slset
-
c 14 Variant that was used to fill a selection screen. The relevant 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 - Number of lines in the current screen layout. Set after the event PAI.
- sy-staco
-
i - Number of the first displayed column in the list for which a list event was raised. Counting begins at 1. See also Lists - System Fields.
- sy-staro
-
i - Number of the list line displayed at the top of the displayed page for list, for which a list event was raised. Counting begins at 1. The page header is not counted. See also Lists - System Fields.
- sy-stepl
-
i - Index of the current line 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 line, the content of sy-stepl is undefined.
- sy-subrc
-
i - Return value that is set by many ABAP statements. In general, the value 0 means that the statement was executed without problems. Depending on which statement was used to set sy-subrc, the cause of an error can be derived from this value. The content of sy-subrc keeps its previous value or is undefined after statements where the setting of sy-subrc is not documented explicitly.
- sy-sysid
-
c 8 System ID of AS ABAP, for example ”S01” or ”K99”.
- sy-tabix
-
i - Line number in the table index of an internal table. Contains the last line addressed using a primary or secondary table index. Is set to 0 when accessed using a hash algorithm.
- sy-tcode
-
c 20 Name of the current transaction code. Initial in background processing, unless a transaction was called during background processing.
- sy-tfill
-
i - In the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, sy-tfill is given the number of lines of the accessed internal table.
- sy-timlo
-
t - User time, such as ”152557”.
- sy-title
-
c 70 Text that appears in the title bar of the dynpro.
- sy-tleng
-
i - In the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, sy-tleng is given the line size of the accessed internal table.
- sy-tzone
-
i - Time difference of the system time to the UTC reference time in seconds, for example ”3600” or ”10800”.
- sy-ucomm
-
c 70 Function code that raised the event PAI. This function code is usually uniquely linked to a function. Only Enter can pass different function codes to sy-ucomm in accordance with the following hierarchy: Content of the command field in the system toolbar, assigned function code; not influencing of the content.
- sy-uline
-
c 255 Contains 255 ”-” characters for displaying lines in lists. For the display of sy-uline with the statement WRITE, the same applies as to the statement ULINE, that is, every ”-” character is replaced by a line element by default.
- sy-uname
-
c 12 User name of the current user session, for example ”KELLERH”.
- sy-uzeit
-
t - System time.
- sy-vline
-
c 1 Contains a vertical line (|) for displaying 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 User time zone, for example ”CET” or ”PST”.
The system field sy-repid is not a component of the structures syst or sy. Instead, each program contains the built-in constants sy-repid and syst-repid, which both contain the name of the corresponding program. There are also two built-in types with the same names, sy-repid and syst-repid, of type c and length 40.
a Programming Guidelines
-
1. Evaluate system fields in the correct place
-
2. Do not use obsolete or internal system fields
-
3. Do not write to system fields
-
4. Do not use system fields as actual parameters
-
5. Do not use system fields in statements that set them
-
6. Do not use system fields on the user interface
b Hints
Although it is not syntactically forbidden, data objects or types with the names sy or syst or with the names of the system fields themselves in programs should not be created separately, since they can hide built-in data objects and types. The content of system fields is only defined as stated in the table above or for individual ABAP statements. In any other contexts, the content of system fields is not reliable. In particular those statements whose effect on system fields is undocumented can impact the content of certain system fields in undefined ways, for example sy-subrc. This primarily applies to statements that call ABAP code implicitly or explicitly when executed. If possible, a system field should be evaluated directly following the statement that set it, to prevent it from being overwritten by other statements. If necessary, the values of system fields should be stored in auxiliary variables. A system field should only be entered as an operand in a read position if its content is not set by the same statement. Otherwise, the system may behave unexpectedly. System fields and the associated structure SYST have a pure program-internal meaning. No dynpro fields should be created with reference to system fields, since the relevant field help is not intended for end users. Internal system fields are intended entirely for internal use in the ABAP runtime environment and in the ABAP kernel. They must never be overwritten in ABAP programs and should not be read in any way. The obsolete system fields were usually transferred during the transition from R/2 to R/3 and are no longer filled. These system fields can no longer be used. The static methods of the system class CL_ABAP_SYST also return important system states. The use of these methods can replace the evaluation of the corresponding system fields in all cases where it is important that a system field has not been overwritten inadvertently in the program. In the case of sy-dbsys, it is recommended that the class CL_DB_SYS is used.
c Example
Typical evaluation of the system field sy-subrc after a SELECT statement.
SELECT SINGLE * FROM scarr WHERE carrid = '...' INTO @DATA(wa). IF sy-subrc <> 0. RETURN. ENDIF.