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

Extracting Numeric Data from Alphanumeric Field


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

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Dec 09, 2010 1:27 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Dec 09, 2010 1:32 am
Reply with quote

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
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Dec 09, 2010 2:04 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Dec 09, 2010 2:15 am
Reply with quote

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
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Dec 09, 2010 2:58 am
Reply with quote

When I was comparing WS-DIFF with a number it was not working.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Dec 09, 2010 3:07 am
Reply with quote

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
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Dec 09, 2010 3:13 am
Reply with quote

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
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Dec 09, 2010 3:17 am
Reply with quote

Got it.Thank you all.I made a very silly mistake.Sorry
Back to top
View user's profile Send private message
rakeshnair1985

New User


Joined: 30 Nov 2010
Posts: 2
Location: Chennai

PostPosted: Thu Dec 09, 2010 12:09 pm
Reply with quote

Gud post.. Very useful for beginners
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: Fri Dec 10, 2010 1:22 am
Reply with quote

Hello,

Quote:
Very useful for beginners

Are you aware that we have a separate forum for stuents and freshers/beginners? Look here:
www.ibmmainframeforum.com/index.php
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 How to save SYSLOG as text data via P... All Other Mainframe Topics 4
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Store the data for fixed length COBOL Programming 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top