Page 1 of 1

How to select one group of records

PostPosted: Fri Jul 10, 2009 12:23 am
by Irene Ioujanina
Good afternoon, all. Good afternoon, Frank
Long time no see:) I hope you all are well.

May I please ask again.
I have a file with group of records, each group has a header and the trailer. I need to extract one group.
For instance:

001HEADER
111 DATA 1
222 DATA 2
Trailer
002HEADER
333 DATA 3
111 DATA 1
Trailer
005HEADER
555 DATA 5
Trailer

After I run the SORT -> I need to have the file with the followng data ( extract the group with the header value '002':
002HEADER
333 DATA 3
111 DATA 1
Trailer
( it means based on the header value '002' I extracted the header, all the item records in the same order and the trailer).

Thanking so much in advance,
Irene.

Re: How to select one group of records

PostPosted: Fri Jul 10, 2009 1:18 am
by Frank Yaeger
Irene,

You can use a DFSORT job like the following to do what you asked for. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
001HEADER
111 DATA 1
222 DATA 2
Trailer
002HEADER
333 DATA 3
111 DATA 1
Trailer
005HEADER
555 DATA 5
Trailer
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,EQ,C'002H'),
    END=(1,7,CH,EQ,C'Trailer'),PUSH=(81:ID=1))
  OUTFIL INCLUDE=(81,1,CH,NE,C' '),BUILD=(1,80)
/*

Re: How to select one group of records

PostPosted: Fri Jul 10, 2009 1:44 am
by Irene Ioujanina
Thank you so much :)