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

How to extract numeric data from alpha-numeric field?


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

New User


Joined: 28 May 2007
Posts: 31
Location: Pune

PostPosted: Tue Feb 21, 2012 12:38 pm
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

Moderator Emeritus


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

PostPosted: Tue Feb 21, 2012 1:08 pm
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: 31
Location: Pune

PostPosted: Tue Feb 21, 2012 1:56 pm
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: 31
Location: Pune

PostPosted: Tue Feb 21, 2012 1:58 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 21, 2012 2:09 pm
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
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
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: 31
Location: Pune

PostPosted: Tue Feb 21, 2012 4:10 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Feb 21, 2012 5:19 pm
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: 2455
Location: Hampshire, UK

PostPosted: Wed Feb 22, 2012 2:06 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top