View previous topic :: View next topic
|
Author |
Message |
annujp
New User
Joined: 31 Aug 2005 Posts: 39 Location: St Paul,MN
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
skkp2006
New User
Joined: 14 Jul 2006 Posts: 93 Location: Chennai,India
|
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Anitha,
If you're using COBOLII (I think) or later, just move ws-a to ws-b. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Yup, just tried this with Enterprise COBOL and it works just fine.
Thanx, Jack
d |
|
Back to top |
|
|
annujp
New User
Joined: 31 Aug 2005 Posts: 39 Location: St Paul,MN
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
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
d |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Sorry Dick, you're wlecome. I just now saw your "Thanx". Another Sr. moment. I'm losing count.
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Quote: |
Another Sr. moment. I'm losing count |
Yup, i resemble that
d |
|
Back to top |
|
|
|