Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
ABAP

Reading internal table dynamically

 

Recently I came up with a requirement where I have to read the tables based on the condition. Instead of reading the table based on condition I have decided to read it dynamically. Below is the piece of code which reads the two internal table dynamically.

TYPES : begin of s_stru,
          field1
type
char10,
          field2
type
string,
       
end of
s_stru,
        
        tt_stru
type standard table of
s_stru.

data : lv_var type
char10,
       wa    
type
s_stru,
       itab1 
type standard table of
s_stru,
       itab2 
type standard table of
s_stru.
      


parameters : lv_cond type c default 'X'
.

field-symbols : <fs_table> type
table.


* Populate the internal tables


wa-field1 =
'1001'.
wa-field2 =
'Sample data'
.
append wa to
itab1.
clear
wa.

wa-field1 =
'1002'
.
wa-field2 =
'Sample data 2'
.
append wa to
itab2.
clear
wa.


if lv_cond = abap_true.           " Read from itab 1


 
assign itab1 to <fs_table>.

  lv_var =
'1001'
.

else.                            
" Read from itab 2


 
assign itab2 to <fs_table>.

  lv_var =
'1002'
.

endif.


read table <fs_table> into wa with key ('field1'
) = lv_var.

if sy-subrc = 0.

 
write
: wa-field1, wa-field2.
  
endif.

About Arun

0 Comments:

Post a Comment

Powered by Blogger.