COBOL ‘Divide By Giving Remainder’ Code Not Working Correctly

0 pts.
Tags:
COBOL
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!!!
ASKED: November 12, 2004  1:25 PM
UPDATED: February 23, 2010  3:16 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • PscJohnD
    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 pointsBadges:
    report
  • REMAINDER
    I WANT TO FIND THE REMAINDER VALUE IN COBOL CALCULATION PLEASE SUGGEST
    20 pointsBadges:
    report
  • REMAINDER
    I WANT TO GET REMAINDER WHEN I CALCULATE 5 / 2 HOW I GET REMAINDER AND HOW I GET QUOTIENT
    20 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following