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
 

 

How to extract numeric data from alpha-numeric field?

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

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Tue Feb 21, 2012 12:38 pm    Post subject: How to extract numeric data from alpha-numeric field?
Reply with quote

I have to extract phone number from one field. This field contains Special Characters also. I need to extract only numbers also left aligned. Now I am using the below logic but this I hope will take more CPU time.
Code:
MOVE TEL-NO-01 TO WS-WORK-TELNO     
MOVE SPACES TO  TEL-NO-01           
MOVE ZERO                   TO WS-SUB           
MOVE 1                      TO TALLY             
PERFORM UNTIL TALLY > LENGTH OF WS-WORK-TELNO   
PERFORM UNTIL TALLY > LENGTH OF TEL-NO-01   
   IF  WS-WORK-DELANO (TALLY:1) IS NUMERIC       
       ADD  1              TO WS-SUB             
       MOVE WS-WORK-TELNO  (TALLY:1)             
            TO TEL-NO-01(WS-SUB:1) 
   END-IF                                       
 ADD 1 TO TALLY                                 
END-PERFORM               

Sample Values:
Code:
326-2835 - should be 3262835                       
(83)43-0460 should be 83430460


please help.. if I can use any functions.
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Tue Feb 21, 2012 1:08 pm    Post subject: Re: How to extract numeric data from alpha-numeric field?
Reply with quote

To preserve the spacing for your code, you should have used the Code tags.

You have not pasted from your mainframe screen, but re-typed. Now we don't know whether we are commenting on a problem, or on a typo.

You have shown no data definitions. I know why, because you have tried to do as little definition as possible, but since you are using the lengths of two fields it would be nice to see them.

You use TALLY and reference-modification. Find for a quick-and-dirty illustration of some concept, but obfuscating in actual code.

Also, read through what you have written, the words part, not the code part. Not quite sure when you say you "hope"?

What your code as presented is doing, is the whole operation, but "length" number of times. The two original fields should be the same length or the numeric shorter but at least as long as the maximum possible number. What is the maximum possible number? The length of the input field. Why, surely numbers can't really be that long? Yes, but if the input field on someone's screen was that long, it will have been filled with entirely numerics at some point.

Why would you think a function might improve performance? Less typing, less thinking for you, fewer tiresome data definitions, but always be sure if you feel that performance is an issue that what you are saying makes sense. You want performance, and then just hope there is some function as well. Wrong way round. If you have performance probllems, it is the simple bug.
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Tue Feb 21, 2012 1:56 pm    Post subject:
Reply with quote

Code:
01 TEL-NO-01                    PIC X(26)
           Value '(83)43-0460'.
01 WS-WORK-TELNO                PIC X(26). 
01 WS-SUB                       PIC  9(008)     BINARY.
-----------------------------------------------------------------
MOVE TEL-NO-01 TO WS-WORK-TELNO       
MOVE SPACES TO  TEL-NO-01             
MOVE ZERO                   TO WS-SUB               
MOVE 1                      TO TALLY               
PERFORM UNTIL TALLY > LENGTH OF TEL-NO-01       
   IF  WS-WORK-TELNO (TALLY:1) IS NUMERIC           
       ADD  1              TO WS-SUB               
       MOVE WS-WORK-TELNO  (TALLY:1)               
            TO TEL-NO-01(WS-SUB:1)     
   END-IF                                           
   ADD 1 TO TALLY                                     
END-PERFORM
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Tue Feb 21, 2012 1:58 pm    Post subject:
Reply with quote

PFA correct code. Can I use Inspect or Unstring function instead of Inline Perform?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Tue Feb 21, 2012 2:09 pm    Post subject: Reply to: How to extract numeric data from alpha-numeric fie
Reply with quote

You are in bad need for an ophthalmologist !

have You seen how Your initial post was edited to use the cod tags to provide for better readability

and how the same has been done for the last one too!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Feb 21, 2012 3:31 pm    Post subject:
Reply with quote

You with receive performance boost by using INDEXing
as apposed to reference modification.

you will also, by using the 88 level, insure that you are only moving 0 thru 9.

look at the compiled code, don't think you are going to beat this routine:

Code:

01 TEL-NO-01                    PIC X(26)
           Value '(83)43-0460'.
01 TEL-NO-WITH-IDX
   REDEFINES
   TEL-NO-01.
   05  TEL-NO-WITH-IDX-ELEMENT  OCCURS 26 TIMES
                                INDEXED BY PRIM-IDX
                                PIC X(01).
       
01 WS-WORK-TELNO                PIC X(26).
01 WS-WORK-TELNO-WITH-IDX
   REDEFINES
   WS-WORK-TELNO.
   05  WS-WORK-TELNO-WITH-IDX-ELEMENT
                                OCCURS 26 TIMES
                                INDEXED BY WORK-IDX
                                PIC X(01).
       88  WS-WORK-TELNO-0-TO-9 VALUES "0", "1",
                                "2", "3", "4", "5",
                                "6", "7", "8", "9".

-----------------------------------------------------------------
MOVE TEL-NO-01 TO WS-WORK-TELNO       
MOVE SPACES TO  TEL-NO-01             
SET PRIM-IDX                TO 1

PERFORM VARYING WORK-IDX
           FROM 1
             BY 1
          UNTIL WORK-IDX >26
   IF  WS-WORK-TELNO-0-TO-9 (WORK-IDX)
   THEN
       MOVE WS-WORK-TELNO-WITH-IDX-ELEMENT (WORK-IDX)
         TO TEL-NO-WITH-IDX-ELEMENT        (PRIM-IDX)
       SET PRIM-IDX UP BY 1
   END-IF                                           
END-PERFORM
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Feb 21, 2012 4:05 pm    Post subject:
Reply with quote

Actually, this is probably faster:
Code:

01 TEL-NO-01                    PIC X(26)
           Value '(83)43-0460'.
01 TEL-NO-WITH-IDX
   REDEFINES
   TEL-NO-01.
   05  TEL-NO-WITH-IDX-ELEMENT  OCCURS 26 TIMES
                                INDEXED BY PRIM-IDX
                                           WORK-IDX
                                PIC X(01).
       88  WS-WORK-TELNO-0-TO-9 VALUES "0", "1",
                                "2", "3", "4", "5",
                                "6", "7", "8", "9".

-----------------------------------------------------------------
SET PRIM-IDX                 TO 1

PERFORM VARYING WORK-IDX
           FROM 1
             BY 1
          UNTIL WORK-IDX > 26
   IF  WS-WORK-TELNO-0-TO-9 (WORK-IDX)
   THEN
       MOVE TEL-NO-WITH-IDX-ELEMENT        (WORK-IDX)
         TO TEL-NO-WITH-IDX-ELEMENT        (PRIM-IDX)
       SET PRIM-IDX UP BY 1
   END-IF                                           
END-PERFORM
PERFORM VARYING PRIM-IDX
           FROM PRIM-IDX
             BY 1
          UNTIL PRIM-IDX > 26
        MOVE SPACE TO TEL-NO-WITH-IDX-ELEMENT (PRIM-IDX)
END-PERFORM
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Tue Feb 21, 2012 4:10 pm    Post subject:
Reply with quote

Can I use UNSTRING or INSPECT function for better performance ?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Feb 21, 2012 5:15 pm    Post subject:
Reply with quote

sreejeshcs wrote:
Can I use UNSTRING or INSPECT function for better performance ?


no
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Tue Feb 21, 2012 5:19 pm    Post subject: Reply to: How to extract numeric data from alpha-numeric fie
Reply with quote

What is this whole performance thing? How have you got so many telephone numbers that it is crucial to perform at optimum? If you need optimum, consider assembler.

If you read what dbz has written, and consider what he says, you'll have one answer to your latest question. I agree. I think dbz's code will outperform some weirdness cobbled together with UNSTRING and INSPECT, which are not "functions", which you originally requested.

Get very, very, clear on what you want if you think you don't have it already. Else, take the code provided and apply it to yous. Rather than making dbz's code into a tacky copy of the rest of your program, "restyle" the rest of your program to match dbz's. Start to realise that programs which are easier to read, simpler, nice to look at and all those sorts of things, are easier to understand, maintain, reuse and, at the end of the day, write.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1717
Location: UK

PostPosted: Wed Feb 22, 2012 2:06 am    Post subject:
Reply with quote

Quote:
Start to realise that programs which are easier to read, simpler, nice to look at and all those sorts of things, are easier to understand, maintain, reuse and, at the end of the day, write.

and probably run faster.
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. Unwrap the data based on delimiter X'25' bhavana yalavarthi DFSORT/ICETOOL 30 Fri Dec 09, 2016 10:25 am
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts Is the 'prompt' data for the DSLIST p... Willy Jensen TSO/ISPF 2 Tue Dec 06, 2016 4:38 am
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 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


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