In SORT JCL, the STOPAFT SKIPREC are two conditions that control the processing of input records. You can use the STOPAFT SKIPREC options to reduce the number of records to be processed, which can reduce processor and data transfer time. STOPAFT and SKIPREC are optional parameters and can be used together or separately in a SORT JCL.
- The STOPAFT option allows you to specify the maximum number of records to be accepted for sorting or copying. For example, if you want to sort only the first 1000 records of a file, you can specify STOPAFT=1000 in your SORT JCL.
- The SKIPREC option allows you to skip records at the beginning of the input file and sort or copy only the remaining records. For example, if you want to sort a file but skip the first 10 records, you can specify SKIPREC=10 in your SORT JCL.
- The STOPAFT and SKIPREC conditions can be used with any SORT operation, including SORT, MERGE, and COPY.
- The values for STOPAFT and SKIPREC can be specified as a number or a symbol. Symbols are defined in the JCL using the symbolic parameter definition (SYMDEF) statement.
- If the input file has fewer records than the specified STOPAFT value, the SORT operation will stop after processing all the input records.
- If the input file has fewer records than the specified SKIPREC value, the SORT operation will start at the first input record.
- If both STOPAFT and SKIPREC are specified in the SORT JCL, the SKIPREC value is applied first, and then the STOPAFT value is applied.
- If neither STOPAFT nor SKIPREC is specified in the SORT JCL, the SORT operation will process all the input records.
Limitations
- SKIPREC can only be used to skip a fixed number of records at the beginning of the input file. It cannot be used to skip records based on some other criteria.
- STOPAFT can only be used to stop processing after a fixed number of records have been read. It cannot be used to stop processing based on some other criteria.
- SKIPREC and STOPAFT cannot be used together in the same SORT control statement. If you need to skip a certain number of records and then stop processing, you will need to use two separate SORT control statements.
- The SKIPREC parameter can only be used with fixed-length records. If you are working with variable-length records, you will need to use the IFTHEN statement to add a sequence number to each record and then use the STOPAFT parameter to stop processing after a certain number of records have been read.
- The STOPAFT parameter can cause unexpected results if the input file contains duplicate records. In this case, the SORT utility may stop processing before all of the duplicates have been read.
TOPAFT SKIPREC – STOP after ‘N’ number of records while SORTING (Using SYSIN orPARM)
If STOPAFT is specified as a PARM option and on the SORT control statement, the PARM specification takes precedence.
STOPAFT using SORT
//STEP001 EXEC PGM=SORT //$ORTPARM DD * STOPAFT=100 OR //STEP001 EXEC PGM=SORT,PARM='STOPAFT=N' OR //STEP001 EXEC PGM=SORT //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //REPORT1 DD SYSOUT=* //SORTIN DD DISP=SHR,DSN=XXXXXX.YYYYYY.INPFILE, //SORTOUT DD DSN=XXXXXX.YYYYYY.OUTFILE, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(30,10),RLSE), // UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS) //SORTWK01 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK02 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK03 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SYSIN DD * SORT FIELDS=COPY,STOPAFT=N /* //*
STOPAFT using ICETOOL
//STEP001 EXEC PGM=ICETOOL //TOOLMSG DD SYSOUT=* //DFSMSG DD SYSOUT=* //IN1 DD DSN=XXXXXX.YYYYY.INPUT,DISP=SHR //OUT1 DD DSN=XXXXXX.YYYYYY.OUTFILE, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(30,10),RLSE), // UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS) //TOOLIN DD * COPY FROM(IN1) TO(OUT1) USING(CTL1) /* //CTL1CNTL DD * OPTION STOPAFT=N /*
It’s also worth mentioning that if you’re using the SORT utility with the ICETOOL program, you can use the SELECT operator to achieve similar results to the STOPAFT and SKIPREC conditions. The SELECT operator allows you to specify a range of input records to process or exclude, which can be very helpful in situations where you need to perform complex data manipulations before sorting.
Here’s an example of using the SELECT operator with ICETOOL:
//SORTJOB JOB ... //TOOLSTEP EXEC PGM=ICETOOL //TOOLIN DD * SELECT FROM(IN) TO(OUT) SKIP(10) FIRST(1000) SORT FROM(IN) TO(TEMP) USING(CTL1) OUTFIL FNAMES=OUT,INCLUDE=(1,1,CH,EQ,C'1') /* //CTL1 DD * SORT FIELDS=COPY /*
In this example, the SELECT operator is used to skip the first 10 input records and process only the next 1000 records. The SORT operation is then performed on the selected input data using the CTL1 control statement. Finally, the output data is filtered to include only the records that meet a certain condition using the OUTFIL statement.
SKIP ‘N’ number of records while SORTING
//STEP001 EXEC PGM=SORT //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //REPORT1 DD SYSOUT=* //SORTIN DD DISP=SHR,DSN= XXXXXX.YYYYYY.INPFILE, //SORTOUT DD DSN= XXXXXX.YYYYYY.OUTFILE, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(30,10),RLSE), // UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS) //SORTWK01 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK02 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK03 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SYSIN DD * SORT FIELDS=COPY,SKIPREC=N /* //*
STOPAFT SKIPREC : SKIP ‘X’ and STOP after ‘Y’ number of records while SORTING
//STEP001 EXEC PGM=SORT //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //REPORT1 DD SYSOUT=* //SORTIN DD DISP=SHR,DSN= XXXXXX.YYYYYY.INPFILE, //SORTOUT DD DSN= XXXXXX.YYYYYY.OUTFILE, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(30,10),RLSE), // UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS) //SORTWK01 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK02 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK03 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SYSIN DD * SORT FIELDS=COPY,SKIPREC=X,STOPAFT=Y /* //*
Example: Sort the input file on the basis of the first 11 bytes then format the output file for the first 10000 records.
//SYSUDUMP DD SYSOUT=* //REPORT1 DD SYSOUT=* //SORTIN DD DISP=SHR,DSN= XXXXXX.YYYYYY.INPFILE, //SORTOUT DD DSN= XXXXXX.YYYYYY.OUTFILE, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(30,10),RLSE), // UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS) //SORTWK01 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK02 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SORTWK03 DD UNIT=DISK,SPACE=(CYL,(20,5),RLSE) //SYSIN DD * SORT FIELDS=(01,11,BI,A),SKIPREC=1,STOPAFT=10000 OUTREC FIELDS=(001:001,35, 036:036,05,PD,EDIT=(TTTTTTTTT), 045:041,02,PD,EDIT=(TTT), 048:043,05, 053:048,03,PD,EDIT=(TTTTT), 058:051,03,PD,EDIT=(TTTTT), 063:054,08,PD,EDIT=(TTTTTTTTTTTTTTT)) /* //*
SKIPREC and STOPAFT parameters can be used in conjunction with other parameters in the SORT control statement to create more complex sorting operations. For example, you might use the INCLUDE or OMIT parameters to filter out certain records before sorting or the SUM parameter to create summary information about the input data.
Here’s an example SORT control statement that uses the SKIPREC and SUM parameters to sort a file while skipping the first 10 records and creating a summary report:
SORT FIELDS=(1,10,CH,A) SKIPREC=10 SUM FIELDS=(11,4,ZD)
In this example, the SORT utility will sort the input file based on the first 10 characters of each record, while skipping the first 10 records. The SUM parameter will also be used to create a summary report based on the 4-byte numeric field starting at position 11 in each record.
SKIPREC and STOPAFT parameters can be used with both fixed-format and variable-length records. When working with variable-length records, you’ll need to specify the record length using the RECL parameter in the SORT control statement.
Here’s an example SORT control statement that sorts a variable-length input file while skipping the first 5 records and limiting the sorting to the first 1000 bytes of each record:
SORT FIELDS=(1,10,CH,A) SKIPREC=5 INREC IFTHEN=(WHEN=INIT,OVERLAY=(1001:SEQNUM,8,ZD)), IFTHEN=(WHEN=(1001,8,ZD,LE,1000),BUILD=(1,1000)) OUTREC BUILD=(1,1000) RECL=1000
In this example, the SORT utility will sort the input file based on the first 10 characters of each record, while skipping the first 5 records. The INREC statement is used to add a sequence number to each record and limit the sorting to the first 1000 bytes of each record. The OUTREC statement is used to remove the sequence number from the output records. The RECL parameter is set to 1000 to specify the maximum record length for variable-length records.
Summary
In summary, the STOPAFT and SKIPREC conditions are very useful in limiting the amount of data that needs to be sorted and can help reduce processing time and save on system resources. By using these conditions, you can process only the subset of data that is needed for a particular task, rather than sorting the entire input file.
If you need to perform more complex data manipulations before sorting, you may want to consider using the ICETOOL program with the SELECT operator or other operators that can help you achieve the desired results.
Furthermore, by using the SKIPREC and STOPAFT parameters in conjunction with other SORT control statement parameters, you can create complex sorting operations that meet your specific needs, whether you’re working with fixed-format or variable-length records.
Overall, understanding how to use the SKIPREC and STOPAFT parameters in the SORT utility is an important skill for anyone working with mainframe systems and can help you optimize your sorting operations and improve performance.