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

Error handling in COBOL for NUMVAL FUNCTION /STRING HANDLING


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

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Tue Oct 30, 2007 12:10 pm
Reply with quote

Please look at my query and guide me in this.

I have variable A of declaration A PIC X(12) and other variable B as

B PIC 9(9)v99.

I am receiving value in A from user using CICS screen which is alphanumeric and need to convert it into Numeric and stored into B.

For this I used NUMVAL function as COMPUTE B = FUNCTION NUMVAL (A).

Now, What’s the problem is , if user is going to enter some value in A without clearing the previous value of A on CICS screen then the value in A will be like this [....14....20] and if I perform NUMVAL function it ABENDS with ABEND code AB U4038, since NUMVAL function not accept it.

Now I have to handle this error, If this case occurs I have to make B = ZERO.

Will anybody please guide me how to handle this error, OR is there any other way so that I can Identify whether user is entered single value(cleared previous one and entering only numeric value).

Also I have to handle if User enters value like 12C, i.e. combination of numbers and Alphabets (ALPHANUMERIC).

Please help me in this scenario, if anybody wants some more clarification regarding my problem please let me know.

Thanks in advance,

Yogesh
Back to top
View user's profile Send private message
Help-Me-Out

New User


Joined: 09 Dec 2006
Posts: 56
Location: Pune

PostPosted: Tue Oct 30, 2007 12:43 pm
Reply with quote

y don't u clear the field as soon as you porcess the NUMVAL function. icon_question.gif
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Oct 30, 2007 2:28 pm
Reply with quote

Hi !

1.) What Help-Me-Out recommended
2.) Check that field by using INSPECT for blanks or whatever.
3.) Make it compatible by own code to the use of the numval-function.

Regards, UmeySan
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Oct 30, 2007 3:02 pm
Reply with quote

Usually at any reasonably established IT development site
there are general use subroutines/functions/call_them_anything_you_want

to carry on various data checking..
for numerics, for a date, pattern driven , application dependent, ...

check with application development support if there are such things available
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Wed Oct 31, 2007 7:27 pm
Reply with quote

Thanks all for your reply...

I got some solution for it. I used INSPECT,REFERENCE MODIFICATION and UNSTRING for this purpose.

The test program is shown Below , Please let me know whether this is correct way or not. Also if you have any other solution please post the same.

*************************************************************

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES. CLASS VALID-DATA '0' THRU '9'
' '
'.'.

**** I used this for checking whther ALphabets/Symbols are present in A.

INPUT-OUTPUT SECTION.
DATA DIVISION.

WORKING-STORAGE SECTION.

01 A PIC X(12).

01 B PIC 9(9)V99.

01 C PIC X(12).

01 D PIC X(12).
01 E PIC X(12).
01 F PIC ZZZZZZZZZ.99.

01 CHARCOUNT PIC 99 VALUE 00.

PROCEDURE DIVISION.

MOVE ' 3523A 18.9' TO A.

IF A IS VALID-DATA
***Checking for Alphabets/Symbols
NEXT SENTENCE
ELSE
DISPLAY 'NOT VALID DATA '
GO TO EXIT-PARA.


INSPECT A TALLYING CHARCOUNT FOR LEADING SPACES
MOVE A(CHARCOUNT + 1:12 - CHARCOUNT) TO C.

**** Removing Leading Spaces in A

DISPLAY 'ORIGINAL VALUE OF A -> ' A.
DISPLAY SPACES.

DISPLAY 'NO. OF LEADING SPACES PRESENT - > ' CHARCOUNT.
DISPLAY SPACES.

IF CHARCOUNT = 12
DISPLAY 'NOT VALID DATA '
GO TO EXIT-PARA
ELSE NEXT SENTENCE.

**** Checking if A is Blank


DISPLAY 'AFTER REMOVING LEADING SPACES OF A -> ' C.
DISPLAY SPACES.


MOVE 0 TO CHARCOUNT.


UNSTRING C DELIMITED BY SPACES INTO D COUNT IN CHARCOUNT
END-UNSTRING.

*** Seprating two values entered in A using UNSTRING and Reference *** Modification

DISPLAY 'COUNTER ' CHARCOUNT.
DISPLAY SPACES.

IF C NOT = D
MOVE C(CHARCOUNT + 1: ) TO E
DISPLAY 'ERROR -> USER ENTERED TWO VALUES '
DISPLAY SPACES
GO TO EXIT-PARA
ELSE
NEXT SENTENCE.

*** Checking whether User entered two values in A

MOVE D TO E.

DISPLAY 'SINGLE VALUE ENTERED '
DISPLAY SPACES

COMPUTE B = FUNCTION NUMVAL(D).

**** Alphanumeric to Numeric Conversion

DISPLAY 'CONVERTED INTO NUMERIC -> ' B.
DISPLAY SPACES.

COMPUTE F = 1.2 + B.

DISPLAY ' AFTER ADDITION OF 1.2 - >' F.


EXIT-PARA.
EXIT.

DISPLAY SPACES.
INSPECT D REPLACING ALL SPACES BY 'B'.
INSPECT E REPLACING ALL SPACES BY 'B'.
DISPLAY 'D ' D.
DISPLAY SPACES.
DISPLAY 'E ' E.

STOP RUN.

*************************************************************
o/p
***************************************************************** IF A IS ' 3523A 18.9'
*************************************************************
NOT VALID DATA

D ............

E ............

***************************************************************** IF A IS ' 23.45 18.9'
*************************************************************
ORIGINAL VALUE OF A -> 23.45 18.9

NO. OF LEADING SPACES PRESENT - > 01

AFTER REMOVING LEADING SPACES OF A -> 23.45 18.9

COUNTER 05

ERROR -> USER ENTERED TWO VALUES


D 23.45BBBBBBB

E BB18.9BBBBBB

***************************************************************** IF A IS ' 23 '
*************************************************************
ORIGINAL VALUE OF A -> 23

NO. OF LEADING SPACES PRESENT - > 01

AFTER REMOVING LEADING SPACES OF A -> 23

COUNTER 02

SINGLE VALUE ENTERED

CONVERTED INTO NUMERIC -> 00000002300

AFTER ADDITION OF 1.2 - > 24.20

D 23BBBBBBBBBB

E 23BBBBBBBBBB
*************************************************************

If you have any comments please let me know.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Error to read log with rexx CLIST & REXX 11
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Error when install DB2 DB2 2
Search our Forums:

Back to Top