Skip to Content
author's profile photo Former Member
Former Member

Read two dynamic internal tables with dynamic key and also values assinged

Hi Experts,

I have two dynamic internal tables. first will have the old values and the second will have new values of same structure

All dynamic tables and work areas are created, assigned and populated with values before this step

My question can we make the read statement with dynamic with key option and dynamic value populated option.

Based on the first dynamic internal table , workarea values in the second dynamic internal table are read . Both internal table are having the same structure

My code looks like as below :

data: lv_string type string.

loop at <dyn_table_x> into <dyn_wa_x>

dynamic_field = p_table. " fileld name is determined with the user input

"i.e it is the key field in dyn_table_x and dyn_Table_y

read table <dyn_table_y> into <dyn_wa_y>

with key (dynamic_field) = <dyn_wa_x>-<fieldname> filled based on the outer loop.

  • similarly the value of <fieldname> is same as that of p_table. But based on the user input the value might get change everytime


What change needs to be done in the above read statement in order to read fieldname and its values dynamically ?

i have checked SDN for the read statment :

from sdn :

READ TABLE <fs_data> ASSIGNING <fs_data_aux> WITH KEY (field_key) = 'TEST'.

In this read i want to pass dynamic variable name instead of value 'TEST'. Can we acheive this ?



Add comment
10|10000 characters needed characters exceeded

2 Answers

  • Best Answer
    Posted on Sep 21, 2010 at 06:21 PM

    Like this

    field-symbols <comp> type any.
    assign component 'FIELDNAME' of structure <dyn_wa_x> to <comp>.
    "now you can read it
    read table <dyn_table_y> into <dyn_wa_y> 
    with key (dynamic_field) = <comp>.

    the 'FIELDNAME' can be substituted with variable that holds name of the component.



    Add comment
    10|10000 characters needed characters exceeded

    • I have a small clarification : but if i use assign component inside my loop endloop the component would be assinged for every read of the record. is that fine ?

      It must be there, as in each loop <dyn_wa_x> is changing, hence <comp> will also have to change each time.



  • Posted on Sep 21, 2010 at 06:23 PM

    This syntax will work but you have to create the dyn table and dynwork area properly

    loop at <dyn_table_x> assigning <dyn_wa_x>
    read table <dyn_table_y> assigning <dyn_wa_y> with key (p_table) = <dyn_wa_x>-<fieldname> .
    if sy-subrc = 0.

    @marcin - Hi .. Do we need a assign component when its getting assigned in the loop ? 😊

    Add comment
    10|10000 characters needed characters exceeded