sapdev logo background
sapdev logo sapdev logo
Comments

ABAP READ TABLE DBTAB Statement syntax, information and example SAP source code



Return to Statement index



READ TABLE dbtab

Short Reference

ABAP Syntax(Obsolete) READ TABLE { dbtab | *dbtab }
[WITH KEY key]
[SEARCH {FKEQ|FKGE|GKEQ|GKGE}]
[VERSION vers].

ABAP_ADDITIONS:
1 ... WITH KEY key
2 ... SEARCH {FKEQ|FKGE|GKEQ|GKGE}
3 ... VERSION vers

What does it do? This variant of the statement READ (not allowed in classes) reads a row from the database table dbtab and assigns the content to a work area.
A table work area dbtab or *dbtab is used implicitly as the work area. The table work area must be declared using the statement TABLES . If, instead of the name of the database table dbtab , the description *dbtab is used, dbtab is actually accessed but an additional table work area is used. All components of the table work area that match the primary key fields of the database table dbtab must be character-type.
For dbtab , you must specify a database table that begins with "T" and has a maximum length of five characters. 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 Meaning
0A table entry was read.
4No table entry was found under the specified search key.
8The table work area is too short.
12The database table was not found.

Latest notes: This form of READ statement is not allowed in classes. It must be replaced by the statement SELECT
.

ABAP_ADDITION_1 ... WITH KEY key

What does it do? The addition WITH KEY determines the key by using the content of data object key , which expects a flat character-like data type.
The content of the table work area or the data object key is taken from the database table as a search key (left-aligned with the length of the key components); then a matching entry is searched in the database.

ABAP_ADDITION_2 ... SEARCH {FKEQ|FKGE|GKEQ|GKGE}

What does it do? The addition SEARCH determines how the row is searched:
Without the addition SEARCH and with SEARCH FKEQ , the first row in the database table is searched that matches the search key.
SEARCH GKEQ is used to search generically for the first row of the database table that matches the search key. The search key handles blanks as if they match all values.
SEARCH FKGE searches the first row of the database table is that is greater than or equal to the search key.
SEARCH GKGE searches (generically) the first row of the database table is that is greater than or equal to the search key. The search key handles blanks as if they match all values.

ABAP_ADDITION_3 ... VERSION vers

What does it do? If the addition VERSION is specified, then the database table dbtab is not read, and the table whose name is composed of "T" and the content of vers is read instead. vers
expects a data object with a maximum of four characters, of type c . If the database table is not available, sy-subrc is set to 12.
The content of the row is still assigned to the table work area of dbtab or *dbtab and its type is cast. If table work area is too short, then sy-subrc is set to 8.

Example ABAP Coding 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 as follows. It uses a dynamic FROM clause and also uses CREATE DATA to create a suitable work area for the INTO clause.
NEXT EXAMPLE
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.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




READ_TABLE
READ_TABLE_FREE




comments powered by Disqus