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

Dyanamic read statement

Former Member
0 Likes
657

Hi,

can any one help me how to write dyanamic READ statement

If we do not know the name of a component until runtime, then how we can use the expression WITH TABLE KEY ... to specify it keys dynamically .

please send some sample code to illustrate

thanks...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
626

Hai Bobby,

Do you want to pass the fields dynamically ? Then use the statement

read table it_tab with key (fieldname) = 'VALUE'.

6 REPLIES 6
Read only

Former Member
0 Likes
627

Hai Bobby,

Do you want to pass the fields dynamically ? Then use the statement

read table it_tab with key (fieldname) = 'VALUE'.

Read only

0 Likes
626

hi,

try:

DATA key1(72) VALUE 'BUKRS'.

...

read table itab with key (key1) = ztab-bukrs.

Message was edited by: Andreas Mann

Read only

Former Member
0 Likes
626

A)

DATA: T LIKE STANDARD TABLE OF BKPF WITH HEADER LINE.

DATA: FIELD1(10),

FIELD2(10).

FIELD1 = .....

FIELD2 = .....

READ TABLE T WITH TABLE KEY (FIELD1) = <VALUE>

(FIELD2) = <VALUE>.

B)

DATA: T LIKE STANDARD TABLE OF BKPF WITH HEADER LINE WITH NON-UNIQUE KEY BUKRS BELNR.

DATA: FIELD1(10),

FIELD2(10).

FIELD1 = .....

FIELD2 = .....

READ TABLE T WITH TABLE KEY (FIELD1) = <VALUE>

(FIELD2) = <VALUE>.

Max

Read only

0 Likes
626

hi,

but can you tell me how to pass whole key with fields & value

thanks

Read only

0 Likes
626

Hi,

1.You can fill the fieldname statically or dynamically using cl_abap_*type classes.

2. you can fill the fieldvalue using ASSIGN ...COMPONENT

variant like this..

field-symbols: <lv_field_value> type any.

ASSIGN COMPONENT fieldname

OF STRUCTURE ls_strucure_name TO <lv_field_value>.

If it is assigned sy-subrc will be 0.

Regards,

Suresh

Read only

0 Likes
626

Hi,

could you please tell me how to pass the key fields and the value as in the below read statement in brackets dyanamically because I have senario where different fields are being populated for different cases.

read table itab with key ( matnr = jtab-matnr

werks = jtab-werks )

thanks