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

wrong calculation

Former Member
0 Likes
852

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.

7 REPLIES 7
Read only

Former Member
0 Likes
798

Hi khan,

try <b>clearing itab</b> also.

this might solve ur problem.

<b>Reward points if this solves ur problem.</b>

Kiran

Read only

Former Member
0 Likes
798

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

Read only

0 Likes
798

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.

Read only

Former Member
0 Likes
798

Hi Khan,

Since it is Debit and Credit calculation , try to multiply debit value -1.

Reward if useful!

Read only

Former Member
0 Likes
798

Dear Khan,

If you send your select statement or full code probably i can help you!

Antony Thomas

Read only

0 Likes
798

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.

Read only

Former Member
0 Likes
798

answred