RRDS is a short form of Relative Record Data Set. RRDS has both DATA and INDEX components. RRDS supports fixed-length and variable-length records. Based on the record type, the RRDS divided into two types -

  • Fixed-length RRDS (RRDS).
  • Variable-length RRDS (VRRDS).

Fixed-length RRDS -

RRDS has several fixed-length pre-formatted logical-record slots. Each slot has a unique Relative Record Number (RRN), varying from 1 to the maximum number of records in the dataset. The slots are arranged in ascending order based on RRN. The slots are grouped in CI(s).

Each fixed-length logical record stores in a slot. The record is stored and retrieved by using the RRN of the slot. i.e., The logical record has a fixed position, and its RRN cannot be changed.

The slot can either contain data or be empty; RRN is permanent for the slot. The RDF shows the slot has the record or empty.

  • RRDS records must be of fixed length. If inserting a record, it places in the empty slot and no change in the RRN for the slot.
  • If deleting a record, it deletes from the slot, makes it available for another record insertion, and no change in RRN for the slot.
  • If updating a record, there will be no change in records positions as well as records RRN.

Variable-length RRDS (VRRDS) -

VRRDS is like an RRDS, except it contains only variable-length records. VRRDS has no slots like RRDS. Each record has a unique Relative Record Number (RRN), and records are placed in ascending order of RRN. RRN is used to access the record from the VRRDS, and RRN can't get changed.

If a record is deleted, the RRN is reused for the new record. VRRDS acts as KSDS, whereas it accesses with RRN instead of a key.

Note! This organization is not used frequently.

RRDS processing types -

RRDS supports three types of processing, and those are -

Sequential access -

RRDS sequential access is the same as ESDS sequential access. RRDS can be accessed from the beginning without providing RRN.

Direct access -

RRDS supports direct accessing a record by supplying the RRN. The RRN uses as a search argument for random access always.

VSAM calculates the RBA from the supplied RRN and retrieves the record. Accessing a record directly by providing RBA is not supported.

Skip-Sequential access -

RRDS supports skip-sequential access by positioning at a record through direct access. After that, records are processed in ascending RRN sequence.

DEFINE RRDS -

RRDS data set can be created using the NUMBERED parameter in the IDCAMS DEFINE CLUSTER command.

Syntax -

RRDS- JCL for creating RRDS dataset:

//JOB CARD
//*------------------------------------------------------------------
//* Definition of RRDS
//*------------------------------------------------------------------
//STEP01  EXEC PGM=IDCAMS
//SYSPRINT  DD SYSOUT=*
//SYSIN     DD *
    DEFINE CLUSTER 				-
       (NAME(userid.CLUSTER.NAME) 		–
	CYLINDERS(primary secondary)		-
       	VOL(XXXXXX) 				–
	BUFFERSPACE(buffer-space)		–
	CONTROLINTERVALSIZE(ci-size) 		–
	FREESPACE(primary secondary)		–	
	RECORDSIZE(avg max) 			–
        NUMBERED 				-
        NOREUSE 				-
        OWNER(userid) ) 			-
      DATA 					-
        (NAME(userid.CLUSTER.NAME.DATA)) 	-
      CATALOG(XXXXXX)

/*

In the above syntax,

  • The NUMBERED parameter specifies the file that is creating is RRDS.
  • The remaining parameters usage is almost identical for RRDS or KSDS. Note that the values in the parameter might change.

Create Fixed-length RRDS JCL -

Requirement - Create RRDS with fixed-length records of size 47 bytes.

Code -

Create RRDS JCL
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEGJR JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),            
//             NOTIFY=&SYSUID                                           
//************************************************************          
//* DEFINE VSAM FIXED LENGTH RRDS CLUSTER                               
//************************************************************          
//STEP01   EXEC PGM=IDCAMS                                              
//SYSPRINT DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD  *                                                        
  DEFINE CLUSTER(NAME(MATEGJ.TEST.RRDS)  -                              
     RECORDSIZE(47,47)    -                                             
     CYLINDERS(2,1)       -                                             
     VOLUMES(DEVHD4)      -                                             
     NUMBERED             -                                             
     REUSE   )            -                                             
  DATA(NAME(MATEGJ.TEST.RRDS.DATA))                                     
/*                                                                      
**************************** Bottom of Data ****************************

In the above JCL, MATEGJ is the userid and changes all as required.

Output -

Once the above JCL is submitted, check the MAXCC of the job for any errors. If the MAXCC is 00 or 04, RRDS successfully created.

Create RRDS Output

Verify the RRDS in 3.4 (Dataset List utility) or any File management tools.

Create RRDS Output

Explaining Example -

In the above example,

  • RECORDSIZE(47,47) specifies the record average length is 47, and the maximum length is 47. So the RRDS file we are creating is fixed-length.
  • CYLINDERS(2,1) specifies the primary memory allocation is 2 CYLINDERS, and secondary memory allocation is 1 CYLINDER.
  • VOLUMES(DEVHD4) specifies that allocate the RRDS on volume DEVHD4.
  • NUMBERED parameter specifies the file is to create RRDS.
  • REUSE specifies the memory can reuse immediately once the file gets deleted.
Note! In the above example, the RRDS file was created with minimum parameters. Add the additional parameters based on the requirements. Refer total parameters description in Define Cluster topic.

Create Variable-length RRDS JCL -

Requirement - Create RRDS with variable-length records of average size 47 and maximum size 67 bytes.

Code -

Create RRDS JCL
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEGJR JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),            
//             NOTIFY=&SYSUID                                           
//************************************************************          
//* DEFINE VSAM VARIABLE LENGTH RRDS CLUSTER                            
//************************************************************          
//STEP01   EXEC PGM=IDCAMS                                              
//SYSPRINT DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD  *                                                        
  DEFINE CLUSTER(NAME(MATEGJ.TEST.VRRDS)  -                             
     RECORDSIZE(47,67)    -                                             
     CYLINDERS(2,1)       -                                             
     VOLUMES(DEVHD4)      -                                             
     NUMBERED             -                                             
     REUSE   )            -                                             
  INDEX(NAME(MATEGJ.TEST.VRRDS.INDEX))    -                             
  DATA(NAME(MATEGJ.TEST.VRRDS.DATA))                                    
/*                                                                      
**************************** Bottom of Data ****************************

In the above JCL, MATEGJ is the userid and changes all as required.

Output -

Once the above JCL is submitted, check the MAXCC of the job for any errors. If the MAXCC is 00 or 04, RRDS successfully created.

Create RRDS Output

Verify the RRDS in 3.4 (Dataset List utility) or any File management tools.

Create RRDS Output

Explaining Example -

In the above example,

  • RECORDSIZE(47,67) specifies the record average length is 47, and the maximum length is 67. So the RRDS file we are creating is variable-length.
  • CYLINDERS(2,1) specifies the primary memory allocation is 2 CYLINDERS, and secondary memory allocation is 1 CYLINDER.
  • VOLUMES(DEVHD4) specifies that allocate the RRDS on volume DEVHD4.
  • NUMBERED parameter specifies the file is to create RRDS.
  • REUSE specifies the memory can reuse immediately once the file gets deleted.
Note! As specified above, INDEX component is required for variable-length RRDS. If the INDEX component is missed in create JCL, INDEX component created automatically.

Advantages -

  • Easy and fast creation.
  • Sppedy access to the record by RRN.
  • Can access the records sequentially, randonly and dynamicallu(Skip-sequential).
  • Fixed-length RRDSs use less storage and are usually faster at retrieving records than KSDS or variable-length RRDSs.

Disadvantages -

  • Structure depending on numbering sequences.
  • Fixed-length records.

Usage -

  • Applications that require only direct access.
  • Applications with there is a one-to-one correspondence between records and RRNs.

Loading Data to RRDS -

Loading data to RRDS can be done in three ways -

  • Using utilities.
  • Using File Management Tools[Covered in tools section in future].
  • Through programmatically[Covered as part of COBOL tutorial ].

Using utilities -

If the records count is more, load the records to a flat file(PS) and copy PS's data to RRDS. To do that, IDCAMS utility used like below -

Code -

Loading RRDS
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEGJR JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),            
//             NOTIFY=&SYSUID                                           
//************************************************************          
//* LOADING DATA TO RRDS FROM PS(FLAT FILE)                             
//************************************************************          
//STEP01   EXEC PGM=IDCAMS                                              
//SYSPRINT DD   SYSOUT=*                                                
//INPUT    DD   DSN=MATEGJ.TEST.DATA,DISP=SHR                           
//OUTPUT   DD   DSN=MATEGJ.TEST.RRDS,DISP=SHR                           
//SYSIN    DD   *                                                       
      REPRO    -                                                        
           INFILE(INPUT)   -                                            
           OUTFILE(OUTPUT)                                              
/*                                                                      
**************************** Bottom of Data ****************************

In the above JCL, MATEGJ.TEST.DATA is the flat file and MATEGJ.TEST.RRDS is the RRDS file.

Output -

Once the above JCL is submitted, check the MAXCC of the job for any errors. If the MAXCC is 00 or 04, RRDS successfully loaded with records.

loading RRDS Output

Verify the RRDS in 3.4 (Dataset List utility) or any File management tools.

loading RRDS Output

Explaining Example -

In the above example, all the records from the MATEGJ.TEST.DATA(flat file of length 47) file copied to MATEGJ.TEST.RRDS(RRDS file of length 47) file.

Note! The flat file(PS) and RRDS file should have the same record length(47 in the above example) to load the data successfully.

Delete RRDS -

Requirement - Delete RRDS using the IDCAMS utility.

Code -

Delete RRDS
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEGJD JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),            
//             NOTIFY=&SYSUID                                           
//************************************************************          
//* DELETING RRDS                                                       
//************************************************************          
//STEP01   EXEC PGM=IDCAMS                                              
//SYSPRINT DD   SYSOUT=*                                                
//SYSIN    DD   *                                                       
      DELETE 'MATEGJ.TEST.RRDS'                                         
/*                                                                      
**************************** Bottom of Data ****************************

In the above JCL, MATEGJ.TEST.RRDS is the RRDS name that is planned to delete.

Output -

Once the above JCL is submitted, check the MAXCC of the job for any errors. If the MAXCC is 00 or 04, RRDS successfully got deleted.

DELETE RRDS Output

Verify the RRDS in 3.4 (Dataset List utility) or any File management tools if required to double-check.

DELETE RRDS Output

Explaining Example -

In the above example, the MATEGJ.TEST.RRDS (RRDS file) successfully deleted and uncatalogued(space released).

Note! If the file is already deleted and trying to delete the file again, we may receive MAXCC as 08. So, verify the file once before proceeding for delete.

How to use RRDS in the COBOL program?

Fixed-length RRDS files -

Requirement - Define the fixed-length RRDS file for RANDOM access in the COBOL program.

Let us assume MATEGJ.TEST.RRDS is the RRDS file with the record length 47, and it is defined like below in the COBOL program.

In Environment Division -

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
	SELECT RRDS-1 ASSIGN to INPUT.
	ORGANIZATION IS RELATIVE.
	ACCESS MODE IS RANDOM.
	RELATIVE KEY is RRDS-KEY-1.
	FILE STATUS IS file-status1.

In Data Division -

DATA DIVISION.
FILE SECTION.
FD RRDS-1.
	RECORD CONTAINS 47 CHARACTERS.
	BLOCK CONTAINS 470 CHARACTERS.
	DATA RECORD is RRDS-RECORD-1.
	RECORDING MODE IS F.

01 RRDS-RECORD-1 PIC X(47).

In the above example, RRDS-1 is the file-name used to represent the RRDS file in the COBOL program. INPUT is the DDNAME used to map with the JCL DDNAME specified corresponding to the RRDS file. For example,

//INPUT DD DSN=MATEGJ.TEST.RRDS,DISP=SHR

RRDS-RECORD-1 represents the logical record used to insert the data to a file or read the data from a file.

Variable-length RRDS files -

Requirement - Define the variable-length RRDS file for DYNAMIC access in the COBOL program.

Let us assume MATEGJ.TEST.VRRDS is the variable-length RRDS file with rectord length 47 to 67, and it is defined like below in the COBOL program.

In Environment Division -

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
	SELECT RRDS-2 ASSIGN to INPUTV.
	ORGANIZATION IS RELATIVE.
	ACCESS MODE IS DYNAMIC.
	RELATIVE KEY is RRDS-KEY-1.
	FILE STATUS IS file-status2.

In Data Division -

DATA DIVISION.
FILE SECTION.
FD RRDS-2.
	RECORD CONTAINS 47 TO 67 CHARACTERS.
	BLOCK CONTAINS 470 TO 670 CHARACTERS.
	DATA RECORD is RRDS-RECORD-2.
	RECORDING MODE IS V.

01 RRDS-RECORD-2 PIC X(67).

In the above example, RRDS-2 is the file-name used to represent the RRDS file in the COBOL program. INPUT is the DDNAME used to map with the JCL DDNAME specified corresponding to the RRDS file. For example,

//INPUTV DD DSN=MATEGJ.TEST.VRRDS,DISP=SHR

RRDS-RECORD-2 represents the logical record used to insert the data to a file or read the data from a file.