Cobol

REDEFINES and RENAMES use in COBOL Program

REDEFINES: Sometimes, it may be found that two or more storage areas defined in the DATA DIVISION are not in use simultaneously. In such cases, only one storage area can serve the purpose of two or more areas if the area is redefined.

The REDEFINES clause allows the same memory area to be described by different data items. In program if we are sure that 2 or more date names are not in use at the same time then we go for redefines clause.

Advantage: Conservation of Storage space

Format:

>>-level-number--+--------+--REDEFINES--data-name-2-------><
+-data-name-1-+
'-FILLER------'

(Level-number, data-name-1, and FILLER are not part of the REDEFINES clause, and are included in the format only for clarity.)

When specified, the REDEFINES clause must be the first entry following data-name-1 or FILLER. If data-name-1 or FILLER is not specified, the REDEFINES clause must be the first entry following the level-number

Rules:

  • The level-number of data-name-1 and data-name-2 must be identical.
  • Except when the REDEFINES clause is used to 01 level, data-name-1 and data-name-2 must be of the same size
  • When the 01 level is used, the size of data-name-1 must not exceed that of dataname-2
  • Multiple redefinitions are allowed. The entries giving the new descriptions must immediately follow the REDEFINES entry. Page 25 of 104 Tips for Mainframe Programmers
  • In the case of multiple redefinitions, the data-name-2 must be the data name of the entry that originally defined the area.
  • The REDEFINES clause must immediately follow the data-name-1
  • Entries giving new descriptions can’t have the value clauses (except in the case of condition-names(88))
  • The REDEFINES clause must not be used for records (01 level) described in the FILE SECTION. The appearance of multiple 01 entries in the record description is implicitly assumed to be the redefinition of the first 01 level record.
  • This clause must not be used for level-number 66 or 88Difference between REDEFINES and RENAMES: RENAMES clause is used for regrouping elementary data items and gives one name to it. REDEFINES clause allows you to use different data descriptions entries to describe same memory area

Examples:01

01 WS-NAME.
      05 WS_FST-NAME PIC X(05) VALUE “John”.
      05 WS_FST-NAME PIC X(05) VALUE “Mike”.
01 WS-TOTAL-NAME REDEFINES WS-NAME PIC X(10).

In above example WS-TOTAL-NAME will use same memory area allocated to WS-NAME.
So WS-TOTAL-NAME will have “John Mike”

Examples:02

01 PAY-REC.
   05 FIXED-PAY.
      10 BASIC-PAY PIC 9(6)V99.
01 WS-NAME.
   05 WS_FST-NAME PIC X(05) VALUE “John”.
   05 WS_FST-NAME PIC X(05) VALUE “Mike”.
01 WS-TOTAL-NAME REDEFINES WS-NAME PIC X(10).

In above example WS-TOTAL-NAME will use same memory area allocated to WS-NAME.So WS-TOTAL-NAME will have “John Mike”

Examples:03

IDENTIFICATION DIVISION.
PROGRAM-ID. REDEFINES.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-DESCRIPTION.
   05 WS-DATE-DOJ VALUE '19990815'.
   10 WS-YEAR PIC X(4).
   10 WS-MONTH PIC X(2).
   10 WS-DATE PIC X(2).
   05 WS-DATE-TERM REDEFINES WS-DATE-DOJ PIC 9(8).

PROCEDURE DIVISION.
   DISPLAY “DEFAULT DATE IS : " WS-DATE-DOJ.
   COMPUTE WS-DATE-TERM = FUNCTION DATE-OF-INTEGER 
                (365 + FUNCTION INTEGER-OF-DATE (19990815))
   DISPLAY “NEW DEFAULT DATE IS : " WS-DATE-DOJ.
   DISPLAY "TERM DATE IS : " WS-DATE-TERM.

STOP RUN.

RESULTS:
DEFAULT DATE IS : 19990815
NEW DEFAULT DATE IS : 20000814
TERM DATE IS : 20000814

RENAMES: Sometimes a re-grouping of elementary data items in a record may be necessary so that they can belong to the original as well as to the new group.

REDEFINES VS RENAMES:

RENAMES: Sometimes a re-grouping of elementary data items in a record may be necessary so that they can belong to the original as well as to the new group.

Format:

>>-66–data-name-1–RENAMES–data-name-2————————> >–+————————–+——————————–><   ‘-+-THROUGH-+–data-name-3-‘        ‘-THRU—-‘ 

Rules:

  • All RENAMES entries must be written only after the last record description entry
  • The RENAMES clause must be used only with the special level number 66
  • Data-name-2 and data-name-3 can be the names of elementary items or group items. They, however, can’t be items of levels 01,66,77 or 88
  • Neither data-name-2 nor data-name-3 can have an OCCURS clause in its description entry, nor can they be subordinate to an item that has an occurs clause in its data description entry
  • Data-name-3, if mentioned, must follow data-name-2, in the record and must not be one of its subfields.

Example 01

01 PAY-REC.
   05 FIXED-PAY.
      10 BASIC-PAY PIC 9(6)V99.
      10 DEARNESS-ALLOWANCE PIC 9(6)V99.
05 ADDITIONAL-PAY.
   10 HOUSE-RENT PIC 9(4)V99.
   10 MNTHLY-INCENTIVE PIC 9(3)V99.
05 DEDUCTIONS.
   10 PF-DEDUCT PIC 9(3)V99.
   10 IT-DEDUCT PIC 9(4)V99.
   10 OTHER-DEDUCT PIC 9(3)V99.
66 PAY-OTHER-THAN-BASIC RENAMES DEARNESS-ALLOWANCE THRU MNTHLY-INCENTIVE
66 IT-AND-PF-DEDUCTIONS RENAMES PF-DEDUCT THRU IT-DEDUCT.

In the above example, PAY-OTHER-THAN-BASIC will become a new group consisting of DEARNESS-ALLOWANCE, HOUSE-RENT, and MNTHLY-INCENTIVE. Note that the new group overlaps on two original groups, namely, part of FIXED-PAY and the entire ADDITIONALPAY. Such overlapping is allowed provided the elementary items are all contiguous. In a similar way, IT-AND-PF-DEDUCTIONS has two elementary items PF-DEDUCT and ITDEDUCT. This new group is formed out of the original group DEDUCTIONS. Alternatively, the same thing can also be done in the original group description by placing like this

05 DEDUCTIONS.
     10 IT-AND-PF-DEDUCTIONS.
            15 PF-DEDUCT PIC 9(3)V99.
             15 IT-DEDUCT PIC 9(4)

Example 02

IDENTIFICATION DIVISION.
PROGRAM-ID. RENAMES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PAY-REC.
   05 FIXED-PAY.
      10 BASIC-PAY PIC 9(6)V99.
      10 DEARNESS-ALLOWANCE PIC 9(6)V99.
   05 ADDITIONAL-PAY.
      10 HOUSE-RENT PIC 9(4)V99.
      10 MNTHLY-INCENTIVE PIC 9(3)V99.
   05 DEDUCTIONS.
      10 PF-DEDUCT PIC 9(3)V99.
      10 IT-DEDUCT PIC 9(4)V99.
      10 OTHER-DEDUCT PIC 9(3)V99.
66 PAY-OTHER-THAN-BASIC RENAMES DEARNESS-ALLOWANCE THRU MNTHLY-INCENTIVE.
66 IT-AND-PF-DEDUCTIONS RENAMES PF-DEDUCT THRU IT-DEDUCT.

PROCEDURE DIVISION.
MOVE 200 TO BASIC-PAY
MOVE 100 TO DEARNESS-ALLOWANCE
MOVE 20 TO HOUSE-RENT
MOVE 8 TO MNTHLY-INCENTIVE
MOVE 5 TO PF-DEDUCT
MOVE 4 TO IT-DEDUCT
MOVE 3 TO OTHER-DEDUCT
DISPLAY "PAY-OTHER-THAN-BASIC : " PAY-OTHER-THAN-BASIC.
DISPLAY "IT-AND-PF-DEDUCTIONS : " IT-AND-PF-DEDUCTIONS.
STOP RUN.

RESULT:
PAY-OTHER-THAN-BASIC : 0001000000200000800 
IT-AND-PF-DEDUCTIONS : 00500000400

REDEFINES VS RENAMES:

RENAMES clause is used for regrouping elementary data items and gives one name to it. REDEFINES clause allows you to use different data descriptions entries to describe the same memory area.

COBOL Blog: Click Here IBM Reference: Click Here

Admin

Share
Published by
Admin

Recent Posts

Increase Transparency and Collaboration Product Backlog

A well-maintained product backlog is crucial for successful product development. It serves as a single…

4 days ago

Product Backlog – Incremental value to the customer

Incremental value to the customer refers to the gradual delivery of small, functional parts of…

6 days ago

Product Market, Customer’s Desire, Need, and Challenges

A Product Market refers to the group of potential customers who might be interested in…

1 week ago

PAL-EBM Professional Agile Leadership – EBM Certification

The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…

3 months ago

PAL I Professional Agile Leadership Certification

The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…

4 months ago

Scrum Master Certification: CSM, PSM, SSM

Choosing the right Scrum Master Certification depends on your current experience and career goals. If…

5 months ago