Generation Data Group (GDG)
What is GDG?
GDG stands for "Generation Data Group", a concept in the mainframe that allows organizing and managing datasets or files over the time. These are a group of datasets that are logically related (with the same attributes like format and record length) to each other from the process and usage point of view.
Generation data sets (GDSs) can be sequential (PS), direct, or partitioned data sets (PDS).
Naming of GDG?
All datasets (generation) within GDG share the same name except the last qualifier, which is a combination of the generation number and version number. The same name is called as "GDG Base", and the remaining datasets with a different qualifier at the end are called as "GDG Files or GDG Generations". At any point, a GDG can have a maximum of 255 generations.
Absolute (full) Generation & Version Numbers -
The generation and version numbers are used to identify a specific generation of GDG. The format is -
MATEPK.TEST.GDG.GmmmmVnn
In the above -
- MATEPK.TEST.GDG is the GDG base name.
- GmmmmVnn is the generation and version numbers form, where mmmm is a 4-digit generation number (ranges from 0001 to 9999) and nn is a 2-digit version number (ranges from 00 to 99).
Relative Version Numbers -
We can also use relative generation numbers to refer to the GDG datasets based on their position from the latest GDG file. To code a relative number, we can use the GDG name followed by a negative integer, a positive integer, or a 0, enclosed in parentheses —for example, X.Y.Z(-1). X.Y.Z(+1), or X.Y.Z(0).
MATEPK.TEST.GDG([+|-]nnn)
In the above -
- MATEPK.TEST.GDG is the GDG base name.
- nnn is the relative number of the GDG generation from the latest. nnn is a 3-digit generation number (ranges from 001 to 255). So, at any point in time, a GDG can have a maximum of 255 generations.
Example - Let us assume we have a GDG like the one below, and we will discuss how the relative number is used on it.
MATEPK.TEST.GDG
MATEPK.TEST.GDG.G0001V00
MATEPK.TEST.GDG.G0002V00
- MATEPK.TEST.GDG(0) refers to the latest generation. From the above example, it refers to MATEPK.TEST.GDG.G0002V00.
- MATEPK.TEST.GDG(-nnn) refers to the previous generation from the latest. From the example, MATEPK.TEST.GDG(-1) refers to MATEPK.TEST.GDG.G0001V00.
- MATEPK.TEST.GDG(+nnn) refers to the newly created generation on top of the latest generation. From the example, MATEPK.TEST.GDG(+1) refers to MATEPK.TEST.GDG.G0003V00.
+nnn (positive relative number) is only used when creating a new generation in the JCL. For example, +1 is the first new generation, +2 is the second generation, and so on.
Once the JCL is run successfully, the last newly created generation becomes the latest, referring to a relative number (0), and the old generation's relative numbers are updated accordingly.
Rules to Remember -
- All the generations of a GDG should have the same attributes (DCB parameters such as record length, record format, and so on).
- A maximum of 255 generations can exist within a GDG.
- GDGs should be cataloged.
- Generations of GDG should be sequential and reside on disk.
- While creating a new generation, the DISP parameter should be set to (NEW, CATLG,...).
- DSN and UNIT parameters are mandatory for creating a new generation.
- Generation data sets cannot be VSAM data sets.
Creating New GDG Base -
Before using GDG, we need to create a GDG base first. Then, we need to create the generations on it. IDCAMS utility is used to create a GDG base. The syntax is as follows -
----+----1----+----2----+----3----+----4
//job-card
//STEP01 EXEC PGM=IDCAMS
//SYSIN DD *
DEFINE GDG(NAME(gdg-base-name) -
LIMIT(nnn) -
EMPTY|NOEMPTY -
SCRATCH|NOSCRATCH)
/*
- LIMIT(nnn) - Specifies the total number of generations that the GDG may contain. The maximum value for LIMIT is 255.
- EMPTY|NOEMPTY - These are mutually exclusive parameters.
EMPTY parameter specifies that all existing generations are to be uncataloged whenever the generations of GDG reach the maximum limit.
NOEMPTY specifies that only the oldest generation of the GDG is to be uncataloged if the limit is reached. - SCRATCH|NOSCRATCH - These are mutually exclusive parameters.
SCRATCH specifies that the generation should be deleted physically when uncataloged.
NOSCRATCH specifies that the generation should not be deleted when it is uncataloged. It can be accessed using the UNIT and VOL parameters.
Practical Example -
Scenario - Create a GDG base with 5 generations limit and delete the oldest generation when it reaches the limit.
Code -
----+----1----+----2----+----3----+----4----+----5----+----6
//MATEPKCG JOB (123),'MTH',CLASS=A,MSGCLASS=A,
// MSGLEVEL=(1,1),NOTIFY=&SYSUID
//****************************************
//* Create GDG Base
//****************************************
//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE GDG(NAME(MATEPK.TESTPS.GDG) -
LIMIT(05) -
NOEMPTY -
SCRATCH)
/*
In this example, the IDCAMS utility creates the GDG called MATEPK.TESTPS.GDG. The number of generations that can exist at anytime is limited to five. NOEMPTY specifies the system should uncatalog the oldest generation once the limit is reached. The SCRATCH parameter determines whether to delete the uncataloged data set physically.
Creating New Generation -
A GDG generation can be a PS. It is used to take the PRODuction or test files backup. IEFBR14 utility creates the generation as PS.
Example -
Scenario - Create GDG generation as PS.
----+----1----+----2----+----3----+----4----+----5----+----6
//MATEPKPS JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//********************************************************
//* Allocate generation using IEFBR14 Utility
//********************************************************
//STEP01 EXEC PGM=IEFBR14
//DD1 DD DSN=MATEPK.TESTPS.GDG(+1),
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
In the above example, we have created GDG generation as PS. This generation can work the same as the regular PS. It is mainly used to take the PRODuction files backup during the region cycle backup.
Using GDG in JCL -
To reference a GDG generation in a JCL, we use its name along with a generation number or a relative generation number.
- Absolute Generation Reference - MATEPK.TESTPS.GDG.G0001V00
- Relative Generation Reference - MATEPK.TESTPS.GDG(0)
Examples -
Scenario1 - Let us assume the GDG has two generations, as shown below. Copy the current GDG version to the new version using the absolute generation number.
MATEPK.TEST.GDG
MATEPK.TEST.GDG.G0001V00
Code -
----+----1----+----2----+----3----+----4----+----5----+----6
//MATEPKCG JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//STEP10 EXEC PGM=IEBGENER
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD DSN=MATEPK.TEST.GDG.G0001V00,DISP=SHR
//SYSUT2 DD DSN=MATEPK.TEST.GDG.G0002V00,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(10,10),RLSE),
// UNIT=3390,VOL=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSIN DD DUMMY
We can use the absolute generation number to refer to the generations in the JCL. In this scenario, we code the full name of the generation.
Scenario2 - Let us assume the GDG has three generations, as shown below. Copy the current GDG version to the new version using the relative generation number..
MATEPK.TEST.GDG
MATEPK.TEST.GDG.G0001V00
MATEPK.TEST.GDG.G0002V00
Code -
----+----1----+----2----+----3----+----4----+----5----+----6
//MATEPKCG JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//STEP10 EXEC PGM=IEBGENER
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD DSN=MATEPK.TEST.GDG(0),DISP=SHR
//SYSUT2 DD DSN=MATEPK.TEST.GDG(+1),
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(10,10),RLSE),
// UNIT=3390,VOL=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSIN DD DUMMY
We can use the relative generation number to refer to the generations in the JCL.
Alter GDG parameters -
Sometimes, there are some scenarios where we need to change the attributes of GDG. Modifying the parameters of a GDG involves altering the characteristics of the GDG base. This can be done using the IDCAMS utility in JCL.
Example -
Scenario - Let us assume the GDG is defined with NOEMPTY and has two generations, as shown below. Alter the GDG base with the EMPTY option.
MATEPK.TEST.GDG
MATEPK.TEST.GDG.G0001V00
MATEPK.TEST.GDG.G0002V00
Code -
----+----1----+----2----+----3----+----4----+
//MATEPKMG JOB (123),'MTH',CLASS=A,
// MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
ALTER MATEPK.TEST.GDG EMPTY
/*
In the above example, we have modified the GDG parameter from NOEMPTY to EMPTY. The ALTER statement is used to modify the parameters of the MATEPK.TEST.GDG. The newly modified features applied to any existing generations or new generations created for the GDG.
Delete GDG or Generations -
Deleting a Generation Data Group (GDG) involves two key aspects: deleting the GDG base and optionally deleting the individual generations (datasets) associated with that GDG.
Deleting Generation -
If we want to delete the individual generations associated with the GDG, we should delete them separately. This can be done either before or after deleting the GDG base.
Scenario - Delete the latest generation.
MATEPK.TEST.GDG
MATEPK.TEST.GDG.G0001V00
MATEPK.TEST.GDG.G0002V00
Code -
----+----1----+----2----+----3----+----4----+----5----+
//MATEPKDG JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//STEP1 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=A
//SYSIN DD *
DELETE (MATEPK.TEST.GDG(0)) GDG
/*
In the above example, we have deleted the latest generation (MATEPK.TEST.GDG.G0002V00) of the GDG MATEPK.TEST.GDG.
Deleting GDG Base -
To delete a GDG base, we typically use the IDCAMS utility DELETE statement in JCL. DELETE statement uses two parameters: -
- PURGE parameter deletes the GDG base, even if its retention period has not expired.
- FORCE parameter is used to delete the GDG base, the model, and all related generations if they exist.
Scenario - Deleting GDG Base.
MATEPK.TEST.GDG
MATEPK.TEST.GDG.G0001V00
MATEPK.TEST.GDG.G0002V00
Code -
----+----1----+----2----+----3----+----4----+----5----+
//MATEPKC JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//*
//STEP1 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=A
//SYSIN DD *
DELETE (MATEPK.TEST.GDG) GDG FORCE
/*
In the above example, we have deleted the base (MATEPK.TEST.GDG.G0002V00) and all its generations that are currently on it.