‎2012 Feb 09 10:15 AM
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!
‎2012 Feb 09 1:36 PM
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.
‎2012 Feb 09 10:24 AM
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
‎2012 Feb 09 10:44 AM
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
‎2012 Feb 09 10:54 AM
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
‎2012 Feb 09 10:54 AM
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
‎2012 Feb 09 11:07 AM
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?
‎2012 Feb 09 1:36 PM
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.
‎2012 Feb 09 3:40 PM
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.
‎2016 Sep 15 7:44 AM
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.