Reformatting Records Using OUTREC – Part 1

 

 

Though OUTREC is one of the most frequently used features of DFSORT,  many still find a SORT cards with OUTREC FIELDS=(21:106,4,35:1,75) confusing . We will try to explore the many uses of OUTREC in this article with some examples .

OUTREC gives you the flexibility to reformat your output file in multiple ways . Lets consider the below file as our input or SORTIN file where NAME is 5 bytes , DEPT is 2 bytes , SALARY takes 4 bytes and is a packed decimal filed and EMP_ID is 5 bytes .

Input file

1 . Selecting list of fields from your input file 

If you want to include only selected fields from your input file to be part of your output , you can do that by simply giving the starting position and length of the fields you would want to select in your OUTREC . If we want only the Name and Employee ID to be part of our output file just include the following

//SYSIN  DD  *

   SORT FIELDS=COPY

   OUTREC FIELDS=(1,5,16,6)  

   END

/*

1,5 denotes the starting position and length of NAME and 16,6 the position and length of Employee ID in your input file.

Output file created

Screen Shot 2015-04-05 at 1.00.33 AM

SORT will automatically calculate the length and block size of your output file based on the sort card if LRECL is not provided in your JCL, its best to just provide the DCB in your JCL and leave the LRECL part and let DFSORT calculate the appropriate record length based on your sort card.

2 . Reordering fields from your Input File 

To re arrange the fields from your input file just list the fields as per the order you wish them to appear in your output file in the SORT card , following the above example , if you wish to have an output file with the columns in the reverser order as the input file use the below sort card

//SYSIN  DD  *

   SORT FIELDS=COPY

   OUTREC FIELDS=(16,6,8,4,6,2,1,5)  

   END

/*

16,6 is the starting position and length for Employee ID , 8,4 for salary ( salary is 9(6)V9(2) COMP-3 fields and takes 4 bytes) , 6,2 for department and 1,5 for name .

Output file created

Screen Shot 2015-04-05 at 1.12.42 AM

3 . Controlling the position of fields in your output file

If you want your output file to contain only name and employee id as shown in the first example but you want name to start at the 20th position and employee id to start at the 30th position in your output file you can do so using OUTREC by mentioning the output file position followed by a colon (:) and then starting position and length of the required field in from your input file.

//SYSIN  DD  *

   SORT FIELDS=COPY

   OUTREC FIELDS=(10:1,5,30:16,6)  

   END

/*

10:1,5 means that bytes from 1 to 5 of your input file are placed at starting at position 10 in the output file and 20:16,6 places bytes starting from 16 to 21 of your input starting at position 30 in your output file.

The Column : clause, causes DFSORT to fill in blanks from the last field with data (or column 1) up to the column before Column : , so 10: puts blanks in columns 1-9 and 30: puts blanks in column 15-29.

Output file created

Screen Shot 2015-04-05 at 2.09.34 AM

 

More in part 2 …

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Mainframe Wiki © 2015 Frontier Theme