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

Converting an edited picture clause value to signed numeric


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

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Wed Nov 07, 2007 3:06 am
Reply with quote

I have a field that is defined as

Code:
10 WS-A          PIC ZZ,ZZZ,ZZZ.99-


I want to extract the numerical value of this variable and put it in a field

Code:
10 WS-B          PIC S9(8)V99


Could you please tell me how i can move the numeric value of the edited picture clause value to this signed variable?
Thanks in advance
Anitha

P.S. I searched the forum for something similar but i could not find anything.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 07, 2007 3:30 am
Reply with quote

Hello,

How did the value get into ws-a? You might move the value to some other field (or even ws-b) at the same time it is moved to ws-a.

If the edited value comes from some input file, i've often set up a work field that has something like:
Code:
01  ws-wkfld.
    05 ws-dlrs  pic 9(8).
    05 filler   pic x.
    05 ws-cnts  pic 99.
I then redefine ws-a as a pic x(11) field and move the redefinition to the work field. In the work field, i eliminate the leading spaces then compute the value of ws-b. Keep in mind that you need to "scale" the dollars one way or another.

It is ugly, but has always worked icon_smile.gif
Back to top
View user's profile Send private message
skkp2006

New User


Joined: 14 Jul 2006
Posts: 93
Location: Chennai,India

PostPosted: Wed Nov 07, 2007 10:29 am
Reply with quote

Have u tried NUMVAL function. I am not sure whether it works or not. Give it a try.

http://publib.boulder.ibm.com/infocenter/pdthelp/v1r1/index.jsp?topic=/com.ibm.entcobol3.doc/tpstr19.htm
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Nov 07, 2007 9:01 pm
Reply with quote

Hi Anitha,

If you're using COBOLII (I think) or later, just move ws-a to ws-b.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 07, 2007 9:43 pm
Reply with quote

Hello,

Yup, just tried this with Enterprise COBOL and it works just fine.

Thanx, Jack icon_smile.gif

d
Back to top
View user's profile Send private message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Thu Nov 08, 2007 1:02 am
Reply with quote

Thanks Dick.
I did just what you said. I moved the variable into a gp variable to separate out the ',' and the '.'. Then used the parts of the dollar and cent amount to calculate the correct value. Based on the sign in the input, i multiplied the computed value by '-1' to generate a negative sign.

Thanks for your help.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Nov 08, 2007 2:23 am
Reply with quote

You're welcome icon_smile.gif

While i've used the method i posted for a long, long time (way before the "simple move" way was implemented), i really like the wha t Jack posted better.

I need to do some testing on what happens if the data is not numeric (due to some problem) and if a "not numeric" compare would catch all errors.

Good to hear your requirement has been met icon_cool.gif

d
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Nov 12, 2007 12:20 am
Reply with quote

Sorry Dick, you're wlecome. I just now saw your "Thanx". Another Sr. moment. I'm losing count. icon_smile.gif

BTW, your caution is well noted. I only use it when I'm sure the field was created by a COBOL pgm.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Nov 12, 2007 3:44 am
Reply with quote

Quote:
Another Sr. moment. I'm losing count
Yup, i resemble that icon_smile.gif

d
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 To search DB2 table based on Conditio... DB2 1
No new posts Convert HEX to Numeric DB2 3
No new posts Converting fixed length file to excel... IBM Tools 7
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Find a record count/numeric is multip... COBOL Programming 1
Search our Forums:

Back to Top