Search
Search

# calculating totals by customer based on invoice -credits

I am trying to get an output for customers that purchased at a trade show. A customer may have credits applied so I need to subtract the credit from the invoices generated.

eg. customer purchased \$200 of product at a show but returned \$150 so I want the report to reflect overall sales of \$50.

This is the logic I am using in my report. I don't think the collect statement works in this scenario because I am applying a negative number to a positive number. How do I get around this?

SELECT * FROM VBAK WHERE ERDAT IN DATE AND

KVGR1 = I_SHOW-SHOW_C.

I_SHOW-ORDER = VBAK-VBELN.

ITAB-CUST = VBAK-KUNNR.

*CHECKS BILLING TABLE FOR \$ AND QTY.

SELECT * FROM VBRP WHERE AUBEL = I_SHOW-ORDER.

ITAB-OR_TYPE = VBRP-AUTYP.

CASE ITAB-OR_TYPE.

WHEN 'C'.

ITAB-COUNT = VBRP-BONBA.

WHEN 'H'.

ITAB-COUNT = VBRP-BONBA * ( -1 ).

WHEN 'O'.

ITAB-COUNT = VBRP-BONBA * ( -1 ).

WHEN OTHERS.

ITAB-COUNT = VBRP-BONBA.

ENDCASE.

SELECT SINGLE * FROM KNA1 WHERE KUNNR = ITAB-CUST.

IF SY-SUBRC = 0.

ITAB-NAME = KNA1-NAME1.

ENDIF.

COLLECT ITAB.

SORT ITAB BY CUST.

TOT_NETWR = TOT_NETWR + ITAB-COUNT.

ENDSELECT.

ENDSELECT.

ENDIF.

IF RB_CUST = 'X'.

WRITE: 01 'CUSTOMER',

20 'NAME',

50 'TOTAL'.

ENDIF.

LOOP AT ITAB.

WRITE: /01 ITAB-CUST,

20 ITAB-NAME,

50 ITAB-COUNT.

ENDLOOP.

##### Former MemberOctober 07, 2008 at 21:38 PM0 Likes
View more on this topic or