Extract line & line no while finding String in PDS members.



IBM's Command List programming language & Restructured Extended Executor

Extract line & line no while finding String in PDS members.

Postby jiteshyadav » Fri Apr 25, 2014 11:16 am

Hi,

I was trying to find a string in the members of a PDS and did that using below:
REXX:
PUSH INP                                                 
MAC = FINDMAC                                             
ADDRESS ISPEXEC "VIEW DATASET('"FILE_NAME"') MACRO("MAC")"
IF RC = 0 THEN                                           
DO                                                       
   PULL FINDS                                             
   FINDCNT.STRC = FINDS                                   
END                                                       

MACRO:
ADDRESS ISREDIT         
"MACRO"                 
"RES"                   
PULL INP               
STR = "'"||STRIP(INP)"'"
ISREDIT FIND STR ALL   
"(FINDS) = FIND_COUNTS"
PUSH FINDS             
"ISREDIT END"           

Occurrence count is coming fine.
Now my requirement is to get the line number where string is found and the line itself i.e. the report displaying the line number and full line text where the string is found.
Any suggestions how to extract these details?
jiteshyadav
 
Posts: 22
Joined: Tue Apr 15, 2014 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract line & line no while finding String in PDS members.

 

Re: Extract line & line no while finding String in PDS membe

Postby NicC » Fri Apr 25, 2014 1:30 pm

Read member line by line
Find sting
String found?
If 'yes' save line number end-if
read next line
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2702
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Extract line & line no while finding String in PDS membe

Postby enrico-sorichetti » Fri Apr 25, 2014 2:30 pm

see here how to process a FIND line by line

http://ibmmainframes.com/about59997.html
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2648
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 132 times

Re: Extract line & line no while finding String in PDS membe

Postby jiteshyadav » Fri Apr 25, 2014 2:44 pm

Hi NicC,

Thanks for your reply.

The thing is I am trying to find out anti-patterns in COBOL programs. Since a COBOL program may be of thousands of lines (for e.g. 20000) and there can be 'n' no of anti-patterns (for e.g. 50) in another file which I need to find in that COBOL program, dealing with 20000 * 50 = 1000000 lines of code in a single go might cause buffer to go out of space.
Which is why I am taking 50 lines from the COBOL code, concatenating those 50 lines of code in single string and then use POS to find the string.
In this case 50 * 50 = 2500 is rather acceptable I guess.
Also this allow me to find the strings which are split in 2 lines as well (since lines are concatenated) for e.g.
MOVE +100
      TO SQLCODE


I have already achieved above written.
Please let me know if this makes sense or it seems flawed?

And because of the above approach I used an edit macro to use "F ALL" to find total no of occurrences. I am looking for a way to find the line no and line in edit macro itself, if possible.

Any suggestions?
jiteshyadav
 
Posts: 22
Joined: Tue Apr 15, 2014 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract line & line no while finding String in PDS membe

Postby jiteshyadav » Fri Apr 25, 2014 2:49 pm

Hi Enrico,
enrico-sorichetti wrote:see here how to process a FIND line by line

http://ibmmainframes.com/about59997.html

Line by line seems fine.
Any views on the approach that I have shared above?

Thanks
jiteshyadav
 
Posts: 22
Joined: Tue Apr 15, 2014 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract line & line no while finding String in PDS membe

Postby NicC » Fri Apr 25, 2014 3:49 pm

With so much input data Rexx is possibly not the best option.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2702
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Extract line & line no while finding String in PDS membe

Postby Pedro » Fri Apr 25, 2014 6:54 pm

get the line number where string is found and the line itself i.e. the report displaying the line number and full line text where the string is found.

It sounds like you are trying to recreate the output of the SRCHFOR utility. Why not just call the utility instead of re-writing it yourself?
Pedro Vera
User avatar
Pedro
 
Posts: 571
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 40 times

Re: Extract line & line no while finding String in PDS membe

Postby jiteshyadav » Mon Apr 28, 2014 10:03 am

Hi Pedro,

Thanks for your reply.
I know SRCHFOR is one option. But the requirement of "displaying the line number and full line text where the string is found" is added later on. I had achieved finding the string using the edit macro above.
So I was looking for some way, if any, to do that thru edit macro only. Otherwise I will opt for SRCHFOR.
Thanks.
jiteshyadav
 
Posts: 22
Joined: Tue Apr 15, 2014 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract line & line no while finding String in PDS membe

Postby Pedro » Mon Apr 28, 2014 6:49 pm

I know SRCHFOR is one option.

Given the new requirements, it is the best option. Sometimes you need to abandon your early work when you get new requirements. I think this is one of those times.
Pedro Vera
User avatar
Pedro
 
Posts: 571
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 40 times

Re: Extract line & line no while finding String in PDS membe

Postby jiteshyadav » Tue Apr 29, 2014 10:12 am

Thanks Pedro.
I used SRCHFOR and it's doing wonders. :-)
jiteshyadav
 
Posts: 22
Joined: Tue Apr 15, 2014 3:36 pm
Has thanked: 0 time
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post