Read statement new syntax in ABAP. (7.4+).
* Before ABAP 7.4, we used READ TABLE statement to read the first matching record from the internal table based upon key or index.
* In SAP ABAP new syntax, instead of READ TABLE, we can use the table expressions.
* We need to use the square bracket [ ], In the square bracket, we need to specify the key or index.
* While using table expression, If the table entry does not exist, system throws the exception CX_SY_ITAB_LINE_NOT_FOUND.
* Use line_exists statement to check the existence of a record.
Report
REPORT zab_rp_read_new.
TABLES: vbak.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
SELECT vbeln,erdat,erzet,ernam,auart
FROM vbak
INTO TABLE @DATA(lt_vbak)
WHERE vbeln IN @s_vbeln.
WRITE: 'Index value' COLOR 5.
READ TABLE lt_vbak INTO DATA(lr_vbak) INDEX 2.
IF sy-subrc = 0.
WRITE: / lr_vbak-vbeln, lr_vbak-erdat,lr_vbak-erzet,lr_vbak-ernam,lr_vbak-auart.
ENDIF.
WRITE: / 'With key value' COLOR 5.
READ TABLE lt_vbak INTO lr_vbak WITH KEY vbeln = '0000000005'.
IF sy-subrc = 0.
WRITE:/ lr_vbak-vbeln, lr_vbak-erdat,lr_vbak-erzet,lr_vbak-ernam,lr_vbak-auart.
ENDIF.
WRITE: / 'All value' COLOR 5.
LOOP AT lt_vbak INTO lr_vbak.
WRITE: / lr_vbak-vbeln, lr_vbak-erdat,lr_vbak-erzet,lr_vbak-ernam,lr_vbak-auart.
ENDLOOP.
New Syntax Report
REPORT zab_rp_read_new.
TABLES: vbak.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
SELECT vbeln,erdat,erzet,ernam,auart
FROM vbak
INTO TABLE @DATA(lt_vbak)
WHERE vbeln IN @s_vbeln.
WRITE: 'Index value' COLOR 5.
IF line_exists( lt_vbak[ 2 ] ).
DATA(lr_vbak) = lt_vbak[ 2 ].
WRITE: / lr_vbak-vbeln, lr_vbak-erdat,lr_vbak-erzet,lr_vbak-ernam,lr_vbak-auart.
ENDIF.
WRITE: / 'With key value' COLOR 5.
IF line_exists( lt_vbak[ vbeln = '0000000005' ] ).
lr_vbak = lt_vbak[ vbeln = '0000000005' ].
WRITE:/ lr_vbak-vbeln, lr_vbak-erdat,lr_vbak-erzet,lr_vbak-ernam,lr_vbak-auart.
ENDIF.
WRITE: / 'All value' COLOR 5.
LOOP AT lt_vbak INTO lr_vbak.
WRITE: / lr_vbak-vbeln, lr_vbak-erdat,lr_vbak-erzet,lr_vbak-ernam,lr_vbak-auart.
ENDLOOP.
Input
Output
******************************Thank You***************************
Comments
Post a Comment