Page 1 of 1

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

PostPosted: Fri Apr 25, 2014 11:16 am
by jiteshyadav
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?

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

PostPosted: Fri Apr 25, 2014 1:30 pm
by NicC
Read member line by line
Find sting
String found?
If 'yes' save line number end-if
read next line

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

PostPosted: Fri Apr 25, 2014 2:30 pm
by enrico-sorichetti
see here how to process a FIND line by line

http://ibmmainframes.com/about59997.html

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

PostPosted: Fri Apr 25, 2014 2:44 pm
by jiteshyadav
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?

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

PostPosted: Fri Apr 25, 2014 2:49 pm
by jiteshyadav
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

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

PostPosted: Fri Apr 25, 2014 3:49 pm
by NicC
With so much input data Rexx is possibly not the best option.

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

PostPosted: Fri Apr 25, 2014 6:54 pm
by Pedro
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?

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

PostPosted: Mon Apr 28, 2014 10:03 am
by jiteshyadav
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.

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

PostPosted: Mon Apr 28, 2014 6:49 pm
by Pedro
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.

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

PostPosted: Tue Apr 29, 2014 10:12 am
by jiteshyadav
Thanks Pedro.
I used SRCHFOR and it's doing wonders. :-)