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

Find a record in a file, then copy it plus the next set


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Melvyn Jacobs

New User


Joined: 05 Nov 2010
Posts: 7
Location: Australia

PostPosted: Mon Jan 25, 2016 11:43 am
Reply with quote

Hi

I'd like to search a file (will have lots of them) for a specified string, & if found then copy that record plus the next 6 to a different file.
I'm not sure if SORT can do that, any help is appreciated, thanks

MJ
Back to top
View user's profile Send private message
kranthikumarb

Active User


Joined: 02 Jan 2009
Posts: 115
Location: Hyderabad

PostPosted: Mon Jan 25, 2016 1:38 pm
Reply with quote

Here you go!

Code:

//STEP1 EXEC PGM=SORT                               
//SYSOUT DD SYSOUT=*                                 
//SORTIN DD *                                       
ABC111                                               
EDF21                                               
31                                                   
TEXT22                                               
32                                                   
42                                                   
52                                                   
13                                                   
23                                                   
33                                                   
/*                                                   
//OUT1    DD ...     
//SYSIN DD *                                         
 SORT FIELDS=COPY                                   
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,EQ,C'TEXT'),         
                      PUSH=(10:ID=5))                       
 OUTFIL FNAMES=OUT1,                                         
         BUILD=(1,80),INCLUDE=(10,5,CH,EQ,C'00001'),ACCEPT=6
/*                                                           


Just change the ID length based on your total number of records.
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: Mon Jan 25, 2016 2:16 pm
Reply with quote

It's not clear if the searched-for text can occur more than once in the data.

You don't need an ID (unless you need an ID, if they only want the first group, for instance), just PUSH a known non-blank one-byte field (like the first of the value which indicates the group) then OMIT= for blanks there.
Back to top
View user's profile Send private message
kranthikumarb

Active User


Joined: 02 Jan 2009
Posts: 115
Location: Hyderabad

PostPosted: Mon Jan 25, 2016 2:50 pm
Reply with quote

You are correct bill. Since I have no clue of how the input looks like; which position to take, I used ID. Also, I assumed that the text to be found will always be in a specific position.
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: Mon Jan 25, 2016 3:37 pm
Reply with quote

The GROUP is the important part, and what is missing is RECORDS=6. That will give you groups of six whether one or more key is present. SS as a field-type can find the key within a given range (start, length) on the record.

If there is no byte that can be guaranteed non-blank, can use an ID or SEQ of length one (since the value doesn't matter).
Back to top
View user's profile Send private message
Melvyn Jacobs

New User


Joined: 05 Nov 2010
Posts: 7
Location: Australia

PostPosted: Wed Jan 27, 2016 3:21 am
Reply with quote

sorry, to be clearer, the files being searched contain JCL, I'm only searching for 1 string (on an EXEC statement), and there may be multiple instances of that in any 1 file, not necessarily in the same position
Back to top
View user's profile Send private message
kranthikumarb

Active User


Joined: 02 Jan 2009
Posts: 115
Location: Hyderabad

PostPosted: Wed Jan 27, 2016 9:47 am
Reply with quote

As Bill suggested, you should've tried with SS.

Code:

//STEP1 EXEC PGM=SORT       
//SYSOUT DD SYSOUT=*       
//SORTIN DD *               
UNWANTED                   
UNWANTED                   
UNWANTED                   
UNWANTED                   
UNWANTED                   
123 345 TEXT 22             
WANTED                     
WANTED                     
WANTED                     
WANTED                     
WANTED                     
UNWANTED                     
UNWANTED                   
UNWANTED                   
213 3213 5654654TEXT 546456 565464                             
WANTED                                                         
WANTED                                                         
WANTED                                                         
WANTED                                                         
WANTED                                                         
UNWANTED                                                         
UNWANTED                                                       
UNWANTED                                                       
/*                                                             
//OUT1    DD SYSOUT=*                                           
//SYSIN DD *                                                   
 SORT FIELDS=COPY                                               
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,80,SS,EQ,C'TEXT'),RECORDS=6,
                       PUSH=(81:SEQ=5))                         
  OUTFIL FNAMES=OUT1,                                           
          BUILD=(1,80),INCLUDE=(10,5,CH,GE,C'00001')           
/*


This will work for multiple intances of text with in one dataset.
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: Wed Jan 27, 2016 12:47 pm
Reply with quote

Melvyn Jacobs,

It is really good to give all the information upfront.

kranthikumarb has now twice spent time on this for you, yet there is a better way.

Since to be a genuine EXEC in JCL it must be the second "word" on a line (after // or //text) then PARSE is a better way to do it.
Back to top
View user's profile Send private message
Melvyn Jacobs

New User


Joined: 05 Nov 2010
Posts: 7
Location: Australia

PostPosted: Thu Jan 28, 2016 3:09 am
Reply with quote

Hi Bill

Sorry about that, guess I was thinking in "general solution" terms when I asked - i.e. this time it's with JCL but next time it may not be . . .

Thanks to everyone who helped, all appreciated

cheers
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: Thu Jan 28, 2016 5:06 am
Reply with quote

There's some discussion and examples here that may be helpful.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top