JCL to reverse the file records

JCL Trick to write the output file in reverse order of input using SORT. If the input file has some records in Random order ( not in sorted order) and if the out file needs to be written exactly in reverse order. This can be achieved by using the SORT Overlay along with OUTREC BUild. Below id the JOB to do that.


  • INREC OVERLAY statement adds a sequence in 40th position.
  • SORT FILEDS statement sorts the records in descending order based on the newly added sequence number.
  • OUTREC BUILD – As the sequence number is not required in output, this build statement copied the actual data till 35th position.

Input file has records as below and it has data till 35th position.

Output after Reversing the order

But how to reverse the records if there is no free space available in the input file or output file. In this case, SORT job requires a temporary data set to add the sequence number and sort then copying this temporary data set into the required output file.


Leave a Reply

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