sapdev logo background
sapdev logo sapdev logo
Comments

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



Return to Statement index



READ TABLE - table_key

Short Reference

ABAP Syntax ... { FROM wa [USING KEY keyname
] }
| { WITH TABLE KEY [ keyname COMPONENTS]
{comp_name1|(name1)} = operand1
{comp_name2|(name2)} = operand2
... } ... .

ABAP_ALTERNATIVES:
1 ... FROM wa [USING KEY keyname]
2 ... WITH TABLE KEY [keyname COMPONENTS] ...


ABAP_ALTERNATIVE_1 ... FROM wa [USING KEY keyname]


If the primary table key is used to access a standard table and the key is
empty , then the first row of the internal table is read. If this is statically identifiable, the syntax check produces a warning.

Latest notes: When using the primary table key, note that this key can be the standard key , which can also have unexpected consequences:
  • For structured row types, the standard key covers all character-like and byte-like components.

  • The standard key of a standard table can be

  • empty .

    Apart from classes, the FROM wa declaration can be left out if the internal table has an itab header line with the same name. The statement then does not evaluate the content of the primary table key in the header line; instead, it evalu
    ates the content of the standard key ; initial fields are subject to special handling (see READ TABLE - obsolete_key ).

    ABAP_ALTERNATIVE_2 ... WITH TABLE KEY [keyname COMPONENTS] ...

    Table expressions enable reads to be performed in operand positions too. A table key is used whenever it is specified explicitly using key
    .

    Example ABAP Coding For different key inputs, see Key Access .

    Example ABAP Coding Reads rows of the internal table spfli_tab using the primary table key and a secondary table key. The first READ statement evaluates the work area spfli_key ; the second READ
    statement specifies the components of the secondary table key
    city_key explicitly.
    DATA: spfli_tab TYPE SORTED TABLE OF spfli
    WITH UNIQUE KEY carrid connid
    WITH NON-UNIQUE SORTED KEY city_key
    COMPONENTS cityfrom cityto,
    spfli_key LIKE LINE OF spfli_tab.

    FIELD-SYMBOLS <(><<)>spfli> TYPE spfli.

    ...

    spfli_key-carrid = 'LH'.
    spfli_key-connid = '0400'.
    READ TABLE spfli_tab FROM spfli_key ASSIGNING <(><<)>spfli>.

    IF sy-subrc = 0.
    ...
    ENDIF.

    ...

    READ TABLE spfli_tab
    WITH TABLE KEY city_key
    COMPONENTS cityfrom = 'LH' cityto = '2402'
    ASSIGNING <(><<)>spfli>.

    IF sy-subrc = 0.
    ...
    ENDIF.
    Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




    READ_TABLE_INDEX
    READ_TABLE_OBSOLET




    comments powered by Disqus