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

data validation from input file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 26, 2013 6:09 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 26, 2013 6:34 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 26, 2013 8:00 pm
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
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

Superior Member


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

PostPosted: Mon Apr 29, 2013 2:43 pm
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
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

Superior Member


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

PostPosted: Mon Apr 29, 2013 4:13 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 29, 2013 4:16 pm
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

Superior Member


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

PostPosted: Mon Apr 29, 2013 4:22 pm
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
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

Superior Member


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

PostPosted: Mon Apr 29, 2013 4:34 pm
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 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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Store the data for fixed length COBOL Programming 1
Search our Forums:

Back to Top