RRDS


  • RRDS is a short form of Relative Record Data Set.
  • It 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.
  • It supports fixed-length and variable-length records.

RRDS divided into two types based on record length -

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

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

Syntax -

//JOBCARD
//*
//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 is RRDS.
  • INDEX component is applicable for variable-length RRDS only.

Refer IDCAMS DEFINE command for full set of parameters.

RRDS processing types -


RRDS supports three types of processing, and those are -

Access TypeDescription
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.

Fixed-length RRDS -


  • Fixed length RRDS file contains fixed-length records.
  • 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).
  • One fixed-length 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.

Create Fixed-length RRDS Example -


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

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//STEP01   EXEC PGM=IDCAMS
//SYSIN    DD  *
  DEFINE CLUSTER(NAME(MATEGJ.TEST.RRDS)  -
     RECORDSIZE(47,47)    -
     CYLINDERS(2,1)       -
     VOLUMES(DEVHD4)      -
     NUMBERED             -
     REUSE   )            -
  DATA(NAME(MATEGJ.TEST.RRDS.DATA))
/*
...

How to use Fixed-length RRDS files in the COBOL program?


Scenario - 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 (VRRDS) -


  • VRRDS is like an RRDS, except it contains only variable-length records.
  • VRRDS has no slots like fixed-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 be 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! RRDS dataset is not used frequently.

Create Variable-length RRDS Example -


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

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//STEP01   EXEC PGM=IDCAMS
//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))
/*
...
Note! As specified above, INDEX component is required for variable-length RRDS. If the INDEX component is missed in define cluster JCL, INDEX component created automatically.

How to use variable-length RRDS files in the COBOL program?


Scenario - 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.

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 -

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//STEP01   EXEC PGM=IDCAMS 
//INPUT    DD   DSN=MATEGJ.TEST.DATA,DISP=SHR
//OUTPUT   DD   DSN=MATEGJ.TEST.RRDS,DISP=SHR
//SYSIN    DD   *
      REPRO    -
           INFILE(INPUT)   - 
           OUTFILE(OUTPUT)
/*
...

In the above JCL, MATEGJ.TEST.DATA is the flat file and MATEGJ.TEST.RRDS is the RRDS 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 -


Scenario - Delete RRDS using the IDCAMS utility.

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//STEP01   EXEC PGM=IDCAMS
//SYSPRINT DD   SYSOUT=* 
//SYSIN    DD   *
      DELETE 'MATEGJ.TEST.RRDS'
/*
...

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

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.

Advantages -


  • Easy and fast creation.
  • Record accessing speed is high 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.