0 pts.
 COBOL ‘Divide By Giving Remainder’ Code Not Working Correctly
Good Afternoon! I would appreciate any assistance with the following coding question. ARH-UNITS database field is defined as Signed 7,2. Initial value of zero. ARH-HOURS database field is defined as Signed 4,2. Initial value of 1.75. 03 WS-CAL-UNITS PIC S9(5) VALUE ZEROS. 03 WS-CAL-REMAINDER PIC SV9(2) VALUE ZEROS. The following 'Divide By' code should produce WS-CAL-UNITS=1 and WS-CAL-REMAINDER=.160. Instead, WS-CAL-REMAINDER always produces .250. Why? What do I need to do to get the appropriate remainder? COMPUTE ARH-UNITS = ARH-HOURS / 1.5 COMPUTE WS-UNIT-RATE = RCF-RATE * 1.5 DIVIDE ARH-HOURS BY 1.5 GIVING WS-CAL-UNITS REMAINDER WS-CAL-REMAINDER EVALUATE TRUE WHEN WS-CAL-REMAINDER = ZERO MOVE ZERO TO WS-CAL-REMAINDER WHEN WS-CAL-REMAINDER < .34 MOVE .3 TO WS-CAL-REMAINDER WHEN WS-CAL-REMAINDER < .51 etc.... Once again, any assistance would be greatly appreciated! Thank you!!!

Software/Hardware used:
ASKED: November 12, 2004  1:25 PM
UPDATED: February 23, 2010  3:16 PM

Answer Wiki:
First try changing the WS_CAL_REMAINDER field to SV9(3). The actual value returned should be .16666666 so, depending on which COBOL you are using and how rounding is defined either in the code or preferences you could be rounding up because the field is being truncated. Since you aren't using COMP or COMP-3 fields the compiler has to convert the results back and forth to display mode which may further add converion/rounding errors.
Last Wiki Answer Submitted:  November 12, 2004  1:45 pm  by  Cballinger   0 pts.
All Answer Wiki Contributors:  Cballinger   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

1.75 divided by 1.5 giving 1 remainder .25 is correct because 1.5 + .25 = 1.75.

The remainder (.25) divided by 1.5 = .16 which is the fraction of 1.5 that you appear to want to evaluate.

Note that a remainder and a decimal fraction are not the same thing.

 0 pts.

 

I WANT TO FIND THE REMAINDER VALUE IN COBOL CALCULATION
PLEASE SUGGEST

 20 pts.

 

I WANT TO GET REMAINDER WHEN I CALCULATE 5 / 2
HOW I GET REMAINDER

AND

HOW I GET QUOTIENT

 20 pts.