Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
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
ajayachander

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

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: 8355
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
sergeyken

Active User


Joined: 29 Apr 2008
Posts: 320
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:
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    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 Utility to list Data Set Information Auryn JCL & VSAM 3 Tue Jul 17, 2018 5:03 pm
No new posts Comparing Comp-3 fields with greater ... Prateeksichem1 DFSORT/ICETOOL 11 Fri Jul 13, 2018 8:45 am
No new posts Query for fetching matching data in t... Poha Eater DB2 10 Mon Jul 09, 2018 6:06 pm
No new posts How to delete large data. Mounika Nemani DB2 3 Wed Jun 13, 2018 1:58 pm
No new posts Ways to share data between Cobol and ... Benchwarmer Java & MQSeries 3 Thu May 10, 2018 9:16 pm

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