READ TABLE dbtab [WITH KEY key]
[SEARCH {FKEQ|FKGE|GKEQ|GKGE}]
[VERSION vers].
1. ... WITH KEY key
2. ... SEARCH {FKEQ|FKGE|GKEQ|GKGE}
3. ... VERSION vers
This variant of the statement READ (not allowed in classes) reads a row from the database table dbtab and assigns the content to the respective table work area. For dbtab, you must specify the name of a database table that begins with "T" and is not longer than five characters. The table work area must have been declared with statement TABLES for database table dbtab. If a database table is specified that does not begin with "T", then the first letter is implicitly replaced by "T".
Without the addition WITH KEY, the row to be read is determined
by the content of the components of the table work area that correspond to the primary key fields of database table dbtab.
System Fields
sy-subrc | Relevance |
0 | A table entry was read. |
4 | No table entry was found under the specified search key. |
8 | The table work area is too short. |
12 | The database table was not found. |
... WITH KEY key
With the addition WITH KEY, the key is determined through the content of data object key for which a flat character-type data type is expected.
The content of the table work area resp. of the data object key
is taken from the database table as search key (left-aligned with the length of the key components); then a matching entry is searched in the database.
... SEARCH {FKEQ|FKGE|GKEQ|GKGE}
The addition SEARCH determines how the row is searched:
... VERSION vers
If the addition VERSION is specified, then not the database table dbtab is read, but the table whose name is composed of "T" and the content of vers. For vers, you have to specify a data object of the type c with a maximum length of four characters. If the database table is not available, sy-subrc is set to 12.
The content of the rows is still assigned to table work area dbtab, on whose type it is also cast onto. If table work area is too short, then sy-subrc is set to 8.
The statement is not executed if the database table does not exist or does not comply with the naming conventions stated above.
Reading of a row from the database table T100 or another database table that starts with "T".
TABLES t100.
PARAMETERS p TYPE c LENGTH 4 DEFAULT '100T'.
t100-sprsl = 'E'.
t100-arbgb = 'BC'.
t100-msgnr = '010'.
READ TABLE t100 SEARCH FKEQ VERSION p.
IF sy-subrc = 0.
...
ENDIF.
The Open-SQL-syntax to be used instead reads:
PARAMETERS p TYPE c LENGTH 5 DEFAULT 'T100T'.
DATA dref TYPE REF TO data.
FIELD-SYMBOLS <fs> TYPE ANY.
CREATE DATA dref TYPE (p).
ASSIGN dref->* TO <fs>.
SELECT SINGLE *
FROM (p)
INTO <fs>
WHERE sprsl = 'E' AND
arbgb = 'BC' AND
msgnr = '010'.
IF sy-subrc = 0.
...
ENDIF.