In this section, we will explore several real-world examples of JCL (Job Control Language) to help you understand how JCL is used in practical scenarios. These examples will cover various common tasks that you might encounter in a mainframe environment.

Example 1: Copying a Data Set

Objective

Copy a data set from one location to another using the IEBGENER utility.

JCL Code

//COPYJOB  JOB (ACCT),'COPY DATASET',CLASS=A,MSGCLASS=A
//STEP1    EXEC PGM=IEBGENER
//SYSPRINT DD  SYSOUT=A
//SYSIN    DD  DUMMY
//SYSUT1   DD  DSN=SOURCE.DATASET,DISP=SHR
//SYSUT2   DD  DSN=TARGET.DATASET,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(TRK,(5,5),RLSE),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

Explanation

  • JOB Statement: Defines the job name (COPYJOB), accounting information, and job characteristics.
  • EXEC Statement: Specifies the program to execute (IEBGENER).
  • SYSPRINT DD Statement: Directs the output listing to the system output class A.
  • SYSIN DD Statement: Indicates no control statements are needed (DUMMY).
  • SYSUT1 DD Statement: Defines the input data set (SOURCE.DATASET).
  • SYSUT2 DD Statement: Defines the output data set (TARGET.DATASET) with new allocation parameters.

Exercise

Modify the above JCL to copy a data set named USER.INPUT.DATA to USER.OUTPUT.DATA with a block size of 3200.

Solution

//COPYJOB  JOB (ACCT),'COPY DATASET',CLASS=A,MSGCLASS=A
//STEP1    EXEC PGM=IEBGENER
//SYSPRINT DD  SYSOUT=A
//SYSIN    DD  DUMMY
//SYSUT1   DD  DSN=USER.INPUT.DATA,DISP=SHR
//SYSUT2   DD  DSN=USER.OUTPUT.DATA,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(TRK,(5,5),RLSE),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=3200)

Example 2: Sorting a Data Set

Objective

Sort a data set in ascending order using the DFSORT utility.

JCL Code

//SORTJOB  JOB (ACCT),'SORT DATASET',CLASS=A,MSGCLASS=A
//STEP1    EXEC PGM=SORT
//SYSOUT   DD  SYSOUT=A
//SORTIN   DD  DSN=INPUT.DATASET,DISP=SHR
//SORTOUT  DD  DSN=OUTPUT.DATASET,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(TRK,(5,5),RLSE),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSIN    DD  *
  SORT FIELDS=(1,10,CH,A)
/*

Explanation

  • JOB Statement: Defines the job name (SORTJOB), accounting information, and job characteristics.
  • EXEC Statement: Specifies the program to execute (SORT).
  • SYSOUT DD Statement: Directs the output listing to the system output class A.
  • SORTIN DD Statement: Defines the input data set (INPUT.DATASET).
  • SORTOUT DD Statement: Defines the output data set (OUTPUT.DATASET) with new allocation parameters.
  • SYSIN DD Statement: Contains the control statements for the sort operation. Here, it sorts the data set based on the first 10 characters in ascending order.

Exercise

Modify the above JCL to sort the data set USER.DATA.INPUT and output the sorted data to USER.DATA.SORTED, sorting by the first 15 characters in descending order.

Solution

//SORTJOB  JOB (ACCT),'SORT DATASET',CLASS=A,MSGCLASS=A
//STEP1    EXEC PGM=SORT
//SYSOUT   DD  SYSOUT=A
//SORTIN   DD  DSN=USER.DATA.INPUT,DISP=SHR
//SORTOUT  DD  DSN=USER.DATA.SORTED,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(TRK,(5,5),RLSE),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSIN    DD  *
  SORT FIELDS=(1,15,CH,D)
/*

Example 3: Merging Data Sets

Objective

Merge two data sets into a single data set using the DFSORT utility.

JCL Code

//MERGEJOB JOB (ACCT),'MERGE DATASETS',CLASS=A,MSGCLASS=A
//STEP1    EXEC PGM=SORT
//SYSOUT   DD  SYSOUT=A
//SORTIN01 DD  DSN=INPUT.DATASET1,DISP=SHR
//SORTIN02 DD  DSN=INPUT.DATASET2,DISP=SHR
//SORTOUT  DD  DSN=OUTPUT.DATASET,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(TRK,(5,5),RLSE),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSIN    DD  *
  MERGE FIELDS=(1,10,CH,A)
/*

Explanation

  • JOB Statement: Defines the job name (MERGEJOB), accounting information, and job characteristics.
  • EXEC Statement: Specifies the program to execute (SORT).
  • SYSOUT DD Statement: Directs the output listing to the system output class A.
  • SORTIN01 DD Statement: Defines the first input data set (INPUT.DATASET1).
  • SORTIN02 DD Statement: Defines the second input data set (INPUT.DATASET2).
  • SORTOUT DD Statement: Defines the output data set (OUTPUT.DATASET) with new allocation parameters.
  • SYSIN DD Statement: Contains the control statements for the merge operation. Here, it merges the data sets based on the first 10 characters in ascending order.

Exercise

Modify the above JCL to merge USER.DATA.INPUT1 and USER.DATA.INPUT2 into USER.DATA.MERGED, merging by the first 20 characters in ascending order.

Solution

//MERGEJOB JOB (ACCT),'MERGE DATASETS',CLASS=A,MSGCLASS=A
//STEP1    EXEC PGM=SORT
//SYSOUT   DD  SYSOUT=A
//SORTIN01 DD  DSN=USER.DATA.INPUT1,DISP=SHR
//SORTIN02 DD  DSN=USER.DATA.INPUT2,DISP=SHR
//SORTOUT  DD  DSN=USER.DATA.MERGED,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(TRK,(5,5),RLSE),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSIN    DD  *
  MERGE FIELDS=(1,20,CH,A)
/*

Conclusion

In this section, we have covered three practical examples of using JCL to perform common tasks such as copying, sorting, and merging data sets. These examples demonstrate the power and flexibility of JCL in managing data on mainframe systems. By practicing these examples and exercises, you will gain a deeper understanding of how to apply JCL in real-world scenarios.

© Copyright 2024. All rights reserved