‎2014 Jul 24 2:24 PM
Hi Everyone,
Here is my problem..
I am dynamically creating an internal table based on select-option table entered by user.
The key for this table can be determined only at runtime.
The table entered might have by one field as key field or 10 key fields..
How can I use the dynamic read in this situation
‎2014 Jul 24 2:38 PM
Hi
You can use a loop and check the keys fields into the loop: it's not very good for performance but it can works well
Max
‎2014 Jul 24 2:48 PM
You can also try this:
read TABLE itab with key (key_field1) = <key1>
(key_field2) = <key2>
....................
(key_fieldn) = <keyn>.
In this case you need to arrange a READ TABLE for max N key
Max
‎2014 Jul 24 2:50 PM
Hi,
This is the form of read statement upto 10 keyfields,
You can read some std tables/FM to get the key fields of a table.
Later you can assign the key fields field symbols as shown:-
* Loop to assign fieldnames & values to READ TABLE keyfields
LOOP AT li_keyfields INTO work_area WHERE keyfield EQ 'X' .
l_index = l_index + 1.
CASE l_index.
WHEN 1.
ASSIGN COMPONENT work_area-fieldname OF STRUCTURE work_area TO <fs_c1>.
MOVE work_area-fieldname TO l_key1.
WHEN 2.
ASSIGN COMPONENT work_area-fieldname OF STRUCTURE work_area TO <fs_c2>.
MOVE work_area-fieldname TO l_key2.
WHEN 3.
ASSIGN COMPONENT work_area-field OF STRUCTURE work_area TO <fs_c3>.
MOVE work_area-fieldname TO l_key3.
..................................................................................................................................
..................................................................................................................................
..................................................................................................................................
WHEN 10.
ASSIGN COMPONENT work_area-fieldname OF STRUCTURE work_area TO <fs_c10>.
MOVE work_area-fieldname TO l_key10.
ENDCASE.
ENDLOOP.
READ TABLE <fs_itab> ASSIGNING <fs_wa>
WITH KEY (l_key1) = <fs_c1>
(l_key2) = <fs_c2>
.......................
..............................
(l_key10) = <fs_c10>.