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

Moving a COMP-3 Variable to a Numeric data-item


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ajayachander

New User


Joined: 08 Apr 2015
Posts: 1
Location: Chennai

PostPosted: Thu Dec 14, 2017 5:46 pm
Reply with quote

Requirement:
I have a variable with the below declaration with data coming from a file
Code:
05 MODEPREM1            PIC S9(7)V99 USAGE COMP-3.


This field needs to be moved to a report and displayed in readable numeric format (i.e. 1500.00)

Issue:
I have done a fair bit of reading, did try out a few ways but I have consistently managed to fail to accomplish what is required.
So here I am.

I understand that a S9(7)V99 COMP-3 is stored in 5 bytes = [(7+2) numeric + 1 sign(half byte)]/2
(Correct me if I got any of it wrong, I am here to learn!

I have tried displaying the data and it shows
Code:
MODEPREM1 :.0Ü0.0.0.


I opened the file in File-Aid to see how it is represented in HEX and it shows
Code:
MODEPREM1 5/PS   X'F0C0F0F0F0'

(I tried converting the HEX value to a numeric decimal through an online tool and it shows "1034029166832") - Is this the underlying data?
If Yes, then should it be 10340291668.32? It has a total of 13 numerical values, so I believe this won't be right. (If it indeed is right, how are 13 digits accommodated in 9(7)V99)
If NO, what is the underlying value?

When I try moving it to a Working storage variable declared with the same PIC clause in COMP-3 such as
Code:
05 WS-AMOUNT-COMP3          PIC S9(7)V99 USAGE COMP-3.


A simple MOVE statement failed with S0C7
Code:
MOVE MODEPREM1 TO WS-AMOUNT-COMP3


So I rather tried a compute and it failed as well with the same reason
Code:
COMPUTE WS-AMOUNT-COMP3 = MODEPREM1 * 1


I ran a condition to check if the field in question (MODEPREM1) was indeed numeric
Code:
IF MODEPREM1 IS NUMERIC
 DISPLAY "NUMERIC TRUE"
ELSE
 DISPLAY "NOT NUMERIC"
END-IF

and it failed. It went to the ELSE part of the loop to display "Not Numeric"
(I always had the understanding that a COMP-3 variable could only be Numeric, but then...)

And now I am stuck!
Can anybody throw a suggestion on where I have gone wrong.

icon_rolleyes.gif
Hope I have given enough information to make this post meaningful.
If not please let me know what else is required. And go easy, this is my first post.

Cobol Version:
PP 5655-S71 IBM Enterprise COBOL for z/OS 4.2.0
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Dec 14, 2017 6:20 pm
Reply with quote

Your first problem is that X'F0C0F0F0F0' is NOT a packed decimal value! This is a zoned decimal value with 4 zeroes in the first and third through fifth characters and a { in the second character.

You need to find out how the non-numeric data is getting into that variable -- table overflow is the most likely culprit but there are other possibilities.

If you have a valid numeric value in the packed decimal variable, File Aid will show something like X'123456789' (since the decimal point is implied and not actually part of the value); File Aid most likely would display 123456789 as the value if it is a proper packed decimal value.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Fri Dec 15, 2017 3:24 am
Reply with quote

Correct data for COBOL format PIC S9(7)V99 USAGE COMP-3 would be:
Code:

0.00             --> X'000000000C'
+1.00            --> X'000000100C'
+0.01            --> X'000000001C'
+1.11            --> X'000000111C'
+1000000.00      --> X'100000000C'
-1.00            --> X'000000100D'
-0.01            --> X'000000001D'
-1.11            --> X'000000111D'
-1000000.00      --> X'100000000D'

Everything else should cause ABEND S0C7, as expected.

No mystery arithmetic operation would help, when the original data is wrong.

In File-Aid, if PS-type field is displayed in HEX that means the decimal format is wrong. You can try to enter real decimal thru File-Aid Edit function, and then view it in hex mode to find out what is correct decimal format.

P.S.
File-Aid doesn't recognize the COBOL decimal point (assumed) position marked with 'V' in its PICTURE definition.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
Search our Forums:

Back to Top