Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic read statement

Former Member
0 Likes
1,994

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

3 REPLIES 3
Read only

Former Member
0 Likes
1,059

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

Read only

Former Member
0 Likes
1,059

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

Read only

SharathYaralkattimath
Contributor
0 Likes
1,059

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>.