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
 

 

data validation from input file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
amarjit singh

New User


Joined: 08 Mar 2013
Posts: 30
Location: india

PostPosted: Fri Apr 26, 2013 5:30 pm    Post subject: data validation from input file
Reply with quote

hello,
my cobol program is getting data of X(02) from input file with leading spaces or trailing space.

example:
-----------
data can be ' 1' or '1 '.

as per the requirement, we need to convert into valid numric data (exm '01' ) for further proceesing.

my approach:
Code:
A  PIC XX
B  PIC X


Code:
IF A1:1) = ' '
   MOVE '0' TO A(1:1)
ELSE
IF A(2:1) = ' '
   MOVE A(1:1)    TO B
   MOVE '0'  TO    A(1:1)
   MOVE B   TO    A(2:1)
END IF.
 

Please suggest a better way, if the above is not appropiate.

thanks.

Code'd
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Fri Apr 26, 2013 6:09 pm    Post subject:
Reply with quote

Click on the IBM Manuals link at the top of this page, find the COBOL Language Reference manual, and read up on the FUNCTION NUMVAL in 7.1.32.
Back to top
View user's profile Send private message
amarjit singh

New User


Joined: 08 Mar 2013
Posts: 30
Location: india

PostPosted: Fri Apr 26, 2013 6:24 pm    Post subject:
Reply with quote

thanks Robert. its working fine for numeric data.
but i am getting error when i have space /any alphabet char in the input field.
any suggestion for that.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Fri Apr 26, 2013 6:34 pm    Post subject:
Reply with quote

I do not understand your post. NUMVAL explicitly handles leading or trailing spaces, so spaces should not cause you any problems. One way to handle non-numeric data would be to define a 2-byte variable C and use this code (where B is defined as PIC 9, not PIC X):
Code:
MOVE A TO C
INSPECT C
    REPLACING ALL SPACES BY ZEROES
IF  C NUMERIC
    COMPUTE B = FUNCTION NUMVAL (A)
ELSE
    <handle non-numeric A>
END-IF.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Fri Apr 26, 2013 8:00 pm    Post subject: Reply to: data validation from input file
Reply with quote

Code:
01  a-nice-name.
    05  ann-first-byte PIC X.
        88  ann-first-byte-is-space VALUE SPACE.
    05  ann-first-byte-num
         REDEFINES ann-first-byte PIC 9.
    05  ann-second-byte PIC X.
        88  ann-second-byte-is-space VALUE SPACE.
    05  ann-second-byte-num
         REDEFINES ann-second-byte PIC 9.
01  a-nice-name-num REDEFINES a-nice-name PIC 99.


Code:
MOVE input-data TO a-nice-name

EVALUATE TRUE
    WHEN a-nice-name NUMERIC
        PERFORM two-digit-number
    WHEN ( ann-first-byte-is-space
     AND ann-second-byte NUMERIC )
        PERFORM one-numeric-leading-space
    WHEN ( ann-second-byte-is-space
     AND ann-first-byte NUMERIC )
        PERFORM one-numeric-trailing-space
    WHEN OTHER
        PERFORM not-numeric-enough
END-EVALUATE


In PERFORMed paragraphs/SECTIONs, use the appropriate "-num" fields.
Back to top
View user's profile Send private message
amarjit singh

New User


Joined: 08 Mar 2013
Posts: 30
Location: india

PostPosted: Mon Apr 29, 2013 10:19 am    Post subject:
Reply with quote

hello Robert when i have spaces in input file NUMVAL is giving error AB U1097.
any way thank you Robert and Bill for the valuable time .. i use both the logic and its working fine for me.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Apr 29, 2013 2:43 pm    Post subject:
Reply with quote

What does "AB" mean in "AB U1097"? Did you mean "abend"? icon_neutral.gif

OTOH, the description of U1097 says:

Quote:
Message Format: IGZ097I THE CALLER WAS NOT A COBOL PROGRAM.

Description: A non-COBOL program attempted to call a VS COBOL II program without going through the appropriate interface and, as a result, VS COBOL II could not find a COBOL environment. The job step is cancelled.

User Action: See VS COBOL II APPLICATION PROGRAMMING GUIDE for an explanation of CALL statement rules and requirements.
That makes me curious.

It'd be nice if you can, please, share what finally worked for you.
Back to top
View user's profile Send private message
amarjit singh

New User


Joined: 08 Mar 2013
Posts: 30
Location: india

PostPosted: Mon Apr 29, 2013 3:29 pm    Post subject:
Reply with quote

Hi anuj,

below code works for me:

input file structure:
-----------------------
Code:
01  WS-IN-RECORD.
    05 WS1.
      10  WS1-FIRST-BYTE PIC X.
          88  WS1-FIRST-BYTE-IS-SPACE VALUE SPACE.
      10  WS1-FIRST-BYTE-NUM
          REDEFINES WS1-FIRST-BYTE PIC 9.
      10  WS1-SECOND-BYTE PIC X.
          88  WS1-SECOND-BYTE-IS-SPACE VALUE SPACE.
      10  WS1-SECOND-BYTE-NUM
          REDEFINES WS1-SECOND-BYTE PIC 9.
    05 FILLER                     PIC X(78) VALUE SPACES.

WS2         PIC99.

procedure division:
----------------------
Code:
IF WS1 IS NUMERIC THEN
   NEXT SENTENCE
ELSE
IF  ( WS1-FIRST-BYTE-IS-SPACE
    AND WS1-SECOND-BYTE IS NUMERIC ) THEN
       COMPUTE WS2 = FUNCTION NUMVAL(WS1)
       MOVE WS2 TO WS1
ELSE
IF  ( WS1-SECOND-BYTE-IS-SPACE
    AND WS1-FIRST-BYTE IS NUMERIC ) THEN
       COMPUTE WS2 = FUNCTION NUMVAL(WS1)
       MOVE WS2 TO WS1
ELSE
       PERFORM ERROR-DATA
END-IF.

I was getting abend initialy, when there was space in input WS1.
and in NUMVAL i was getting U1097.

thanks.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Apr 29, 2013 4:13 pm    Post subject:
Reply with quote

Amarjit - I've edited your code to add BBcode Tags, please learn to use them. "WS2 PIC99" was just lumping around with no 'label' attached to it, so I'm not sure if that's way you wanted it.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Apr 29, 2013 4:16 pm    Post subject: Reply to: data validation from input file
Reply with quote

Why, when you've identified one byte as being numeric and you have a field ready for it which is defined as PIC 9, do you use NUMVAL rather than a plain, simple, must less stressful to the CPU, MOVE?
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Apr 29, 2013 4:22 pm    Post subject:
Reply with quote

I don't understand this move:
Code:
MOVE WS2 TO WS1
- WS2 is of PIC 9(2) while WS1 is PIC X(80).

As Robert has also said - The NUMVAL function returns the numeric value represented by the alphanumeric character string or national character string specified as the argument. The function removes any leading or trailing spaces in the string to produce a numeric value. And 'space can be a string of one or more spaces.' So the mystry about U1097 still remains. I'll try to run some more tests to see if I can recreated this at my end.
Back to top
View user's profile Send private message
amarjit singh

New User


Joined: 08 Mar 2013
Posts: 30
Location: india

PostPosted: Mon Apr 29, 2013 4:30 pm    Post subject:
Reply with quote

HI,
WS1 is of pic X(02) followed by filler x(78).
WS2 is also independent variable.

thanks.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Apr 29, 2013 4:34 pm    Post subject:
Reply with quote

icon_redface.gif - I overlookd your Data-definition. That's where BBcode helps.
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 How to move a long alphanumeric data ... lind sh COBOL Programming 0 Mon Dec 05, 2016 7:51 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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