View previous topic :: View next topic
|
Author |
Message |
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Hi Experts,
What is the value should i get for WS-C below? i was told that it should be +00022401 but i am not sure how to get this number? Is the WS-C should =
Code: |
288120.00/12.00= + 24010? |
sorry, i am not the Cobol programmer.
Code: |
COMPUTE WS-C = WS-A / WS-B.
WS-C is defined as S9(4) comp.
WS-A is defined as S9(11)V99 comp-3.
WS-B is defined as S9(9)V99 comp-3. |
The number for the A and B
Code: |
WS-A = +000000028812000
WS-B = +00000001200 |
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
Why not to try it in a test program to verify the result?
What prevents you from doing this?
P.S.
IMHO, if one cannot, or doesn’t want to run this simplest program on real computer, then it should not matter what may be its result... |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Moved to Homework’s .. |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Sorry i forgot to mention.. I did run the test but never got the expected results +22401. i got +4010 or if i made WS-A one less zero at the end to 2881200 then result is 2401 not 22401 so i want to check if i missed anything.. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
i was told that it should be +00022401 |
You need to go back to whoever told you this and get them to explain why they think this. 22401 times 12 is 268812, not 288120. COBOL numeric computations can be affected by the PICTURE clauses (intermediate results depend upon the number of digits for each variable both before and after the decimal point) but also by the compiler options being used (PIC S9(4) COMP will give different results depending upon the TRUNC compiler option, as just one example). Using the COBOL compiler to experiment with different combinations of PICTURE clauses and compiler options is the best way to figure out exactly what is happening in your case.
And the "correct value" will depend upon what you're looking for -- with TRUNC set to STD and PIC S9(4) COMP for WS-C, 4010 will be the "correct value". With TRUNC set to BIN and PIC S9(4) COMP for WS-C, 24010 will be the "correct value". |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
Some notes regarding TRUNC option in COBOL.
The problem is, the item declared in COBOL as
WS-C PIC S9(4) COMP
is in fact implemented by IBM compiler and mainframe hardware as “half-word binary” -
WSC DS H
TRUNC STD makes compiler to consider the maximum allowed value for this item as defined by COBOL, e.g. +9999.
TRUNC BIN makes compiler to consider the maximum allowed value for the same item as allowed by IBM hardware, e.g. +32767 (hex 7FFF in memory).
This may be the reason why the intermediate result of arithmetic operation is truncated differently (either to 4 digits, or sometimes to 5 digits). |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Thank you for all your answers. Really appreciated ! |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
jackzhang75 wrote: |
Thank you for all your answers. Really appreciated ! |
The good idea is, always to define ALL used items properly, depending on all their possible values.
The bad idea is, to rely on some specific hardware- or software- version related features or options. |
|
Back to top |
|
|
|