‎2007 Jul 04 1:20 PM
HI Experts!
I have a customer balance report. in some customer A/c No. the calculation is wrong. Mostly it makes it double. i.e if any cust. a/c has 2 Debit 1,200 each. Its must show the total 2,400. but its showing 4,800. this problem is there is some A/c. is there any problem in my Loop. If there is any problem in loop then why other cust. A/c are showing correctly. for ur refrence below is the loop code.
SORT ITAB BY KUNNR.
LOOP AT ITAB.
IF ITAB-SHKZG = 'S'.
WCREDIT = WCREDIT + ITAB-DMBTR.
ELSEIF ITAB-SHKZG = 'H'.
WDEBIT = WDEBIT + ITAB-DMBTR.
ENDIF.
ITAB-CREDIT = WCREDIT.
ITAB-DEBIT = WDEBIT.
ITAB-AMOUNT = ITAB-CREDIT - ITAB-DEBIT.
MOVE-CORRESPONDING ITAB TO FINAL.
AT END OF KUNNR.
APPEND FINAL.
CLEAR : WCREDIT , WDEBIT.
ENDAT.
ENDLOOP.
any need to update the code. Plz help. i need it urgently. thanks. alot.
Khan.
‎2007 Jul 04 1:28 PM
Hi khan,
try <b>clearing itab</b> also.
this might solve ur problem.
<b>Reward points if this solves ur problem.</b>
Kiran
‎2007 Jul 04 1:29 PM
Hi
do like this
SORT ITAB BY KUNNR.
LOOP AT ITAB.
IF ITAB-SHKZG = 'S'.
WCREDIT = WCREDIT + ITAB-DMBTR.
ELSEIF ITAB-SHKZG = 'H'.
WDEBIT = WDEBIT + ITAB-DMBTR.
ENDIF.
ITAB-CREDIT = WCREDIT.
ITAB-DEBIT = WDEBIT.
ITAB-AMOUNT = ITAB-CREDIT - ITAB-DEBIT.
MOVE-CORRESPONDING ITAB TO FINAL.
APPEND FINAL.
CLEAR : WCREDIT , WDEBIT.
ENDLOOP.
Itab final1 will have only KUNNR and TOTALS of DEBIT,CREDIT,AMOUNT
SORT final BY KUNNR.
LOOP AT final.
AT END OF KUNNR.
read table final index sy-tabix.
SUM.
MOVE-CORRESPONDING FINAL TO FINAL1.
APPEND FINAL1.
ENDAT.
clear final1.
ENDLOOP.
<b>Reward points for useful Answers</b>
Regards
Anji
‎2007 Jul 05 5:27 AM
hi Anji,
Thanks for replying. IS your code also works for range of Cust. A/c like If on selection screen I enter PC04000001 To PC04000009. or ur code is just for single entry? Coz I think At End of KUNNR code should be before end of first ENDLOOP. Plz clearify me.
Thanks Alot.
Khan.
‎2007 Jul 04 1:30 PM
Hi Khan,
Since it is Debit and Credit calculation , try to multiply debit value -1.
Reward if useful!
‎2007 Jul 04 1:34 PM
Dear Khan,
If you send your select statement or full code probably i can help you!
Antony Thomas
‎2007 Jul 05 5:14 AM
hi thomas,
Below is the code with select statement. plz help me out.
********************************************************************************************
SELECT-OPTIONS : S_BUKRS FOR BSEG-BUKRS NO-EXTENSION NO INTERVALS ,
S_KUNNR FOR BSEG-KUNNR ,
S_ERDAT FOR BKPF-BUDAT OBLIGATORY DEFAULT SY-DATUM TO SY-DATUM .
SELECTION-SCREEN : END OF BLOCK B1.
SELECT BELNR BUDAT FROM BKPF INTO (WBELNR , WBUDAT ) WHERE BUDAT IN S_ERDAT.
SELECT DMBTR KUNNR KOART SHKZG FROM BSEG INTO (ITAB-DMBTR ,ITAB-KUNNR , ITAB-KOART ,ITAB-SHKZG)
WHERE BUKRS IN S_BUKRS
AND KUNNR IN S_KUNNR
AND KOART EQ 'D'
AND AUGBL EQ SPACE
AND ( UMSKZ EQ SPACE OR UMSKZ EQ 'A')
AND BELNR = WBELNR.
APPEND ITAB.
ENDSELECT.
ENDSELECT.
LOOP AT ITAB.
SELECT SINGLE NAME1 ORT01 FROM KNA1 INTO (ITAB-NAME , ITAB-ORT01) WHERE KUNNR = ITAB-KUNNR.
MODIFY ITAB.
ENDLOOP.
SORT ITAB BY KUNNR.
LOOP AT ITAB.
IF ITAB-SHKZG = 'S'.
WCREDIT = WCREDIT + ITAB-DMBTR.
ELSEIF ITAB-SHKZG = 'H'.
WDEBIT = WDEBIT + ITAB-DMBTR.
ENDIF.
ITAB-CREDIT = WCREDIT.
ITAB-DEBIT = WDEBIT.
ITAB-AMOUNT = ITAB-CREDIT - ITAB-DEBIT.
MOVE-CORRESPONDING ITAB TO FINAL.
AT END OF KUNNR.
APPEND FINAL.
CLEAR : WCREDIT , WDEBIT.
ENDAT.
ENDLOOP.
*********************************************************************************************
Thanks. alot.
Khan.
‎2007 Jul 05 11:58 AM