‎2010 Nov 16 5:46 PM
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
‎2010 Nov 16 5:54 PM
Hi Meenakshi,
Try to move internal table to work area,then sum accordingly.
Regards,
Venkat.
‎2010 Nov 16 5:59 PM
‎2010 Nov 16 6:33 PM
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
‎2010 Nov 16 6:29 PM
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.
‎2010 Nov 16 6:33 PM
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.
‎2010 Nov 16 6:33 PM
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.
‎2010 Nov 16 6:49 PM
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
‎2010 Nov 16 7:07 PM
Yes Minakshi,
this syntax will sum up all the integer type fields.
Try it.
Thanks,
Anmol.