‎2008 Apr 24 4:17 PM
Hi,
My Scenario :
I have two dynamic internal tables.
I am looping at one internal table and trying to read another table.
In the read statement how do I mention the key dyamically.
Example code below :
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
read second dynamic internal table.
enloop.
The key which I want use for reading say it is keyed in the selection criteria....
Also based on the value I read I want to modify the first internal table field value.
Remember I dont want to explicity mention the key
How do I do that?
Thanks
Krishna.
‎2008 Apr 24 4:25 PM
Hi
U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA2> TO <FS>.
CHECK <FS> IN (=) .......
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA> TO <FS2>.
<FS2> = .......
EXIT.
ENDLOOP.
ENDLOOP.Max
‎2008 Apr 24 4:19 PM
Check this Example..
code
DATA: itab TYPE STANDARD TABLE OF mara.
DATA: wa TYPE mara.
DATA: where(72).
DATA: where1(72).
Populate.
wa-matnr = 'TEST'.
wa-mtart = 'M1'.
APPEND wa TO itab.
Where clause
where = 'MATNR'.
where1 = 'MTART'.
READ TABLE itab INTO wa WITH KEY (WHERE) = 'TEST'
(WHERE1) = 'M1'.
IF sy-subrc = 0.
WRITE: / 'found'.
ENDIF.
[/code]
regards,
venkat.
‎2008 Apr 24 4:41 PM
Hi,
READ TABLE itab INTO wa WITH KEY (WHERE) = 'TEST'
'TEST' should not be hardcoded as well.
That will be the field from first internal table.
Thanks,
krishna.
‎2008 Apr 24 4:25 PM
Hi
U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA2> TO <FS>.
CHECK <FS> IN (=) .......
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA> TO <FS2>.
<FS2> = .......
EXIT.
ENDLOOP.
ENDLOOP.Max
‎2008 Apr 24 8:53 PM
Hi Max,
Thankyou . I got it.
Sample coding :
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
READ TABLE ifc INTO wa_ifc WITH KEY fieldname = p_fname.
IF sy-subrc EQ 0.
ASSIGN COMPONENT p_fname OF STRUCTURE <dyn_wa> TO <dyn_wa1>.
READ TABLE it_maptab
WITH KEY matkl = <dyn_wa1> ASSIGNING <fs_tab3>.
<dyn_wa1> = <fs_tab3>-znew_matgrp.
ENDIF.
ENDLOOP.
points rewarded.
Thanks,
Krishna.