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

Help needed for abap statement-sum()

Former Member
0 Likes
1,350

Hi i have an code as below:

...

...

MDMBTR = 0 .

MDMBTR1 = 0 .

MDMBTR2 = 0 .

MDMBTR3 = 0 .

V_MDMBTR = 0 .

Select * from BSIK for all entries in REC_ITAB into table IT_BSIK WHERE BUKRS = REC_ITAB-YBUKRS

AND LIFNR = REC_ITAB-YLIFNR

AND GJAHR = REC_ITAB-YGJAHR

AND BELNR = REC_ITAB-YBELNR.

MDMBTR = MDMBTR + BSIK-DMBTR .

endselect.

MOderator Message: Basic Question. Thread Locked. Points unassigned.

I wanted to perform this addtion in the select query itself using sum() .-BSIK-DMBTR . As the whole statement is inside the loop..so can you help me modify the code of select to include this sum also there.please help as iam not an abaper.

Edited by: kishan P on Nov 17, 2010 6:57 AM

8 REPLIES 8
Read only

Former Member
0 Likes
1,137

Hi Meenakshi,

Try to move internal table to work area,then sum accordingly.

Regards,

Venkat.

Read only

0 Likes
1,137

hI ,

Please show me code as i need to underatand the same.

Read only

0 Likes
1,137

If you use 'SUM ( dmbtr )', you need to select the SHKZG field as well (debit/credit indicator) and use 'GROUP BY shkzg' in the SELECT statement. Consider the debit/credit indicator in your aggregation inside the SELECT...ENDSELECT loop. Consult your development team for more assistance.

As for the previous post, the poster obviously failed to consider the dr/cr indicator - it should never be taken for granted that the direction is always the same, even on the same document - not to mention the cross-document implications...

Edited by: Brad Bohn on Nov 16, 2010 12:34 PM

Read only

Former Member
0 Likes
1,137

Hi,

DATA:v_mdmbtr like DBTABLE-MDMBTR.

DATA: WA_BSIK LIKE LINES OF IT_BSIK.

CLEAR:V_MDMBTR, WA_BSIK.

LOOP MAIN TABLE.

READ TABLE IT_BSIK INTO WA_BSIK.

V_MDMBTR = V_MDMBTR + WA_BSIK-DMBTR.

ENDLOOP MAIN TABLE.

try like above.

Reagrds,

Venkat.

Read only

0 Likes
1,137

The actual code is like below:

SELECT *

FROM BSAK

WHERE BUKRS = REC_ITAB-YBUKRS

AND LIFNR = REC_ITAB-YLIFNR

AND GJAHR = REC_ITAB-YGJAHR

AND BELNR = REC_ITAB-YBELNR .

MDMBTR = MDMBTR + BSAK-DMBTR .

ENDSELECT .

Just wanted to add that sum(DMBTR) in the code i mean.

sorry for confusion on the above code.

Read only

Former Member
0 Likes
1,137

Hi,

instead of


Select * from BSIK for all entries in REC_ITAB into table IT_BSIK WHERE BUKRS = REC_ITAB-YBUKRS
AND LIFNR = REC_ITAB-YLIFNR
AND GJAHR = REC_ITAB-YGJAHR
AND BELNR = REC_ITAB-YBELNR.

MDMBTR = MDMBTR + BSIK-DMBTR .
endselect.

use


Select * from BSIK for all entries in REC_ITAB into table IT_BSIK WHERE BUKRS = REC_ITAB-YBUKRS
AND LIFNR = REC_ITAB-YLIFNR
AND GJAHR = REC_ITAB-YGJAHR
AND BELNR = REC_ITAB-YBELNR.

loop at it_bsik.
sum.
MDMBTR  = it_bsik-DMBTR.
endloop.

Thanks,

Anmol.

Read only

0 Likes
1,137

hI anmol,

does the sum in the code???what it does..i mean its just the statement with sum and no values.

Is the syntax like that???

loop at it_bsik.

sum.

MDMBTR = it_bsik-DMBTR.

endloop.

Edited by: Meenakshi C on Nov 16, 2010 7:49 PM

Read only

0 Likes
1,137

Yes Minakshi,

this syntax will sum up all the integer type fields.

Try it.

Thanks,

Anmol.