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
 

 

Error handling in COBOL for NUMVAL FUNCTION /STRING HANDLING

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Error handling in COBOL for NUMVAL FUNCTION /STRING HANDLING
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    Post subject: Reply to: ERROR HANDLING in COBOL FOR NUMVAL FUNCTION /STRIN
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: 743
Location: Germany

PostPosted: Tue Oct 30, 2007 2:28 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Tue Oct 30, 2007 3:02 pm    Post subject: Reply to: Error handling in COBOL for NUMVAL FUNCTION /STRIN
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    Post subject: Reply to: Error handling in COBOL for NUMVAL FUNCTION /STRIN
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    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
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


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