Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
Moving a COMP-3 Variable to a Numeric data-item

Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message

New User

Joined: 08 Apr 2015
Posts: 1
Location: Chennai

PostPosted: Thu Dec 14, 2017 5:46 pm    Post subject: Moving a COMP-3 Variable to a Numeric data-item
Reply with quote

I have a variable with the below declaration with data coming from a file
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)

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
MODEPREM1 :.0Ü0.0.0.

I opened the file in File-Aid to see how it is represented in HEX and it shows

(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
05 WS-AMOUNT-COMP3          PIC S9(7)V99 USAGE COMP-3.

A simple MOVE statement failed with S0C7

So I rather tried a compute and it failed as well with the same reason

I ran a condition to check if the field in question (MODEPREM1) was indeed numeric

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.

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: 8231
Location: Dubuque, Iowa, USA

PostPosted: Thu Dec 14, 2017 6:20 pm    Post subject:
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

Active User

Joined: 29 Apr 2008
Posts: 271
Location: Maryland

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

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

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.

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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1


Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Get the list of data sets on DASD and... rakaitn JCL & VSAM 3 Thu Mar 08, 2018 12:38 pm
No new posts Data security erase on RAID device steve-myers All Other Mainframe Topics 0 Sat Jan 13, 2018 6:41 am
No new posts Append the milliseconds to the data s... girishb2 DFSORT/ICETOOL 1 Thu Dec 21, 2017 9:07 pm
No new posts COMP Variables Mismatch gayu7 COBOL Programming 5 Wed Dec 20, 2017 5:06 pm
No new posts Extract record for change in combinat... Trinadh DFSORT/ICETOOL 6 Thu Nov 23, 2017 3:32 pm

Back to Top
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us