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 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: 8151
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: 8151
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: 1775
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 Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts JES2 job size field matching Windows ... SRICOBSAS All Other Mainframe Topics 4 Tue Sep 05, 2017 5:49 pm
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts Question related to Data dictionary f... rexx77 SYNCSORT 3 Thu Aug 31, 2017 7:23 am
No new posts Extract Data till prev hour balaji81_k DB2 16 Fri Aug 25, 2017 9:25 pm

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