GDG in JCL

GDG in JCL

GDG in JCL is an important concept. We will show you enough examples to master GDG in Mainframe.

– GDG Stands for ‘Generation data group‘.
– It contains group of similar data sets which are related to each other in chronological order.

Syntax/Format OF GDG:

ABC.PQR.XYZ.GnnnnVmm
– G – Stands for Generation number – Value range 0000 – 9999
– V – Stands for Version number – Value range 00 – 99

Here, the GDG base is – ABC.PRQ.XYZ

Example

MATEKS.TEST.GDG.G0001V00
MATEKS.TEST.GDG.G0002V00
MATEKS.TEST.GDG.G0003V00

Output

In this example, the GDG base is MATEKS.TEST.GDG and it has 3 generations which is G0001, G0002 and G0003

Why do we need to use a GDG?

If we use GDG, it will take care of the following things –

  • We do not need to create a new JCL or change the name of the JCL  every time in a weekly run or daily run or monthly run or yearly run of a JCL.
  • You can set the limit of the related files(generations)
  • We can easily keep track of all generation of data sets
  • We can delete or uncatalog the older generation
  • Any particular generation can be referred easily.

How to create a GDG

STEP1: Create a GDG base (using IDCAMS utility – Access method service utility)

STEP2:  Using IEFBR14 utility, we will create the new generations. You can also use another utility called Fileaid if your site supports this.

List of PARAMETERS used to create GDG:

NAME – Name of the GDG Base

LIMIT – To limit the maximum number of generations

EMPTY/NOEMPTY

  •  NOEMPTY – Uncatalog only the oldest generation in GDG when the limit is reached
  •  EMPTY – Uncatalog all the generations when a limit is reached.

SCRATCH/NOSCRATCH

  • SCRATCH -Physically delete the dataset(generation) which is uncataloged
  • NOSCRATCH – Don’t Physically delete the dataset(generation) which is uncataloged

Rules for using GDGs in JCL

  • Mention the generation number which you want to access in JCL by coding dataset followed by the bracket.
  • You must code the DSN and UNIT parameters for all new generations.
  • Keep the same name for all datasets within a GDG.
  • Generation number will be assigned by the OS when it is created.
    – The syntax is as follows – GaaaaVnn
     Where  G- generation
     Aaaa – absolute sequence number
      V – Version
      Nn – version number
  • Generation(0) refers the current generation.
  • Generation(-1) refers to the generation which is just before the current generation
  • Generation(+1) refers to the generation which is just after the current generation

How to see and read the properties of a GDG?

If you want to see the properties  of a GDG, then you can follow any one of these steps

  • In the ISPF command line, you can issue a command ‘TSO LISTC ENT(‘GDG-BASE-NAME’) ALL
  • Use LISTCAT ENTRY ‘GDG-NAME’ ALL in the IDCAMS utility of the JCL.
  • Use a utility called Fileaid if your site supports Fileaid.

JCL to create a new Generation of a GDG

//CRTGENER JOB (345),’TRAINOOL’,CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//************************************************************
//* TO CREATE A NEW GENERATION OF A GDG
//************************************************************
//STEP10 EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSDUMP DD SYSOUT=*
//DD1 DD DSN=MATEKS.SALES.WEEK(+1),
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(1,1),RLSE),
// UNIT=SYSDA,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//*
//***************************************************

Output

LIMT(4)   – Maximum number of generations = 4
NOEMPTY – Don’t uncatalog all generations once the limit is reached, only uncatalog oldest generation.
SCRATCH – Delete the dataset physically which was uncataloged.

Difference between EMPTY and NOEMPTY

Some of you might be confused between EMPTY and NOEMPTY.

Let us take an example –

Suppose, you have a GDG Base, MATEKS.SALES.WEEK and you have created 3 generations like – MATEKS.SALES.WEEK.G0001V00, MATEKS.SALES.WEEK.G0002V00 , and                            MATEKS.SALES.WEEK.G0003V00.

Now, when you try to create another generation and  if you have coded ‘NOEMPTY‘ – It means that it will remove the the oldest generation from the catalog when the limit is reached which means that only MATEKS.SALES.WEEK.G0001V00 will be uncataloged. So, now the 3 generations which are present are -MATEKS.SALES.WEEK.G0002V00, MATEKS.SALES.WEEK.G0003V00, and MATEKS.SALES.WEEK.G0004V00.

When NOEMPTY is coded

DEFINE GDG ( NAME(MATEKS.SALES.WEEK) –
LIMIT(3) –
NOEMPTY –
SCRATCH )

JCL - 3 generations of GDG base with NOEMPTY coded

When the limit is reached

If you try to create the 4th generation, then

G0004V00 is created and G0001V00 is uncataloged as shown above

Now, Suppose, you have a GDG Base, MATEKS.SALES.WEEK1 and you have created 3 generations like MATEKS.SALES.WEEK1.G0001V00, MATEKS.SALES.WEEK1.G0002V00, and MATEKS.SALES.WEEK1.G0003V00.

Now, what happens when you try to create another generation and  If you have coded ‘EMPTY‘ – It means that it will remove all the older generations from the catalog which means that MATEKS.SALES.WEEK.G0001V00, MATEKS.SALES.WEEK.G0002V00, and MATEKS.SALES.WEEK.G0003V00 will be uncataloged and MATEKS.SALES.WEEK.G00004V00 will be created.

When EMPTY is coded

DEFINE GDG ( NAME(MATEKS.SALES.WEEK1) –
LIMIT(3) –
EMPTY –
SCRATCH )

JCL - 3 generations of GDG base with EMPTY coded

When the limit is reached

After the limit is reached and when you try to create the 4th generation, then 

JCL - All generations are uncataloged when EMPTY is coded once the limit is reached

G0004V00 is created and all the older generations are uncataloged as shown above

Various Generations of a GDG

  1. To create a next generation, code +1 inside the bracket. We should code the other keyword parameter in a similar way, how we code for PS or PDS files.
  2. Example- DSNAME, UNIT or VOLUME related parameters etc should be coded in the same way as if we code for a PS or PDS file.

  3. To refer to a particular generation, code the generation number inside the bracket.
    – Generation(0) means current generation.
    – Generation(-1) means previous generation.
    – Generation(+1) means the next generation one level after the current generation.

Example to refer the current Generation and previous Generation in JCL

Suppose, we have 3 Generations of a GDG

Listing of GDG base in JCL

Let us see the contents of the current Generation and (-1) Generation

Content of 0th Generation and -1 Generation of GDG in JCL

JCL to copy the current Generation

Copy current Generation to a file in GDG

Output

Output file created from the current GDG Generation in JCL

You can see the content of the current Generation of the file i.e. MATEKS.SALES.WEEK.G0008V00 is copied to the output file

Similarly, the step to copy the (-1) Generation

Output

content of -1 Generation of GDG copied to a file in JCL

You can see the content of (-1) Generation of the file i.e. MATEKS.SALES.WEEK.G0007V00 is copied to the output file

JCL to change the properties of a GDG - Alter GDG Base

In this Example, we are trying to alter the properties of a GDG Base. You can alter GDG limit, Alter NOEMPTY to EMPTY or you can even set SCRATCH in place of NOSCRATCH.

You should avoid altering GDG Name.

//ALTERGDG JOB (345),’TRAINOOL’,CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//************************************************************
//* ALTER GDG BASE
//************************************************************
//STEP10 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
ALTER MATEKS.SALES.WEEK) –
LIMIT(2) –
NOEMPTY –
SCRATCH )
/*

Explanation

In this Example, we are trying to alter the properties of a GDG Base. You can alter GDG limit, Alter NOEMPTY to EMPTY or you can even set SCRATCH in place of NOSCRATCH.

You should avoid altering GDG Name.

Delete GDG Base

If you want to DELETE base, then you can use either DELETE GDG FORCE or  DELETE GDG PURGE. You can give any one of these options in IDCAMS utility –

  1. DELETE PURGE – If you want to delete GDG Base or Index even if retention period(RETP) or expiry date is over, then you can use this option.
  2. DELETE FORCE – To delete the GDG index and all the generations forcefully, you can use this option.

Delete GDG using IDCAMS utility

Suppose, we have 3 GDG generations as below –

If we run a JCL to delete the GDG Base as below –

//GDGPURGE JOB (345),’TRAINOOL’,CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//************************************************************
//* PURGE GDG EVEN THE EXPIRY DATE IS STILL NOT REACHED OR
//* RETENTION PERDION(RETP) IS NOT EXPIRED
//************************************************************
//STEP10 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
DELETE (MATEKS.TEST.PURGE) GDG PURGE
/*

Delete GDG Purge or Delete GDG Force

Output

This JCL will delete GDG Base and Generations.

Delete a particular Generation of a GDG or Delete GDG Generations

If you want to delete a particular Generation of a GDG or simply delete GDG Generations, then –

Use IEFBR14 utility where
DSN=MATEKS.TEST.PURGE(0)
DISP=(OLD,DELETE,DELETE)

You need to provide the generation of the GDG in IEFBR14 utility using DISP=(OLD,DELETE,DELETE). So, ‘Delete GDG Generations using IEFBR14’ is one of the most popular ways to delete a particular GDG Generation. Of course, you have a direction ISPF option 3.4 to directly delete the GDG Generation as well.

Tutorials for all brains!