Stop copying the records from sort once i find a string



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Stop copying the records from sort once i find a string

Postby dam_chandu » Tue Sep 21, 2010 8:40 am

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..
dam_chandu
 
Posts: 6
Joined: Mon Sep 20, 2010 6:17 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Frank Yaeger » Wed Sep 22, 2010 1:11 am

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')           
/*
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times

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

Postby dam_chandu » Wed Sep 22, 2010 8:20 am

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.
dam_chandu
 
Posts: 6
Joined: Mon Sep 20, 2010 6:17 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby dick scherrer » Wed Sep 22, 2010 8:31 am

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".
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

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

Postby Frank Yaeger » Wed Sep 22, 2010 10:22 pm

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')                               
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times

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

Postby dam_chandu » Thu Sep 23, 2010 12:28 pm

Thanks Frank..

For detailed explanation of WHEN=GROUP.
dam_chandu
 
Posts: 6
Joined: Mon Sep 20, 2010 6:17 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post