Application Development 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: 

How can I make a dynamic Read Table?

former_member220448
Participant
0 Kudos

Hi all,

I need to create a dynamic Read Table.

Thing is like this:

My key needs to be dynamic, not just the values but the fields too.

Has to be something like this:

READ TABLE l_i_table ASSIGNING <table>

WITH KEY field_1 = value_1

                  field_2 = value_2 

                  ....

                  field_n = value_n.

The fields to be used in the key (field_1, field_2 ... field_n) are read from a dictionary table.

                   

Any idea?

Thanks in advance.

Nico.-

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

If you know the maximum no of keys, then you can use the approach listed above.

If you dont, check my reply in this post.

http://scn.sap.com/thread/3169985

Thanks,

Shambu

5 REPLIES 5

carlos_rodriguez4
Active Participant
0 Kudos

DATA KEY1(10) DEFAULT ‘FIELD’

READ TABLE ALL_CUSTOMERS WITH KEY (KEY1) = VALUE1.


0 Kudos

Thanks Carlos

But remember I can have n fields, how can I add fields to the key?

Former Member
0 Kudos

READ TABLE itab WITH KEY k1 = f1 ... kn = fn result.

The search key consists of arbitrary table fields k1 ... kn. If you do not know the name of a component until runtime, you can specify it dynamically as the content of a field n1 ... nn using (n1) = f1 (n2) = f2 . If n1 ... nn is empty when the statement is executed, the search field is ignore

Former Member
0 Kudos

Hi,

If you know the maximum no of keys, then you can use the approach listed above.

If you dont, check my reply in this post.

http://scn.sap.com/thread/3169985

Thanks,

Shambu

0 Kudos

Thanks Shambu

I was doing it by using 10 variables in the key guessing there will not be more than 10 fields, but your apporach to make the whole statement dynamic is great. I will use that,

Thanks.

Nico.-