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: 

Issue with reading one internal table and passing all records

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

5 REPLIES 5

ThomasZloch
Active Contributor
0 Kudos

Use LOOP AT instead of READ. it_functab should be defined as SORTED table with non-unique table key object_id.

Thomas

Former Member
0 Kudos

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.

0 Kudos

Loop inside a loop will cause perfromance issue thatswhy I want to do it using Read statement.

Regards,

Rajesh.

0 Kudos

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

0 Kudos

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.