‎2010 Aug 10 1:38 PM
Hi All,
I am having one record in it_vbrk table and in it_vbrp table i am having three records with same vbeln with three items.
Loop at it_vbrk into wa_vbrk.
Move: XXXX to XXXX
Read table it_vbrp into wa_vbrp with key vbeln = wa_vbrk-vbeln.
if sy-subrc = 0.
move: XXXX to XXX.
..
endif.
endloop.
here in the above code i am getting only one record output. but i need three records as output with all the three item details of it_vbrp.
i am not suppose to use loop inside a loop.
Please suggest with code example.
Regards,
Kumar
‎2010 Aug 10 1:42 PM
Hello,
You should loop at multiple records internal table.
Loop at it_vbrp into wa_vbrp.
Move: XXXX to XXXX
Read table it_vbrk into wa_vbrk with key vbeln = wa_vbrp-vbeln.
if sy-subrc = 0.
move: XXXX to XXX.
..
endif.
endloop.
It should work.
Thanks.
Tamya.
‎2010 Aug 10 1:43 PM
Hi,
In this scenario try to loop item table and read header table.
Loop at it_vbrp.
read it_vbrk with key .....
if sy-subrc = 0.
move xxx to xyz.
endif.
endloop.
Hope this works.
Thanks,
Venkat
‎2010 Aug 10 1:44 PM
My thumb rule:
"Always LOOP on the line item table & READ the header table"
Of course if there is any specific requirement you've not mentioned in the post, i will stick with my rule
‎2010 Aug 10 2:45 PM
Hi Suhas,
Loop at item and read header ... but i stick with a sorted type item table and a nested loop.
‎2010 Aug 10 2:57 PM
‎2010 Aug 10 3:00 PM
Just an example suhas,
What if the header contais 2 rows and item contains 2000 records related to it . Eventhough a control break and modify statement would do ... but when you measure the run time sorted tables gives you better results.
‎2010 Aug 10 3:21 PM
How can the header data contain multiple rows for the same document ?
AFAIK the header tables generally have the document number as the key fields (BKPF, MKPF, RBKP, VBAK, VBRK etc. )
I'm still not convinced a header table will contain multiple rows referencing to the same object. May be i'm wrong.
There are cases where "thumb rule" doesn't apply. I'm still not convinced OP needs a nested loop unless he mentions some special processing is needed.
BR,
Suhas
‎2010 Aug 10 1:45 PM
Hi, Kumar
You will have to use one inner LOOP to do this, READ TABLE will only return you one record at a time. Hope you understand.
Thanks and Best Regards,
Faisal
‎2010 Aug 10 1:47 PM
Some optimizations guidance :
- Try Parallel Cursor method : look at wiki sample at [Copy of ABAP Code for Parallel Cursor - Loop Processing |http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing]
- Reverse the order of table processing, using the item table in the external LOOP and READ to get the header table, but only if each and every header has a least one item, else you will miss some header records.
- Use a LOOP in another LOOP if the internal table is a SORTED or HASH (as of Release 7.0) one and the WHERE criteria are the key of the table (check LOOP [WHERE log_exp |http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_COND.htm#&ABAP_ADDITION_3@3@] online documentation)
Regards,
Raymond
‎2010 Aug 10 1:49 PM
> i am not suppose to use loop inside a loop.
This rule is nonsense. Make proper use of SORTED tables for the item table. Search for background information, especially in the ABAP Performance forum.
Thomas
‎2010 Aug 11 11:07 AM
‎2010 Aug 11 11:10 AM
>
> Answered
How? so that it will help the people who will search the similar problem.