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

SUM

Former Member
0 Likes
1,065

hi ,

i need to add the DMBTR based on ZUONR(Assignment field).

Suppose i have the values as

BELNR ZUONR DMBTR

1001 KP2345 200

1001 KP2345 300

1001 KP2345 100

1001 MT9872 500

1001 MT9872 400

the output should be as

BELNR ZUONR DMBTR

1001 KP2345 600

1001 MT9872 900

Based on BELNR and ZUONR the values of DMBTR should be added .

from above the ZUONR = KP2345 Whereas DBMTR should be added of the same ZUONR

200 + 300 + 100 = 600 SHOULD display as one line item in the output.

please see my code below

DATA: BEGIN OF GT_BSEG ,

BUKRS LIKE BSEG-BUKRS, "company code

BELNR LIKE BSEG-BELNR, "Document number

GJAHR LIKE BSEG-GJAHR, "Fiscal year

DMBTR LIKE BSEG-DMBTR, "Amount in local currency

WRBTR LIKE BSEG-WRBTR, "Amount in document currency

PSWSL LIKE BSEG-PSWSL,

ZUONR LIKE BSEG-ZUONR,

HKONT LIKE BSEG-HKONT, "General ledger account

END OF GT_BSEG.

DATA: BEGIN OF gt_output ,

zuonr LIKE bseg-zuonr,

dmbtr LIKE bseg-dmbtr,

END OF gt_output.

LOOP AT gt_bseg.

AT END OF zuonr.

gt_output-zuonr = gt_bseg-zuonr.

SUM.

gt_output-dmbtr = gt_bseg-dmbtr.

APPEND gt_output.

CLEAR gt_output.

ENDAT.

ENDLOOP.

i got all the data to gt_bseg internal table.

please help .

8 REPLIES 8
Read only

Former Member
0 Likes
1,000

you can use COLLECT here!!!

it will some up all the values perfectly

regards

bhanu

Read only

Former Member
0 Likes
1,000

use



LOOP AT gt_bseg.
collect gt_bseg into gt_output.
ENDLOOP.

Thanks

Amitava

Read only

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

Hello,

As suggested COLLECT is the best solution:

LOOP AT gt_bseg.
  gt_output-zuonr = gt_bseg-zuonr.
  gt_output-dmbtr = gt_bseg-dmbtr.
  COLLECT gt_output.
  CLEAR gt_output.
ENDLOOP.

Hope this helps !!

BR,

Suhas

Read only

Former Member
0 Likes
1,000

Dear ,

Its very simple goto se11 in the domain of your field

Goto output characteristices --- > Convers. routine and one routine .

Then goto se37 write one routine and attach it there .

In this routine do th processing wht all you want .

Rgds ankit

Read only

Former Member
0 Likes
1,000

And if you want this in code then wht its written above posts tht using COLLECT is best way .

Read only

Former Member
0 Likes
1,000

Hi!

Maybe the results is incorrect because the field ZUONR have to be index, check out your internal table and keep in ZUONR be the firts field declaraded.

I hope this helps,

Regards!

Read only

Former Member
0 Likes
1,000

Write the select query as follows---

select BELNR ZUONR sum( DMBTR ) from bseg where ZUONR = ---.

hope this will solve ur problem.

Read only

Former Member
0 Likes
1,000

This is incorrect because BSEG only captures positive amounts. You have to take the debit/credit indicator - BSEG-SHKZG into account when adding these amounts.

Rob