Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Internal Tables - Overview 

Access to Internal Tables

When internal tables are read, either the entire table or table body can be accessed, or individual rows.

  • The full table is read using special statements such as SORT, but can also be accessed using general statements where internal tables can be specified at operand positions. Examples are assignments, parameter passing, target or source areas in ABAP SQL and many other statements that return or expect tabular data.
  • Individual rows are accessed using
When individual rows are read, either a work area is used into which the row content is read or from which it is modified, or a row is associated with a field symbol or a data reference variable and these are used to access the row directly.

The table category and the table keys are significant when internal tables are edited:

Other versions: 7.31 | 7.40 | 7.54


Notes

  • Internal tables must be specified at operand positions for internal tables, both when the statement is executed and if known statically. Generic formal parameters and field symbols can only be specified if they are typed with at least the generic type any table. Only index tables can be specified at operand positions that include index access, and generic formal parameters and field symbols must be typed with at least the generic type index table.

  • If the row type of internal tables contains object reference variables as the components comp, the attributes attr of the object to which the reference points can be used as key values for reading, sorting, and modifying table rows. This is always possible for statements that address individual components of the table.

  • The content of the primary table key cannot be changed for any writes to individual rows of sorted tables and hashed tables. If writes are performed in writing positions across the entire table row in these tables (for example, as a target field of assignments or as actual parameters for output parameters), an exception is always raised. It is not possible to access entire table rows using field symbols, data references or table expressions.

Example

In the following example, data is written to an internal table with ABAP SQL, sorting takes place, and reads are demonstrated with the statement READ TABLE and a table expression.

DATA scarr_tab 
  TYPE STANDARD TABLE OF scarr 
       WITH NON-UNIQUE KEY carrid. 

SELECT * 
       FROM scarr 
       INTO TABLE @scarr_tab. 

SORT scarr_tab BY carrid ASCENDING. 

READ TABLE scarr_tab WITH TABLE KEY carrid = 'LH' 
                     TRANSPORTING NO FIELDS. 
IF sy-subrc = 0. 
  DATA(idx) = sy-tabix. 
  TRY. 
      cl_demo_output=>display( scarr_tab[ idx + 1 ]-carrid ). 
    CATCH cx_sy_itab_line_not_found. 
      ... 
  ENDTRY. 
ENDIF.