Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
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
 
What's the best way for convert char to numeric

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

New User


Joined: 03 Nov 2005
Posts: 46
Location: Shanghai, China

PostPosted: Sun Jul 23, 2006 3:57 pm    Post subject: What's the best way for convert char to numeric
Reply with quote

If BMS map has a field, length is 8.
We don't know what the user will input.
Then we get the variable of this field in CICS program.
for example: the variable we input is(b stand for blank, s stand for space): "b76bs85s", we want check if we can convert it to '7685'.
What's the best way to judge if it's a legal numeric and convert it to a numeric?
Great thanks!!!!!
Back to top
View user's profile Send private message

DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Jul 25, 2006 1:47 am    Post subject: Re: What's the best way for convert char to numeric
Reply with quote

You can try this code:

Code:

WORKING-STORAGE SECTION.                   
                                           
01  WS-INPUT            PIC X(8).         
01  WS-NBR              PIC 9(8).         
01  SUB1                PIC S9(5)  COMP-3.
01  SUB2                PIC S9(5)  COMP-3.
01  LEN2                PIC S9(5)  COMP-3.

PROCEDURE DIVISION.                               
                                                   
    MOVE LENGTH OF WS-NBR TO LEN2.                 
                                                   
    MOVE 0     TO WS-NBR.                         
    MOVE ' 76  85 '       TO WS-INPUT.             
    PERFORM P2000-CONVERT THRU P2000-EXIT.         
                                                   
    MOVE 0     TO WS-NBR.                         
    MOVE 'S76  85 '       TO WS-INPUT.             
    PERFORM P2000-CONVERT THRU P2000-EXIT.         
                                                   
    GOBACK.                                       

P2000-CONVERT.                                                 
                                                               
    DISPLAY 'WS-INPUT >' WS-INPUT '<'.                         
                                                               
    MOVE LEN2       TO SUB2.                                   
                                                               
    PERFORM                                                     
      VARYING SUB1 FROM LENGTH OF WS-INPUT BY -1               
      UNTIL SUB1 < 1                                           
        IF WS-INPUT(SUB1:1) NUMERIC                             
        THEN                                                   
            MOVE WS-INPUT(SUB1:1) TO WS-NBR(SUB2:1)             
            SUBTRACT 1 FROM SUB2                               
        ELSE                                                   
            IF WS-INPUT(SUB1:1) = ' '                           
            THEN                                               
                CONTINUE                                       
            ELSE                                               
                DISPLAY 'WS-INPUT >' WS-INPUT '< NON NUMERIC'   
            END-IF                                             
        END-IF                                                 
    END-PERFORM.                                               
                                                               
    DISPLAY 'WS-NBR >' WS-NBR '< FROM WS-INPUT >' WS-INPUT '<'.
    DISPLAY ' '.                                               
                                                               
P2000-EXIT.                                                     
    EXIT.                                                       


results of the execution of this program

Code:

                                                     
WS-INPUT > 76  85 <                                 
WS-NBR >00007685< FROM WS-INPUT > 76  85 <           
                                                     
WS-INPUT >S76  85 <                                 
WS-INPUT >S76  85 < NON NUMERIC                     
WS-NBR >00007685< FROM WS-INPUT >S76  85 <           
                                                     


Dave
Back to top
View user's profile Send private message
mainframemouli

New User


Joined: 01 Mar 2005
Posts: 52
Location: Mysore

PostPosted: Tue Jul 25, 2006 11:53 am    Post subject:
Reply with quote

david ,
your answer is specific to the example the author has given .
I think the author needs generalized solution.

All your cics programs should have the normalization step to handle this situation.

try checking out NUMVAL and NUMVAL-C functions of cobol...i am not sure.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Jul 25, 2006 5:04 pm    Post subject: Re: What's the best way for convert char to numeric
Reply with quote

NUMVAL and NUMVAL-C both abend if the input value is not numeric.

My intention was not to code sungang77's program for him. My assumption is that he's intelligent enough to use the code example as a base, though I?m not sure what input condition will not work.

Dave
Back to top
View user's profile Send private message
sungang77

New User


Joined: 03 Nov 2005
Posts: 46
Location: Shanghai, China

PostPosted: Fri Jul 28, 2006 9:08 pm    Post subject:
Reply with quote

Thanks, Dave, and others.
I am sorry I do not see your answer until today because I am busy these days.
I know what you mean. It must work.
I forgot to tell you about y assumption is user can input anything.
If there's none numeric(not include space) in user's input, the repeat part should break as soon as program detect it, how can we improve the code?
Another thing, can we delete the space before we perform the repeat part?

P.S: I haven't use 'inspect' in cobol before, can it used in such situation?
Back to top
View user's profile Send private message
vivek_mvs

New User


Joined: 25 Apr 2006
Posts: 2
Location: United States

PostPosted: Fri Jul 28, 2006 9:36 pm    Post subject: Re: What's the best way for convert char to numeric
Reply with quote

Hi,

I think you can try this is CICS

Code:
EXEC CICS BIF DEEDIT
     FIELD(CONTG)
     LENGTH(9)
END-EXEC

Results

CONTG before execution CONTG after execution
Original value Returned value
14-6704/B 00146704B
$25.68 000002568
It extracts all the numer values and put it back in the variable

This removes all characters other than digits from CONTG, a 9-byte field, and returns the edited result in that field to the application program.Note that a decimal point is an EBCDIC special character and as such is removed.

Thanks
Vivek
Back to top
View user's profile Send private message
sungang77

New User


Joined: 03 Nov 2005
Posts: 46
Location: Shanghai, China

PostPosted: Mon Jul 31, 2006 7:51 pm    Post subject:
Reply with quote

Thanks so much, Vivek.
I have a question. As you refered, "This removes all characters other than digits from CONTG", why in the first example, the character "B" is still in the returned value?
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 Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm
No new posts Can EDCICONV convert EBCDIC to ASCII... natt.sut IBM Tools 3 Fri Nov 17, 2017 8:46 pm
No new posts File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us