READ TABLE with INDEX using ABAP 7.4


Reading a record from internal table with index using ABAP 7.4 syntax, alternative for READ TABLE INDEX

A+ A-

From NetWeaver 7.4, reading a record from an internal table is much simpler, but you can not use sy-subrc for checks, you need to use exception CX_SY_ITAB_LINE_NOT_FOUND

Syntax: <wa> = <ITAB>[ <index> ] 

Example of using READ TABLE using Index ABAp 7.4

SELECT *
  FROM MARA
  INTO TABLE @DATA(IT_MARA)
  UP TO 50 ROWS
  WHERE MTART = 'FERT'.

DATA(wa_mara) = it_mara[ 2 ].  "Read index 2 from IT_MARA
WRITE:/ wa_mara-matnr.

Using exception CX_SY_ITAB_LINE_NOT_FOUND ABAP 7.4

SELECT *
  FROM MARA
  INTO TABLE @DATA(IT_MARA)
  UP TO 50 ROWS
  WHERE MTART = 'FERT'.

TRY .
DATA(wa_mara) = it_mara[ 51 ]. "Read 51 index will fail because only 50 records are there
CATCH CX_SY_ITAB_LINE_NOT_FOUND.
WRITE:/ 'Error Reading Record'.
ENDTRY.
WRITE:/ wa_mara-matnr.

Learner Questions

No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question


    Was this lesson helpful to you? Yes No 2 People out of 2 think this lesson helpful

    Lesson Navigation

    ←Previous Chapter
    Next Chapter →