Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Extracting Numeric Data from Alphanumeric Field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Extracting Numeric Data from Alphanumeric Field
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: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Thu Dec 09, 2010 1:32 am    Post subject:
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    Post subject:
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: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Thu Dec 09, 2010 2:15 am    Post subject:
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    Post subject:
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: 1754
Location: Bloomington, IL

PostPosted: Thu Dec 09, 2010 3:07 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
Reply with quote

Gud post.. Very useful for beginners
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Fri Dec 10, 2010 1:22 am    Post subject:
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:
http://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    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 Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us