Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Find a record in a file, then copy it plus the next set
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: 114
Location: Hyderabad

PostPosted: Mon Jan 25, 2016 1:38 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon Jan 25, 2016 2:16 pm    Post subject: Reply to: Find a record in a file, then copy it plus the next set
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: 114
Location: Hyderabad

PostPosted: Mon Jan 25, 2016 2:50 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon Jan 25, 2016 3:37 pm    Post subject: Reply to: Find a record in a file, then copy it plus the next set
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    Post subject:
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: 114
Location: Hyderabad

PostPosted: Wed Jan 27, 2016 9:47 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jan 27, 2016 12:47 pm    Post subject: Reply to: Find a record in a file, then copy it plus the next set
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu Jan 28, 2016 5:06 am    Post subject: Reply to: Find a record in a file, then copy it plus the next set
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 1 Fri Dec 02, 2016 9:47 am
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us