MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Search and Replace
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Wed Feb 04, 2004 12:04 am    Post subject: Search and Replace Reply with quote

I have a alphanumeric field WS-ADD X(192). I need to search for the sub-string 'XXXXX-9999' in this WS-ADD where X given here should be a numeric digit.

Then i need to replace the 'XXXXX-9999' to 'XXXXX- ' (XXXXX- followed by Spaces).

Can someone Please help me out ?
_________________
Rasprasad S
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Feb 04, 2004 5:37 am    Post subject: Reply with quote

Rasprasad,

You need to provide details like the language you want this logic. Assuming it is cobol ,isn't this a simple solution using INSPECT with replacing? Even though I haven't tested it out , something like this should work.
Code:

WORKING-STORAGE SECTION.                                 
                                                         
01  WS-ADD               PIC X(192).                     
01  WS-STRING            PIC X(10).                     
01  WS-REPL              PIC X(10).                     
PROCEDURE DIVISION.                                     
                                                         
    MOVE ' RASPRASDS HAD TO REPL XXXXX-9999 12345-9999 '
            TO WS-ADD                                   
                                                         
    MOVE '12345-9999' TO WS-STRING                       
    MOVE '12345-    ' TO WS-REPL                         

    INSPECT WS-ADD REPLACING ALL WS-STRING BY WS-REPL   

    DISPLAY 'WS-ADD AFER REPLACE:' WS-ADD               
    GOBACK.                                             



In the above example I am replacing the 12345-9999 With '12345- ', but the other xxxxx-9999 remains as is.

Check this link for a detailed explanation of the INSPECT command with examples

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGYL1101/3.20?DT=19930312093006

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Wed Feb 04, 2004 5:57 am    Post subject: Reply with quote

Kolusu, Thanks for your (as always) quick answer.

I know about INSPECT. But the problem here is that the XXXXX i have mentioned (12345 in your example) will not be fixed. It can be any numeric item. '00000' TO '99999'.

Can you give a solution for this case ?

Thanks,
Prasad
_________________
Rasprasad S
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Feb 04, 2004 6:05 am    Post subject: Reply with quote

rasprasads,

can' you just search for '-9999' and replace it with spaces?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Wed Feb 04, 2004 6:12 am    Post subject: Reply with quote

How about

88 FIVE-DIGIT-NUMBER VALUE 00000 thru 99999.
88 HIPHEN-AND-NINES VALUE '-99999'.

...

If (FIVE-DIGIT-NUMBER AND HIPHEN-AND-NINES) ...
Back to top
View user's profile Send private message Send e-mail
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Wed Feb 04, 2004 7:23 am    Post subject: Reply with quote

Kolusu, I need to check if the format of 'XXXXX-9999' exists. So i can not go for just searching '-9999'. Can UNSTRING or any function can be used ?

Dibakar, I do not understand your solution. This 5 digits + '-' + '9999' can be anywhere in a string of length 192. How can i use your solution then ?

Thanks
_________________
Rasprasad S
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Feb 04, 2004 8:43 am    Post subject: Reply with quote

Rasprasad,

I still don't get the exact requirement. Are you saying that you have data like this?

Code:

 RASPRASDS HAD TO REPL XXXXX-9999 12345-9999 ABCDE-9999


XXXXX-9999 <==== Here XXXXX is alphabetic
12345-9999 <==== here 12345 is numeric
ABCDE-9999 <==== Here XXXXX is alphabetic

Now you want to just replace the 12345-9999 to '12345- ' ?? or do you want to replace all like this
Code:

XXXXX-9999  ====> 'XXXXX-    '
12345-9999  <==== '12345-    '
ABCDE-9999  <==== 'ABCDE-    '



The latter case of replacing All is just simple. you can do it with one inspect statement.
Code:

INSPECT WS-ADD REPLACING ALL '-9999' BY '-    '


Can you show us an example of your input and desired output?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Wed Feb 04, 2004 10:20 am    Post subject: Reply with quote

Here is the input :

"12345-9999 HAS been changed to 23456-9999 AND ABCDE-9999'

Output :

"12345- HAS been changed to 23456- AND ABCDE-9999'

Is it clear now Kolusu ?
_________________
Rasprasad S
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Feb 04, 2004 11:14 am    Post subject: Reply with quote

Rasprasad,

The following code will give you the desired results.

Code:

WORKING-STORAGE SECTION.                                     
                                                             
01  WS-ADD               PIC X(192) VALUE                     
   '12345-9999 HAS BEEN CHANGED TO 23456-9999 AND ABCDE-9999'.
01  WS-REPL-STRING       PIC X(192) VALUE SPACES.             
01  WS-POS1              PIC S9(04) COMP.                     
01  WS-POS2              PIC S9(04) COMP.                     
01  WS-NUM               PIC X(05).                           
01  WS-SUB               PIC S9(04) COMP.                     
                                                             
PROCEDURE DIVISION.                                           
                                                             
   PERFORM VARYING WS-SUB FROM 1 BY 1 UNTIL WS-SUB > 192     
       INITIALIZE WS-POS1 WS-POS2 WS-NUM
                     
       IF WS-ADD(WS-SUB : 1) = '-' AND WS-SUB > 5             
          COMPUTE WS-POS1 = WS-SUB - 5                       
          MOVE WS-ADD(WS-POS1 : 5) TO WS-NUM 
               
          IF WS-NUM IS NUMERIC                               
             COMPUTE WS-POS2 = WS-SUB + 1                     
             MOVE WS-ADD (WS-SUB : 1)                         
                         TO WS-REPL-STRING (WS-SUB  : 1)     
             MOVE SPACES TO WS-REPL-STRING (WS-POS2 : 4)     
             COMPUTE WS-SUB  = WS-SUB + 4                     
          ELSE                                               
             MOVE WS-ADD(WS-SUB  : 1)                         
                        TO WS-REPL-STRING(WS-SUB  : 1)       
          END-IF                                             
       ELSE                                                   
          MOVE WS-ADD(WS-SUB  : 1)                           
                        TO WS-REPL-STRING(WS-SUB  : 1)       
       END-IF                                                 

   END-PERFORM                                               
                                                             
   DISPLAY WS-REPL-STRING.



Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Thu Feb 05, 2004 2:03 am    Post subject: Reply with quote

Thanks Kolusu. I Changed the above logic to space out only '9999' from the last 4 digits and tested it. It works fine.

BTW Will there be any performace impact if the WS-ADD is of length say X(2000) (and this WS-ADD may be occcuring 20000 times in the input file) ?

Can we go for this solution in that case too ? What can be done in order to improve the performance ?
_________________
Rasprasad S
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Thu Feb 05, 2004 4:24 am    Post subject: Reply with quote

If you are wondering about performing the loop 20000 times then I guess there's no way out. You have a big record and your string can occur anywhere, so what else can be done. If you any tool or some function, it will also do the same thing.
Back to top
View user's profile Send private message Send e-mail
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Thu Feb 05, 2004 5:41 am    Post subject: Reply with quote

Yes Dibakar, i agree with you.

But my question for Kolusu is that if there is any way out to improve the performance since the PERFORM may be for 20000 times?
_________________
Rasprasad S
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Feb 05, 2004 6:40 am    Post subject: Reply with quote

Rasprasad,

The performance will take a slight hit when you are talking of scanning 2000 bytes for 20000 times. why don't you run a test and see if the run times are accetable. Just code this replace logic and run the program.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Thu Feb 05, 2004 6:52 am    Post subject: Reply with quote

Ok! Let me test this and soon update you on the slide in performance. Thanks anyway for giving a perfect solution !!!
_________________
Rasprasad S
Back to top
View user's profile Send private message
rasprasads
Beginner


Joined: 10 Dec 2002
Posts: 59
Topics: 20
Location: Chennai

PostPosted: Thu Feb 05, 2004 8:23 am    Post subject: Reply with quote

I tested with a little data and it works thru fine without any hitch in performance as well as functionality.

When i get a huge data i will check the perfomrance again and do a comparison to see how the code affects the performance.
_________________
Rasprasad S
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group