10-16-2008 3:58 PM
Gurus,
I have a situation where I have to read an internal table ITAB with a key. Now ITAB can have multiple values for the same key, so I want to pass all the records found in ITAB for that key in other internal table.
DATA: BEGIN OF it_functab OCCURS 0,
OBJECT_ID type SDOK_PHID,
FUNC_LOC TYPE TPLNR,
END OF it_functab.
DATA: wa_functab like it_functab occurs 0 with header line.
:
:
sort it_functab by object_id.
loop at it_proctab.
READ table it_functab into wa_functab with key object_id = it_proctab-object_id binary search transproting all fields.
endloop.
There are atleast three records in it_functab for a object_id, but in the wa_functab only one record is passed.
Please help.
Regards,
Rajesh.
10-16-2008 4:01 PM
Instead of read use loop with where clause...
DATA: BEGIN OF it_functab OCCURS 0,
OBJECT_ID type SDOK_PHID,
FUNC_LOC TYPE TPLNR,
END OF it_functab.
DATA: wa_functab like it_functab occurs 0 with header line.
:
:
sort it_functab by object_id.
loop at it_proctab.
Loop at it_functab into wa_functab where object_id = it_proctab-object_id.
<< Here Populate records into another internal table
Endloop.
endloop.
10-16-2008 3:59 PM
Use LOOP AT instead of READ. it_functab should be defined as SORTED table with non-unique table key object_id.
Thomas
10-16-2008 4:01 PM
Instead of read use loop with where clause...
DATA: BEGIN OF it_functab OCCURS 0,
OBJECT_ID type SDOK_PHID,
FUNC_LOC TYPE TPLNR,
END OF it_functab.
DATA: wa_functab like it_functab occurs 0 with header line.
:
:
sort it_functab by object_id.
loop at it_proctab.
Loop at it_functab into wa_functab where object_id = it_proctab-object_id.
<< Here Populate records into another internal table
Endloop.
endloop.
10-16-2008 4:04 PM
Loop inside a loop will cause perfromance issue thatswhy I want to do it using Read statement.
Regards,
Rajesh.
10-16-2008 4:16 PM
Please see my answer above. No performance issue when using sorted tables as described, because implicit binary search will be used in the inner loop.
Thomas
10-16-2008 4:17 PM
As u mentioned earlier in ur 2nd table u have 3 records which are matching the 1st table key..if this is the case then I donot think it is aperformance issue but say u have lot of records which are matching with the a key of the outer table then u can use parallel cursor technique to improve the performance.