View previous topic :: View next topic
|
Author |
Message |
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
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 |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
PFA correct code. Can I use Inspect or Unstring function instead of Inline Perform? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
Can I use UNSTRING or INSPECT function for better performance ? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
sreejeshcs wrote: |
Can I use UNSTRING or INSPECT function for better performance ? |
no |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
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 |
|
|
|