Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Processing of External Data →  Obsolete Database Access →  Obsolete Access Statements 

READ TABLE dbtab

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Obsolete Syntax

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

Extras

1. ... WITH KEY key

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

3. ... VERSION vers

Effect

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
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.


Note

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

  • The obsolete access statements do not support automatic client handling. The client identifier of a database table must be specified explicitly. The application programs are only to work with data for the current client. In systems with multitenancy, this is checked by the ABAP runtime environment.

Addition 1

... WITH KEY key

Effect

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.

Addition 2

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

Effect

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.

Addition 3

... VERSION vers

Effect

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

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.

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.