View previous topic :: View next topic
|
Author |
Message |
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Hi All,
I am having a problem in extracting a numeric value from an alphanumeric variable.
The Alphanumeric Variable is PIC X(50) and has value line +00000000001.00
and I want to move this in S9(11)V9(2).So,I tried doing
Move ALphanumericVar(1:14) to NumericVar but it abended with S0C7.
Why this is incorrect? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
There is a link to manuals at the top of the page. Click on it, find the COBOL Language Reference manual, and read up on the FUNCTION NUMVAL. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Hi Robert,
I tried that as well but when I am using the variable for calculation it is not giving correct values.
I did NUMVAL for 2 variables and did a compute to save difference in WS-DIFF (PIC S9(11)V9(2)) and comapared with +100.It was not working. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
If it is not giving you correct values, either you're not using the function correctly or you're not telling us everything.
Code:
Code: |
77 WS-X1 PIC X(50)
VALUE '+00000000001.00'.
77 WS-X2 PIC X(50)
VALUE '+00000000201.00'.
77 WS-N1 PIC S9(11)V9(02).
77 WS-N2 PIC S9(11)V9(02).
77 WS-DIFF PIC S9(11)V9(02).
PROCEDURE DIVISION.
COMPUTE WS-N1 = FUNCTION NUMVAL (WS-X1) .
COMPUTE WS-N2 = FUNCTION NUMVAL (WS-X2) .
COMPUTE WS-DIFF = WS-N2 - WS-N1 .
DISPLAY 'WS-X1 = ' WS-X1.
DISPLAY 'WS-X2 = ' WS-X2.
DISPLAY 'WS-N1 = ' WS-N1.
DISPLAY 'WS-N2 = ' WS-N2.
DISPLAY 'WS-DIFF = ' WS-DIFF. |
produces results, exactly as expected, of:
Code: |
WS-X1 = +00000000001.00
WS-X2 = +00000000201.00
WS-N1 = 000000000010{
WS-N2 = 000000002010{
WS-DIFF = 000000002000{ |
Also, do not say something "is not working" -- this phrase is meaningless. What you say it, do you mean the compile of the code failed? The compile worked but there was an abend while running? If so, which abend? The compile worked but here was another error while running? The compile worked but the results produced were not what you expected? All of these can be construed as "did not work" but they are very different problems to solve. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
When I was comparing WS-DIFF with a number it was not working. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
rgupta71 wrote: |
When I was comparing WS-DIFF with a number it was not working. |
Paste the relevant section of code. Use the code tags to make it legible. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
The problem is
SYS1:000000116236{
SYS2:000000109107E
DIFF:000000007128E
SYS1:000000253495{
SYS2:000000241556A
DIFF:000000011938I
I think the value of Sys2 is coming incorrectly because of which wk-diff is being calculated incorrectly.I used the same function for SYS1 and SYS2. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Got it.Thank you all.I made a very silly mistake.Sorry |
|
Back to top |
|
|
rakeshnair1985
New User
Joined: 30 Nov 2010 Posts: 2 Location: Chennai
|
|
|
|
Gud post.. Very useful for beginners |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
Back to top |
|
|
|