cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

READ TABLE WITH DYNAMIC VARIABLE

Aaron_Lee
Explorer
0 Kudos
138

Hello experts on line,

following is my code.

TYPES: BEGIN OF t_str,
  col1 TYPE c,
  col2 TYPE i,
  END OF t_str.


TYPES: t_itab type TABLE of t_str.
data: gs_str type t_str,
      gt_itab type t_itab.

data gv_name type char10 value 'COL1'.

gs_str-col1 = 'A'.
gs_str-col2 = 1.
APPEND gs_str to gt_itab.

gs_str-col1 = 'B'.
gs_str-col2 = 2.
APPEND gs_str to gt_itab.

PERFORM test_itab USING gt_itab.

*FORM test_itab using pt_itab type t_itab.
*  READ TABLE pt_itab with key col1 = 'A' into gs_str.
*  if sy-subrc = 0.
*    write: gs_str-col1, gs_str-col2.
*  ENDIF.
*endform.

FORM test_itab using pt_itab type ANY TABLE.
  READ TABLE pt_itab with key (gv_name) = 'A' into gs_str.
  if sy-subrc = 0.
    write: gs_str-col1, gs_str-col2.
  ENDIF.
endform.

I don't know why it does works with dynamic variable (gv_name) when I choose 'type any table'.

Could you please do me a favor to explain a little bit? Thanks 

 

Accepted Solutions (0)

Answers (0)