Page 1 of 2

how to copy header record during sorting.

PostPosted: Tue Aug 11, 2009 9:53 am
by helen2000
Hi All,

I have a trouble during sorting. I can sort all records except the header. because my header record didn't have
sort key. does anybody have good idea for that first copy the header record and then sorting the others records.
my sort production is Syncsort for Z/os.

thanks.

Re: how to copy header record during sorting.

PostPosted: Tue Aug 11, 2009 12:30 pm
by nayanpatra
STEP010: First break the file into two files using STOPAFT = 1 for the header and SKIPREC = 1 to capture the records without header. Remember to use SORT FIELDS = COPY.
STEP020: Now sort the second file containing only the records acc. to your requirements.
STEP030: Next combine the two files into a single file. For this you can use REPRO and give the two files as the SORTIN DD statement. In the control card use SORT FIELDS = COPY.

Re: how to copy header record during sorting.

PostPosted: Tue Aug 11, 2009 6:32 pm
by arcvns
Hello,

Here's a one-step SyncSort job which does exactly what you asked. This is just a sample, you can easily modify it as per your requirement.
Let me know if you come across any issues.
//STEP1  EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD *                                         
HEADER                                                   
KEY-A                                                   
KEY-C                                                   
KEY-D                                                   
KEY-B                                                   
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                         
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,C'1')),
        IFTHEN=(WHEN=(81,8,ZD,EQ,1),OVERLAY=(89:C'0'))   
  SORT FIELDS=(89,1,CH,A,1,5,CH,A)                       
  OUTFIL BUILD=(1,80)   
SORTOUT
HEADER
KEY-A
KEY-B
KEY-C
KEY-D

Re: how to copy header record during sorting.

PostPosted: Tue Aug 11, 2009 9:18 pm
by ranga_subham
Arun, what a cool trick this is....... :) Very nice.

Re: how to copy header record during sorting.

PostPosted: Tue Aug 11, 2009 11:49 pm
by helen2000
thanks all of you.
it works well right now. but there is
a little bit problem. my input record is VB. althougn I
got the output dataset. but the header record is
extended to 2004. Could you tell me how to keep the same
size as before sorting for the header record. thanks.
 026900 //SYSIN    DD  *                               
 026910   INREC IFTHEN=(WHEN=(6,5,ZD,EQ,12251),       
 026920                 OVERLAY=(249:C'0',2004:C'0')) 
 027000   SORT FIELDS=(40,10,CH,A,                     
 027100                11,8,CH,A,                     
 027200                249,2,BI,A)                     
 027210 //*            SKIPREC=1                       
 027300 /*           

Re: how to copy header record during sorting.

PostPosted: Wed Aug 12, 2009 12:30 am
by dick scherrer
Hello,

You might consider placing the seqnum at the beginning of the records instead of the end. . .

Re: how to copy header record during sorting.

PostPosted: Wed Aug 12, 2009 1:30 am
by helen2000
thanks, dick

maybe I didn't describe the problem clear. the input dataset have 3 sort key(offset is 40,11 and 249).
all input record have the 3 sort key except header(just 2 sort key, because header's size is 166).
when I run the JCL, got the error message:" control field exceed size". that's why I have to extend
the header record size before sorting.

Re: how to copy header record during sorting.

PostPosted: Wed Aug 12, 2009 1:32 am
by Alissa Margulies
Helen2000,

Do you want the header record to remain as the first record, or to be sorted along with all the data records?

Re: how to copy header record during sorting.

PostPosted: Wed Aug 12, 2009 10:05 am
by arcvns
helen2000,

A few more questions apart from what Alissa has asked.

Does "(6,5,ZD,EQ,12251)" identify your header record?
What is your input LRECL?

Re: how to copy header record during sorting.

PostPosted: Thu Aug 13, 2009 10:16 am
by nayanpatra
You could convert from variable format to fixed format.