ABAP New Syntax of reading internal table with index and keys.
ABAP 7.40 release provides a new syntax to read internal table in a new way.
SCARR table entries.
SAMPLE CODE- KEY READ
SELECT * FROM scarr INTO TABLE @DATA(lt_scarr).
* New Syntax
DATA(ls_scarr) = lt_scarr[ carrid = ‘AA’ ].
* Old way of reading table
“READ TABLE lt_scarr INTO ls_spfli WITH KEY carrid = ‘AA’.
IF sy–subrc IS INITIAL.
cl_demo_output=>display_data( ls_scarr ).
ENDIF.
OUTPUT
SAMPLE CODE - Index Read
SELECT * FROM scarr INTO TABLE @DATA(lt_scarr).
* New Syntax index read
DATA(ls_scarr) = lt_scarr[ 2 ].
IF sy–subrc IS INITIAL.
cl_demo_output=>display_data( ls_scarr ).
ENDIF.
OUTPUT
SPFLI table entries.
SAMPLE CODE- Multiple Key Read
SELECT * FROM spfli INTO TABLE @DATA(lt_spfli).
* New Syntax
DATA(ls_spfli) = lt_spfli[ carrid = ‘AA’ connid = ‘0017’ ].
IF sy–subrc IS INITIAL.
cl_demo_output=>display_data( ls_spfli ).
ENDIF.
OUTPUT
Please remove the Subrc checks after accessing the internal table.
Example:
TRY .
WRITE: / t_data[ TABLE_LINE = sy-INDEX ].
CATCH cx_sy_itab_line_not_found.
WRITE: / ‘Not found’, sy-INDEX.
ENDTRY.
LikeLike
I read this piece of writing completely concerning the comparison of newest and preceding technologies, it’s awesome article.
LikeLike
if we use the above syntax what about read table using binary search.
LikeLike