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

ABAP adding minus values

Former Member
0 Likes
5,717

Hi experts,

Ive put in code in an abap driver program so as to loop through a table based on certain condtions. All my loops are working bar 1. The problem is,when my code loops through the porgram its treating minus vales and adding them rather then subtracting them.

As a result my final outputted figure is incorrect.

Heres my code:

FORM subtotal_accdue tables tab_regup structure regup

changing

i_subtotal_accduevalue TYPE REGUP-WRBTR.

IF REGUP-UMSKZ EQ SPACE.

i_subtotal_accduevalue = REGUP-WRBTR + i_subtotal_accduevalue.

REGUT-RBETR = i_subtotal_accduevalue.

endif.

ENDFORM.

Any help would be appreciated.

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,611

Why are you not considering the Debit/Credit Indicator for these values? And why is everything coded backward? You put the data into the object, not into its type....

Did you mean something like:

FORM subtotal_accdue tables tab_regup structure regup  "where are you handling the table?  there's no loop here
changing i_subtotal_accduevalue TYPE WRBTR. " I_SUBTOTAL_ACCDUEVALUE is used somewhere? 

loop at tab_regup assigning <lfs_reg>. " (of type regup).
 if <lfs_reg> is assigned.

IF <lfs_reg>-UMSKZ EQ SPACE.  "no special GL Account?

IF <lfs_reg>-SHKZG EQ 'S'."debit
i_subtotal_accduevalue = i_subtotal_accduevalue +  <lfs_reg>-WRBTR .
ELSEIF <lfs_reg>-SHKZG EQ 'H'. "credit
i_subtotal_accduevalue =  i_subtotal_accduevalue - <lfs_reg>-WRBTR .
endif.

else.????  REGUP-UMSKZ is not space?:  Is this what you mean?

i_subtotal_accduevalue = i_subtotal_accduevalue  + <lfs_reg>-rbetr. "where did REGUT come from?  

endif.  "UMSKZ populated

endif. "<fs> assigned
endloop.
ENDFORM.

OR? Just reading this, I'm not sure what your subroutine is supposed to do, but you're not going to accomplish what you need without correction.

8 REPLIES 8
Read only

Former Member
0 Likes
3,611

Hi Mike,

You could try to check if the value to be add or subtracted is a positive or negative value

FORM subtotal_accdue tables tab_regup structure regup

changing

i_subtotal_accduevalue TYPE REGUP-WRBTR.

IF REGUP-UMSKZ EQ SPACE.

if REGUP-WRBTR ge 0.

i_subtotal_accduevalue = REGUP-WRBTR + i_subtotal_accduevalue.

else. ** Negative value **

i_subtotal_accduevalue = i_subtotal_accduevalue - REGUP-WRBTR.

endif.

REGUT-RBETR = i_subtotal_accduevalue.

endif.

ENDFORM.

I am not sure which field would hold the negative value as you haven't mentioned it, but this would work assuming REGUP-WRBTR holding negative values

Edited by: AJ Nayak on Feb 9, 2012 11:30 AM

Read only

0 Likes
3,611

Hi AJ,

Thanks for the reply, I really appreciate any help.

I put into your suggestion but unfortunately the code still outputted the same result.

Iu2019m trying to query field DMSHB with data element DMSHB_X8 (Amount in Local Currency with +/- Signs). When I debug and run my code I can see it adds the plus values no problem. However when it reaches a minus value it for some reason treats it as a plus and adds it despite it being a negative. Iu2019m only new to sap so apologies if Iu2019m doing something stupid.

Thanks,

Mike

Read only

0 Likes
3,611

hi mike

that may be due to the data type you are using i.e curr

convert the values to the numeric data type and then perform the operations.

i hope this should help.

regards,

somesh

Read only

Former Member
0 Likes
3,611

Hi Mike,

Please check the datatype . It as float or integer . If you want it in currency field go for pack ( p ) type.

thanks,

Ben

Read only

0 Likes
3,611

Hi All,

Thanks for all the replies.

If im understanding your suggestions correctly: i checked the DMSHB field. It is a currency field.

REGUP-WRBTR is also a currency field. Therefore i would think that my code should work?

Read only

Former Member
0 Likes
3,612

Why are you not considering the Debit/Credit Indicator for these values? And why is everything coded backward? You put the data into the object, not into its type....

Did you mean something like:

FORM subtotal_accdue tables tab_regup structure regup  "where are you handling the table?  there's no loop here
changing i_subtotal_accduevalue TYPE WRBTR. " I_SUBTOTAL_ACCDUEVALUE is used somewhere? 

loop at tab_regup assigning <lfs_reg>. " (of type regup).
 if <lfs_reg> is assigned.

IF <lfs_reg>-UMSKZ EQ SPACE.  "no special GL Account?

IF <lfs_reg>-SHKZG EQ 'S'."debit
i_subtotal_accduevalue = i_subtotal_accduevalue +  <lfs_reg>-WRBTR .
ELSEIF <lfs_reg>-SHKZG EQ 'H'. "credit
i_subtotal_accduevalue =  i_subtotal_accduevalue - <lfs_reg>-WRBTR .
endif.

else.????  REGUP-UMSKZ is not space?:  Is this what you mean?

i_subtotal_accduevalue = i_subtotal_accduevalue  + <lfs_reg>-rbetr. "where did REGUT come from?  

endif.  "UMSKZ populated

endif. "<fs> assigned
endloop.
ENDFORM.

OR? Just reading this, I'm not sure what your subroutine is supposed to do, but you're not going to accomplish what you need without correction.

Read only

0 Likes
3,611

THANK YOU BREAKPOINT:

You were correct.Thanks for the help.

Heres my code to anyone that was having a similar problem:

FORM subtotal_accdue tables tab_regup structure regup

changing

i_subtotal_accduevalue TYPE REGUP-WRBTR.

IF REGUP-UMSKZ EQ SPACE.

IF REGUP-SHKZG EQ 'H'.

i_subtotal_accduevalue = i_subtotal_accduevalue - REGUP-WRBTR.

REGUT-RBETR = i_subtotal_accduevalue.

ELSEIF REGUP-SHKZG EQ 'S'.

i_subtotal_accduevalue = i_subtotal_accduevalue + REGUP-WRBTR.

REGUT-RBETR = i_subtotal_accduevalue.

endif.

endif.

ENDFORM.

Thanks to all experts for your replies.

Read only

0 Likes
3,611

Thank You Very Much Michael.

I was having exactly same problem.

Capturing the value in the extra variable helped me solve the problem.

Thanks again for the great help.

Kind Regards,

Suchitra.