IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

What is the correct value?


IBM Mainframe Forums -> HomeWorks & Requests
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jackzhang75

Active User


Joined: 09 Jun 2014
Posts: 124
Location: CT

PostPosted: Thu May 06, 2021 8:51 am
Reply with quote

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
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1188

PostPosted: Thu May 06, 2021 5:02 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2772
Location: NYC,USA

PostPosted: Thu May 06, 2021 5:48 pm
Reply with quote

Moved to Homework’s ..
Back to top
View user's profile Send private message
jackzhang75

Active User


Joined: 09 Jun 2014
Posts: 124
Location: CT

PostPosted: Thu May 06, 2021 6:32 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8584
Location: Dubuque, Iowa, USA

PostPosted: Thu May 06, 2021 7:12 pm
Reply with quote

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
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1188

PostPosted: Thu May 06, 2021 7:36 pm
Reply with quote

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
View user's profile Send private message
jackzhang75

Active User


Joined: 09 Jun 2014
Posts: 124
Location: CT

PostPosted: Fri May 07, 2021 2:06 am
Reply with quote

Thank you for all your answers. Really appreciated !
Back to top
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1188

PostPosted: Sat May 08, 2021 12:08 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> HomeWorks & Requests

 


Similar Topics
Topic Forum Replies
No new posts ADRDSSU BY(REFDT... not selecting cor... IBM Tools 3
No new posts Is the explanation correct? XRST,CHKP IMS DB/DC 1
This topic is locked: you cannot edit posts or make replies. Get correct date and time when curren... DB2 24
No new posts print out the correct info in LOOP? CLIST & REXX 7
No new posts Output file not getting populated in ... COBOL Programming 7
Search our Forums:

Back to Top