Tony,
I suggest you consult the HP COBOL II/XL Manual, specifically
the 'COMPUTE' statement documentation where the calculation of
intermediate results is discussed. The division is what is
messing you up.
To illustrate, I wrote a quick program and broke up the calcs and
used more digits to the right of the decimal.
RUN DAPCMP.PRN
Val-4: +00001.295382
Val-5: +00129.538
Val-6: +00129.54
End Run
Here are is the code:
01 WS-VAL-1 PIC S9(5)V9(6) VALUE 142.790.
01 WS-VAL-2 PIC S9(5)V9(6) VALUE 110.230.
01 WS-VAL-3 PIC S9(5)V9(6) VALUE 100.000.
01 WS-VAL-4 PIC S9(5)V9(6).
01 WS-VAL-5 PIC S9(5)V999.
01 WS-VAL-6 PIC S9(5)V99.
PAGE
PROCEDURE DIVISION.
MAIN-LOGIC SECTION.
ML-1.
COMPUTE WS-VAL-4 ROUNDED = (WS-VAL-1 / WS-VAL-2)
COMPUTE WS-VAL-5 ROUNDED = WS-VAL-4 * WS-VAL-3.
COMPUTE WS-VAL-6 ROUNDED = WS-VAL-5.
DISPLAY "Val-4: ", WS-VAL-4.
DISPLAY "Val-5: ", WS-VAL-5.
DISPLAY "Val-6: ", WS-VAL-6.
duane
> -----Original Message-----
> From: [log in to unmask]
> [mailto:[log in to unmask]] On Behalf Of Tony Girgenti
> Sent: Tuesday, October 14, 2008 1:50 PM
> To: HP3000 List
> Cc: Tony Girgenti
> Subject: Cobol: Puzzled by results of COBOL Compute with and
> w/o Rounded option
>
>
> Hello.
>
> Using HP3000, 928rx, MPEiX 6.0, HP COBOL II 78, Minisoft WS92
> emulation.
>
> If this is true:
>
> LINE-ITEM-UNIT-PRICE = 0 (PIC S9(5)v99 COMP.)
> LINE-ITEM-UNIT-COST = 0 (PIC S9(5)v999 COMP.)
> STOP-TARIFF-RATE (STOP-NO) = 142.79 (PIC S9(5)v99 COMP.)
> STOP-COST-RATE (STOP-NO) = 142.79 (PIC S9(5)v999 COMP.)
> ORDER-TOTAL-WEIGHT = 110.23 (PIC S9(5)v99 COMP.)
> OHP = 100.000(PIC S9(3)v999 COMP.)
>
> I don't understand why the LINE-ITEM-UNIT-PRICE and
> LINE-ITEM-UNIT-COST yields the following results for this
> COMPUTE statement using ROUNDED
>
> COMPUTE LINE-ITEM-UNIT-PRICE ROUNDED = STOP-TARIFF-RATE (STOP-
> NO) / ORDER-TOTAL-WEIGHT * OHP
> ON SIZE ERROR MOVE ZEROS TO LINE-ITEM-UNIT-PRICE.
>
> Results:
> LINE-ITEM-UNIT-PRICE = 129.50
>
> COMPUTE LINE-ITEM-UNIT-COST ROUNDED = STOP-COST-RATE
> (STOP-NO) / ORDER-TOTAL-WEIGHT * OHP ON SIZE ERROR MOVE ZEROS
> TO LINE-ITEM-UNIT-COST.
>
> Results:
> LINE-ITEM-UNIT-COST = 129.530
>
> Yet, if i take the ROUNDED option out of the compute, the results are:
> LINE-ITEM-UNIT-PRICE = 129.50
> LINE-ITEM-UNIT-COST = 129.500
>
> If i multiply this out on a calculator:
> 142.79 / 110.23 * 100.000 = 129.5382
>
> My puzzlement lies in the mystery of why a ROUNDED option
> causes less rounding than a COMPUTE without the ROUNDED option.
>
> I'm more concerned about finding out a way to get the answer of:
> LINE-ITEM-UNIT-PRICE = 129.54
> LINE-ITEM-UNIT-COST = 129.538
>
> I'm not so concerned about why it is happening as much as how
> to make it give the results I want.
>
> Any help would be gratefully appreciated.
>
> Thanks,
> Tony
>
> * To join/leave the list, search archives, change list settings, *
> * etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
>
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|