RRDS (for Experienced)


  • RRDS is a short form of Relative Record Data Set.
  • RRDS has both DATA and INDEX components.
  • A record is identified by its relative record number (RRN).
  • The first record in the data set is RRN 1, and the second is RRN 2, and so on. The RRN can be changed based on the record position in the file.
  • RRDS supports fixed-length and variable-length records.

RRDS divided into two types based on record length -

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

Fixed-length RRDS -


  • Fixed length RRDS file have the records of fixed length.
  • Fixed length RRDS file have only DATA component.
  • 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 is stored in a slot.
  • The record is stored and retrieved by using the RRN of the slot. i.e., Every RRN has a dedicated slot. The slot can either contain data or be empty; RRN is permanent for the slot.
  • The RDF shows the slot has the record or is empty.
  • The records are reorganized as specified below for each operation -
    • If inserting a record, it places in the empty slot of RRN and no change in the other RRNs position.
    • If deleting a record, it deletes from the RNN slot, makes it available for another record insertion, and no change in the other RRNs position.
    • If updating a record, there will be no change in records positions.

Variable-length RRDS (VRRDS) -


  • VRRDS is like an RRDS, except it contains only variable-length records.
  • VRRDS has no slots like RRDS.
  • VRRDS has DATA and INDEX components.
  • 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 cannot get changed.
  • The RRN is reused for the new record if a record is deleted.
  • VRRDS acts as KSDS, whereas it accesses with RRN instead of a key.
Note! This type of dataset is not used frequently.

RRDS processing types -


RRDS supports three types of processing, and those are -

Access Type Description
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.
Dynamic Access
or
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 Syntax -


IDCAMS DEFINE CLUSTER command with NUMBERED parameter is used to create RRDS dataset.

Syntax - JCL for creating fixed-length RRDS dataset.

//JOBCARD
//*------------------------------------------------------------------
//* Definition of fixed-length 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)
/*

Syntax - JCL for creating variable-length RRDS dataset.

//JOBCARD
//*------------------------------------------------------------------
//* Definition of variable-length 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)) 		-
    INDEX (NAME(userid.CLUSTER.NAME.INDEX)) 	-
    CATALOG(XXXXXX)
/*

In the above syntax,

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

Refer IDCAMS DEFINE command for full set of parameters.

Create Fixed-length RRDS Example -


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

Code -

----+----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 that 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 that the memory can reuse immediately once the file gets deleted.

Create Variable-length RRDS Example -


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

Code -

----+----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 that 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 that 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.
  • Record accessing at high speed using RRN.
  • Can access the records sequentially, randomly, and dynamically (Skip-sequential).
  • Fixed-length RRDS datasets use less storage and are usually faster at retrieving records than KSDS or variable-length RRDS datasets.

Disadvantages -


  • The structure depends on numbering sequences.
  • Fixed-length records requires more space as RRN slots are kept empty until corresponding record inserted.

Usage -


  • Applications have only direct access to retrieve the records of the file.
  • 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 -


IDCAMS utility is used to copy the data from the PS file to RRDS. The JCL is shown below -

Code -

----+----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 Example -


Requirement - Delete RRDS using the IDCAMS utility.

Code -

----+----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 in the COBOL program below.

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 record 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-2 represents the logical record used to insert the data to a file or read the data from a file.