Page 1 of 1

Stop copying the records from sort once i find a string

PostPosted: Tue Sep 21, 2010 8:40 am
by dam_chandu
Hi,

I have a requirement where i need to copy the records from input file onto the output file depending upon two strings..

Eg:

Sample Input file.

11111AAAA
22222BBBB
33333CCCC
44444DDDD
55555EEEE
66666FFFF
77777BBBB
88888FFFF

REQUIREMENT: Start copying the contents of the input file starting from the record which contains 'BBBB' at column 6 till it encounters 'FFFF'.

Sample output file

22222BBBB
33333CCCC
44444DDDD
55555EEEE

Points to note:

1) 'BBBB' is inclusive the record needs to be included in the input file, however the 'FFFF' has to be exclusive, it needs to be excluded from the output file.
2) Match should happen only once mean to say it should not consider the second set of conditions
77777BBBB
88888FFFF
3) Both input and output files are FB, PS, LRECL 80.

I need this requirement to be achieved using SORT. SKIP and STOPAFT works on the record count however my requirement is on the text string and i dont have a clue where these strings might be present in the input file at runtime.

Any help would be much appreciated.

Cheers..

Re: Stop copying the records from sort once i find a string

PostPosted: Wed Sep 22, 2010 1:11 am
by Frank Yaeger
You can use a DFSORT job like the following to do what you asked for:

//S1 EXEC PGM=SORT                                               
//SYSOUT DD SYSOUT=*                                             
//SORTIN DD *                                                   
11111AAAA                                                       
22222BBBB                                                       
33333CCCC                                                       
44444DDDD                                                       
55555EEEE                                                       
66666FFFF                                                       
77777BBBB                                                       
88888FFFF                                                       
//SORTOUT DD SYSOUT=*                                           
//SYSIN DD *                                                     
  OPTION COPY                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(6,4,CH,EQ,C'BBBB'),           
    END=(6,4,CH,EQ,C'FFFF'),PUSH=(81:ID=8))                     
  OUTFIL INCLUDE=(81,8,ZD,EQ,1,AND,6,4,CH,NE,C'FFFF')           
/*

Re: Stop copying the records from sort once i find a string

PostPosted: Wed Sep 22, 2010 8:20 am
by dam_chandu
Thanks a ton Frank..

Your solution is working as per my requirement. But have a small doubt, no where in the sort card there is any statement which says to consider first set of group which matches the condition, however it picked only the first set and skipped the second set which is present at the end.

How was this achieved?

If i need to consider the second set too / multiple similar group of records included in the input file (Which is not my requirement) what more do i need to add to the SORT Card.

Cheers,
Anand.

Re: Stop copying the records from sort once i find a string

PostPosted: Wed Sep 22, 2010 8:31 am
by dick scherrer
Hello,

no where in the sort card there is any statement which says to consider first set of group which matches the condition,
Yes, it is there.

INCLUDE=(81,8,ZD,EQ,1 indicates to include only the first "group".

Re: Stop copying the records from sort once i find a string

PostPosted: Wed Sep 22, 2010 10:22 pm
by Frank Yaeger
Anand,

PUSH=(81:ID=8) sets an id of 1 for the first group, an id of 2 for the second group, etc.

INCLUDE=(81,8,ZD,EQ,1,AND,6,4,CH,NE,C'FFFF') includes only the records from the first group (but not the FFFF record).

If you want ALL of the groups, you can use these DFSORT control statements:

   OPTION COPY
   INREC IFTHEN=(WHEN=GROUP,BEGIN=(6,4,CH,EQ,C'BBBB'),       
    END=(6,4,CH,EQ,C'FFFF'),PUSH=(81:ID=1))     
   OUTFIL OMIT=(81,1,CH,EQ,C' ',OR,6,4,CH,EQ,C'FFFF')           


If you want to include only the first and second groups, you can use these DFSORT control statements or an appropriate variation:

  OPTION COPY                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(6,4,CH,EQ,C'BBBB'),   
    END=(6,4,CH,EQ,C'FFFF'),PUSH=(81:ID=8))             
  OUTFIL INCLUDE=((81,8,ZD,EQ,1,OR,81,8,ZD,EQ,2),       
   AND,6,4,CH,NE,C'FFFF')                               

Re: Stop copying the records from sort once i find a string

PostPosted: Thu Sep 23, 2010 12:28 pm
by dam_chandu
Thanks Frank..

For detailed explanation of WHEN=GROUP.