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

Totalling with out NESTED LOOPS??

Former Member
0 Likes
534

Hi Experts,

I hv data in t_vbak and t_vbap itabs.

I need to SUM the QUANTITY i.e. VBAP-KWMENG for each VBELN in VBAK i.e each Doc.

So, normally, I use,

loop at t_vbak.

loop at t_vbap where vbeln = t_vbak-vbeln

tot_qty = tot_qty + vbap-kwmeng

endloop.

modify ......

endloop.

But, I do not wanna to use NESTED LOOPS, so, pls. let me any other solution?

thanq

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
513

Use COLLECT statement.


* Declare IT_SUM with VBELN and QTY

LOOP AT IT_VBAP.
IT_SUM-VBELN = IT_VBAP-VBELN.
IT_SUM-QTY = IT_VBAP-MENGE.
COLLECT IT_SUM.
CLEAR   IT_SUM.
ENDLOOP.

Regards,

Naimesh Patel

Hi Experts,

I hv data in t_vbak and t_vbap itabs.

I need to SUM the QUANTITY i.e. VBAP-KWMENG for each VBELN in VBAK i.e each Doc.

So, normally, I use,

loop at t_vbak.

loop at t_vbap where vbeln = t_vbak-vbeln

tot_qty = tot_qty + vbap-kwmeng

endloop.

modify ......

endloop.

But, I do not wanna to use NESTED LOOPS, so, pls. let me any other solution?

thanq

3 REPLIES 3
Read only

Sm1tje
Active Contributor
0 Likes
513

Forget it, wasn't look to well a coding....vbaK and vbaP

Sort the table by VBELN and next use SUM (standard ABAP statement) within loop at vbap.

Edited by: Micky Oestreich on May 12, 2008 10:12 PM

Edited by: Micky Oestreich on May 12, 2008 10:12 PM

Edited by: Micky Oestreich on May 12, 2008 10:14 PM

Read only

Former Member
0 Likes
513

make vbeln in another table of the same structure of t_vbap a key and then do this


loop at t_vbap.
read table t_vbak with key vbeln = vbap-vbenln.
if sy-subrc eq 0.
collect vbap into other_vbap.
endif.
endloop.

You will have the sum in kwmeng in the other table

Read only

naimesh_patel
Active Contributor
0 Likes
514

Use COLLECT statement.


* Declare IT_SUM with VBELN and QTY

LOOP AT IT_VBAP.
IT_SUM-VBELN = IT_VBAP-VBELN.
IT_SUM-QTY = IT_VBAP-MENGE.
COLLECT IT_SUM.
CLEAR   IT_SUM.
ENDLOOP.

Regards,

Naimesh Patel