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: 

Sum use to subract the negative values in At end of field control comand.

Former Member
0 Kudos

Hi all,

I have the item values of both positive and negative values, the requirement was to display the I_DISPLAY-WRBTR value with a negative sign at its end if the posting key is 22.

So I used a variable V_WRBTR of type Nlength 14 to concatenate field I_DISPLAY-WRBTR of type quan length 13, with -ve sign if the condition for posting key satisfied. diplayed both fields ,under 1 column as the line items.

Now I am facing the problem for calculating the total per company code of this column.I used SUM in the AT END ofI_DISPLAY-BURKS. IT IS SUMMING THE NEGATIVE VALUES ALSO instead of subracting along with the positive values.

ex: V_WRBTR / I_DISPLAY-WRBTR

86.50-

30.50

then it should give the total as 56, instead its showing 117.00

Suggest me the possible reason n solution for this behaviour of SUM.

Thanks in advance,

Selina.

Edited by: Selina.selk on Sep 10, 2009 11:36 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Just give the data type as i instead of N. It will work fine.

13 REPLIES 13

Former Member
0 Kudos

Hi

Please try this.

data : v_char(20).

data : v_val type i.

v_val = v_val - 50.

if v_val < 0.

write v_val to v_char.

concatenate v_char '-' into char .

condense char no-gaps.

endif.

write : / char.

Thanks

Venkat

0 Kudos

why is it not considering the -ve sign and summing up the negative value instead of substracting?

Former Member
0 Kudos

Hi ..

This is a sample code which i wrote for the SUM .. It is wrking fine.


  TYPES: BEGIN OF ty_test,
           matnr TYPE matnr,
           amount TYPE wrbtr,
         END OF ty_test.
  DATA i_test TYPE TABLE OF ty_test.
  DATA w_test TYPE ty_test.

  MOVE 1 TO w_test-matnr.
  MOVE 100 TO w_test-amount.
  APPEND w_test TO i_test.
  MOVE 1 TO w_test-matnr.
  MOVE 200 TO w_test-amount.
  w_test-amount = w_test-amount * -1.
  APPEND w_test TO i_test.
  MOVE 2 TO w_test-matnr.
  MOVE 300 TO w_test-amount.
  APPEND w_test TO i_test.
  MOVE 2 TO w_test-matnr.
  MOVE 500 TO w_test-amount.
  w_test-amount = w_test-amount * -1.
  APPEND w_test TO i_test.

  LOOP AT i_test INTO w_test.
    AT END OF matnr.
      SUM.
      WRITE: w_test-amount.
    ENDAT.
  ENDLOOP.

Former Member
0 Kudos

Hi

Just give the data type as i instead of N. It will work fine.

0 Kudos

AS I AM USING CONCATENATE STATEMENT TO CONCATENATE - SIGN , ITS NOT LETTING ME TO DECLARE AS TYPE I. Here is my code.Please suggest the changes for getting the total correctly.

Data: V_WRBTR(14) TYPE N,

V_WRBTR1(14) TYPE N,

LOOP AT I_DISPLAY.

READ TABLE I_BSEG INTO WA_BSEG with key belnr = i_display-belnr BSCHL = 22 BINARY SEARCH.

IF SY-SUBRC = 0.

V_WRBTR1 = I_DISPLAY-WRBTR.

CONCATENATE V_WRBTR1 '-' INTO V_WRBTR.

WRITE :109 V_WRBTR currency '*'

ELSE.

WRITE :108 I_DISPLAY-WRBTR currency '*'

AT END OF BUKRS.

SUM.

108 I_DISPLAY-WRBTR currency '*'

ENDAT.

ENDLOOP.

0 Kudos

Hi,

Why are you concatenating. Just multiply with -1. See my example code

Regards

Ansair

0 Kudos

(I am concatinating with - sign as I want to display the value with -ve sign in the right of the value

for the line items field which satisfies posting key Bschl = 22.

example want to display as 85.50-)

Now I have modified my code as beIow.I am Staight away multiplying the I_DISPLAY-WRBTRN with -1. with out using any variables .But in display Iam getting as 85.50 instead of 85.50 and its summing up again though while debugging its showing as 85.50-.

LOOP at I_DISPLAY

READ TABLE I_BSEG INTO WA_BSEG with key belnr = i_display-belnr BSCHL = 22 BINARY SEARCH.

IF SY-SUBRC = 0.

I_DISPLAY-WRBTRN = I_DISPLAY-WRBTRN * -1.

WRITE : 108 I_DISPLAY-WRBTR currency '*'

else.

WRITE : 108 I_DISPLAY-WRBTR currency '*'

Endif.

AT END OF BUKRS.

SUM.

Endat.

Endloop.

0 Kudos

You will get the idea just check this

its because you are not updating the values multiplied in your internal table.


LOOP at I_DISPLAY
READ TABLE I_BSEG INTO WA_BSEG with key belnr = i_display-belnr BSCHL = 22 BINARY SEARCH.
IF SY-SUBRC = 0.
I_DISPLAY-WRBTRN = I_DISPLAY-WRBTRN * -1.
modify I_DISPLAY transporting WRBTRN.         
endif.
Endloop.

LOOP at I_DISPLAY
WRITE : 108 I_DISPLAY-WRBTR currency '*' 
AT END OF BUKRS.
SUM.
write I_DISPLAY-WRBTRN.
Endat.
Endloop.

or try this


data:sum_val type i.

LOOP at I_DISPLAY.
READ TABLE I_BSEG INTO WA_BSEG with key belnr = i_display-belnr BSCHL = 22 BINARY SEARCH.
IF SY-SUBRC = 0.
I_DISPLAY-WRBTRN = I_DISPLAY-WRBTRN * -1.
write I_DISPLAY-WRBTRN.
else.
write I_DISPLAY-WRBTRN.
endif.
sum_val = sum_val + I_DISPLAY-WRBTRN.

at end of bukrs.
write sum_val.
clear sum_val.
endat.

endloop.


Edited by: Keshu Thekkillam on Sep 10, 2009 4:42 PM

0 Kudos

Hi all,

Thank you all for the quick reply.

My issue is solved.

Best regards,

Selina.

Former Member
0 Kudos

That is because N (Numeric) data type doesnot take into account negative values..

use i (integer) instead

Former Member
0 Kudos

Hi,

Please declare the variable as Integer. It wil work fine.

Thanks,

Nit.

Edited by: Nitesh Babu on Sep 10, 2009 12:11 PM

Edited by: Nitesh Babu on Sep 10, 2009 12:13 PM

kesavadas_thekkillath
Active Contributor
0 Kudos

as far i see its becuse of concatenating '-' sign

instead of that multiply the value by -1.

and then sum it.

declare the variable of type i or p.

Former Member
0 Kudos

After concatenating and getting the valiue in the variable, put the values in a new variable of type i and then use it for calculation