F Different ways to read values from internal table in SAP ABAP | CodeTheta

Different ways to read values from internal table in SAP ABAP

January 24, 2020

Source Code :
PROGRAM ZVP_INTERNAL.

TYPES: BEGIN OF STRUC,
         ID(3)       TYPE C,
         NAME(10)    TYPE C,
         ADDRESS(10) TYPE C,
       END OF STRUC.

DATA: WA     TYPE STRUC,
      IT TYPE STANDARD TABLE OF STRUC.

WA-ID = '1'.
WA-NAME = 'SANTANU'.
WA-ADDRESS = 'KONNAGAR'.
APPEND WA TO IT.

WA-ID = '2'.
WA-NAME = 'ANAND'.
WA-ADDRESS = 'KOLKATA'.
APPEND WA TO IT.

WA-ID = '3'.
WA-NAME = 'SANJIBDA'.
WA-ADDRESS = 'KOLKATA'.
APPEND WA TO IT.

WA-ID = '4'.
WA-NAME = 'RUPESH'.
WA-ADDRESS = 'DELHI'.
APPEND WA TO IT.

WA-ID = '5'.
WA-NAME = 'RAJESH'.
WA-ADDRESS = 'ASSAM'.
APPEND WA TO IT.

"Method 1
READ TABLE IT INTO WA INDEX 3.
IF SY-SUBRC EQ 0.
  WRITE: / WA-ID, '|',
            WA-NAME,'|',
            WA-ADDRESS, '|'.
ELSE.
  WRITE: 'NOT FOUND'.
ENDIF.

Output :


"Method 2
READ TABLE IT INTO WA WITH KEY NAME = 'RAJESH'.
IF SY-SUBRC EQ 0.
  WRITE: / WA-ID, '|',
            WA-NAME,'|',
            WA-ADDRESS, '|'.
ELSE.
  WRITE: 'NOT FOUND'.
ENDIF.

Output :


IDE Used To Test This Code : ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment