Application Development 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: 

calculating totals by customer based on invoice -credits

Former Member
0 Kudos

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.

3 REPLIES 3

Former Member
0 Kudos

Hi,

The COLLECT can handle negatives. Try this simple example and put in both positive and negative numbers in the parameter values. You will see that negatives do not bother the COLLECT statement.


REPORT  ZTESTJRG.

parameters: p_n1 type bonba,
            p_n2 type bonba,
            p_n3 type bonba.

data: itab type table of vbrp with header line.

itab-bonba = p_n1.
collect itab.

itab-bonba = p_n2.
collect itab.

itab-bonba = p_n3.
collect itab.

write: /1 p_n1, '+', p_n2, '+', p_n3.

loop at itab.
  write: /1 itab-bonba.
endloop.

What exactly is the result that you are getting which you think is wrong? Please explain further. What are the data types for your itab fields?

Regards,

Jamie

Former Member
0 Kudos

Do you want all order types from VBRP? Currently, you multiply returns and credit memos by -1, but are taking all other order types.

Also, VBRP-BONBA has a sign, so you may be negating an already negative number.

Rob

Former Member
0 Kudos

I have resolved the issue by using two internal tables -one for invoice totals and one for credits. I then do some math to do the final calculation invoice total-credits.

thank you for taking the time to answer one question.