Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 5: Data Division


REDEFINES clause

  • REDEFINES clause is used to describe the same storage area for more than one data name
  • For example,

    01 EMPLOYEE. 05 EMPLOYEE-TYPE PIC X(04). 05 EMP-PERMANENT. 10 EMP-ID PIC X(05). 10 EMP-NAME PIC X(10). 10 EMP-SALARY PIC 9(04)V99. 05 EMP-TEMPORARY REDEFINES EMP-PERMANENT. 10 T-NAME PIC X(15). 10 TEMP-SALARY PIC 9(04)V99.

  • The size of EMPLOYEE group item is 25 bytes. Above declaration is now able to handle both type of records PERM and TEMP depicted below:-
  • In above example data declaration, EMPLOYEE record can be of two types, either permanent (PERM) or temporary (TEMP). So when the employee is permanent within company, he/she must have employee id but if he/she is temporary then only name details is enough. So in order to handle such situation and to save space, we can use the same storage area to describe different data. Depending value of EMPLOYEE-TYPE the record will be interpreted in one of the two forms (i.e. either EMP-PERMANENT or EMP-TEMPORARY). Note that EMP-PERMANENT and EMP-TEMPORARY refer to same storage space. They really represent two different mappings of the same storage area.
  • As we have seen in the above example, sometimes two or more storage areas defined in DATA DIVISION are not used simultaneously. In such cases, only one storage area can serve the purpose of two or more areas if the area is redefined.
  • Basic syntax of the REDEFINES clause:-

    LEVEL_NUM data-name-1 REDEFINES data-name-2

  • data-name-1 is redefining data item and data-name-2 is redefined data item
  • Important rules to be considered while using REDEFINES clause:-
    • The level number of data-name-1 and data-name-2 must be same
    • Redefining data item declaration must immediately follow redefined data item
    • For non-01 level redefinition, the redefining data item size should be equal to the item being redefined. In case of 01 level redefinition, the redefining data item size should be equal to or less than redefined data item.
    • Value clause should not be used for data-name-1 (redefining data item) or to its subordinates.
    • Multiple data item can redefine the same data item.
    • REDEFINES clause cannot be used for records (01 level) described in FILE SECTION.
    • REDEFEINES clause cannot be used for level number 66 and 88






© copyright mainframebug.com
Privacy Policy