JCL

SAVE discarded records using SORT

Record Selection for Output File can be done using STARTREC, ENDREC, INCLUDE/OMIT, SAVE Parameters. Use SAVE to include records for OUTFIL processing that have not been included in any other OUTFIL group. If SAVE is specified on more than one OUTFIL group, then each of these OUTFIL groups gets the records that were discarded from all other OUTFIL groups that do not have SAVE. The OUTFIL INCLUDE/OMIT parameter is mutually exclusive with the SAVE parameter. Only one of these parameters can be specified for an OUTFIL group.

Note: Note that if the SORTOUT data set has not been associated with any OUTFIL control statement but is present in the JCL, the SORTOUT data set will receive a copy of all records prior to OUTFIL processing. This does not affect the SAVE operation, since SAVE is only pertinent to other OUTFIL group specifications.

Syntax – SAVE

SORT FILEDS=(Starting position, length, data-format, A/D)
OUTFIL FNAMES=DD1, INCLUDE/OMIT COND=(….)
OUTFIL FNAMES=DD2, INCLUDE/OMIT COND=(….)
….......
OUTFIL FNAMES=DDn, SAVE

DDn - Actual DD Name present in JCL.
INCLUDE/OMIT - Specifies the INCLUDE/OMIT condition for specific OUTFIL.
SAVE - Specifies the records not selected for any OUTFIL will be saved to DDn.

Example with INCLUDE and SAVE

Scenario: Input contains the Employee Number, Name, Month & Subject. We want to write the records for the English, Physics & Business subjects to separate datasets then rest all discarded records to another dataset.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
1CHERYLJANUARYENGLISH
2NORMANMARCHBUSINESS
3LEONAIDDECEMBERCOMPUTER
4IANOCTOBERHISTORY
5LINDAFEBRURARYPHYSICS
6LITTLEAPRILENGLISH
7PIHUJANUARYHISTORY
8VIKASHOCTOBERBUSINESS
9SATVIJANUARYENGLISH
10LEEDECEMBERPHYSICS
SORT FIELDS=(1,45,CH,A)
  OUTFIL FNAMES=ENGLOUT,INCLUDE=(35,10,CH,EQ,C’ENGLISH   ')
  OUTFIL FNAMES=PHYSOUT,INCLUDE=(35,10,CH,EQ,C’PHYSICS   ')
  OUTFIL FNAMES=BUSIOUT,INCLUDE=(35,10,CH,EQ,C’BUSINESS  ')
  OUTFIL FNAMES=RESTOUT,
    INCLUDE=(35,10,CH,NE,C’ENGLISH   ',AND,
             35,10,CH,NE,C’PHYSICS   ',AND,
             35,10,CH,NE,C’BUSINESS  ')

The first OUTFIL statement writes the records for the English subject to the ENGLOUT data set.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
1CHERYLJANUARYENGLISH
6LITTLEAPRILENGLISH
9SATVIJANUARYENGLISH

The second OUTFIL statement writes the records for the Physics subject to the PHYSOUT data set.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
5LINDAFEBRURARYPHYSICS
10LEEDECEMBERPHYSICS

The second OUTFIL statement writes the records for the Business subject to the BUSIOUT data set.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
2NORMANMARCHBUSINESS
8VIKASHOCTOBERBUSINESS

The fourth OUTFIL statement writes the records not used for English, Physics or Business to the RESTOUT data set.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
3LEONAIDDECEMBERCOMPUTER
4IANOCTOBERHISTORY
7PIHUJANUARYHISTORY

But when there are more subjects the include statement for RESTOUT will be more complex. To avoid this SAVE parameter can be used.

  SORT FIELDS=(1,45,CH,A)
  OUTFIL FNAMES=ENGLOUT,INCLUDE=(35,10,CH,EQ,C’ENGLISH   ')
  OUTFIL FNAMES=PHYSOUT,INCLUDE=(35,10,CH,EQ,C’PHYSICS   ')
  OUTFIL FNAMES=BUSIOUT,INCLUDE=(35,10,CH,EQ,C’BUSINESS  ')
  OUTFIL FNAMES=RESTOUT,SAVE
  1. SORT FIELDS=(1,45,CH,A) – sort all outputs in ascending order based on the CH value from 1 to 45 positions.
  2. OUTFIL FNAMES=ENGLOUT,INCLUDE=(35,10,CH,EQ,C’ENGLISH   ‘)– All the records marching with “ENGLISH” from the 35th position of length 10 will be copied to ENGLOUT file.
  3. OUTFIL FNAMES=PHYSOUT,INCLUDE=(35,10,CH,EQ,C’PHYSICS  ‘)All the records marching with “PHYSICS” from the 35th position of length 10 will be copied to PHYSOUT file.
  4. OUTFIL FNAMES=BUSIOUT,INCLUDE=(35,10,CH,EQ,C’BUSINESS  ‘)– All the records marching with “BUSINESS” from the 35th position of length 10 will be copied to BUSIOUT file.
  5. OUTFIL FNAMES=RESTOUT,SAVEAll the records which are ignored from the above three filters will be copied to RESTOUT file. i.e. All COMPUTER, HISTORY records will be copied to RESTOUT file.

The output of this will be the same as above. RESTOUT dataset will contain the same information as in the previous result i.e. rows with the subject in Computer and History.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
3LEONAIDDECEMBERCOMPUTER
4IANOCTOBERHISTORY
7PIHUJANUARYHISTORY
  SORT FIELDS=(1,45,CH,A)
  OUTFIL FNAMES=ENGLOUT,INCLUDE=(35,10,CH,EQ,C’ENGLISH   ')
  OUTFIL FNAMES=PHYSOUT,INCLUDE=(35,10,CH,EQ,C’PHYSICS   ')
  OUTFIL FNAMES=BUSIOUT,OMIT=(35,10,CH,EQ,C’BUSINESS  ')
  OUTFIL FNAMES=RESTOUT,SAVE

Now with OMIT condition for the BUSIOUT file all the records which don’t have the subject as BUSINESS. So the RESTOUT fil will now contain only the records having the subject as BUSINESS.

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:10)
2NORMANMARCHBUSINESS
8VIKASHOCTOBERBUSINESS

JCL blogs – Click Here SYNCSORT Manual: Click Here

Admin

Share
Published by
Admin

Recent Posts

Optimize Outer Join Queries in the COBOL DB2 Program

Optimize Outer Join queries is a powerful tool for retrieving data from multiple tables. However,…

4 months ago

OUTER JOIN Queries: Common Errors and Resolutions

OUTER JOIN Queries are a valuable tool in SQL, allowing you to retrieve data from…

4 months ago

Impediments: Examples and Strategies for Scrum Masters

Mastering impediments is crucial to the Scrum Master's role in fostering a high-performing Scrum Team.…

4 months ago

Sprint Goal in Scrum with Examples

A Sprint Goal is a short, clear, and motivating target the Scrum Team aims to…

4 months ago

Context Switching – Measure and Avoid

Context switching refers to changing focus or shifting attention from one task or activity to…

5 months ago

Motivate People to Use Scrum – Strategies and Examples

Embracing change is never easy, especially when it involves a shift in work methodology. Motivate…

7 months ago