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

Read Statement antwork

Former Member
0 Likes
1,305

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

12 REPLIES 12
Read only

Former Member
0 Likes
1,264

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.

Read only

Former Member
0 Likes
1,264

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

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,264

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

Read only

0 Likes
1,264

Hi Suhas,

Loop at item and read header ... but i stick with a sorted type item table and a nested loop.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,264

What's the use of a nested loop if you can avoid that ?

Read only

0 Likes
1,264

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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,264

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

Read only

faisalatsap
Active Contributor
0 Likes
1,264

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,264

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

Read only

ThomasZloch
Active Contributor
0 Likes
1,264

> 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

Read only

Former Member
0 Likes
1,264

Answered

Read only

0 Likes
1,264

>

> Answered

How? so that it will help the people who will search the similar problem.