Bulletin Board

What’s new at MAINFRAMES 360
(Updates June '10)...
- I am writing articles on CICS. The effort would be to make the material of certain standard, practical and easy to comprehend.
- JCL needs fresh look, and more weightage needs to assigned to conventions and practises adopted in Production Environments at most sites
- A note of appreciation : Thanks to all our followers, for making Mainframes360 a success!

Mainframes360 Search

Loading

Quick Links

Jump to :  

Wednesday, September 2, 2009

REDEFINES Clause, RENAMES Clause


Contents

  1. REDEFINES Clause
    1. Simple Program to show how REDEFINES Works
  2. RENAMES Clause
    1. Simple Program to show how RENAMES Clause works


Q. What is the REDEFINES Clause in COBOL? Why is it used?

REDFINES Clause can be used to define two group data-items which point to the same storage area. You can use both the data-items in the same COBOL Program.

Suppose, we have a storage area defined in the Working Storage section as

01 EMPLOYEE-DETAILS.
   02 EMP-NAME PIC X(30).
   02 EMP-NAME-DETAILS REDEFINES EMP-NAME.
      03 EMP-FNAME PIC X(10).
      03 EMP-MNAME PIC X(10).
      03 EMP-LNAME PIC X(10).
 
   02 EMP-ADDRESS PIC X(26).
   02 EMP-ADDRESS-DETAILS REDEFINES EMP-ADDRESS.
      03 EMP-STREET PIC X(10).
      03 EMP-CITY PIC X(10).
      03 EMP-PINCODE PIC X(6).
   02 EMP-CONTACT PIC X(20).

   02 EMP-CONTACT-DETAILS REDEFINES EMP-CONTACT.
      03 EMP-PHONE1 PIC 9(10).
      03 EMP-PHONE2 PIC 9(10).

Note that :
1) In the above example, EMP-NAME has been redefined as EMP-NAME-DETAILS, EMP-ADDRESS is redefined as EMP-ADDRESS-DETAILS and EMP-CONTACT is redefined as
EMP-CONTACT-DETAILS. So, EMP-NAME occupies 30 bytes of storage area. The same 30-byte storage area is also pointed to by EMP-NAME-DETAILS, and it provides a breakup into FNAME, MNAME and LNAME. This is a common and typical use of REDEFINES clause.

2) One cannot use the REDFINES clause with 01-level(root-level) data-items in the FILE SECTION. It also should not be used 66-level(renames clause) and 88-level(condition names).

3) The data-item which you want to redefine should not have a OCCURS Clause.

4) Note that, the original data-items and redefined ones both refer to the same memory location in storage area. Hence, in the above example, the total space occupied by EMPLOYEE-DETAILS still remains the same = 30+26+20 = 76.

Q. Show me a COBOL Program that demonstrates how to use the REDEFINES Clause.

Given below is a COBOL Program that shows a practical use of REDEFINES.



 

Upon running the above COBOL Program LOAD, we get the following output in the SYSOUT Dataset -


Q. What is the RENAMES Clause? Is it a good practice to use the RENAMES Clause?

The RENAMES clause is used to regroup data-items. The RENAMES Clause entry always must have level no. 66. You can take existing Data-items, and re-group them, and create a new copy in the memory under a new data-name. Note, that both the copies – the memory locations always remain in sync. While using the RENAMES clause, one must follow certain rules in COBOL. They are as follows :

1) RENAMES clause has the following syntax

    66 new-data-name RENAMES data-item-1 THRU
data-item-2
2) The 66 level RENAMES entry should immediately follow data-items 1 and 2.

3) The Data-Items 1 and 2 should not be 01-Level record entries.

4) The Data-Items 1 and 2 should be contiguous.

5) The new-data name should be one logical level higher than the data-item-1 and data-item-2.

6) The use of RENAMES Clause has often been debated in COBOL, and its considered a malpractice to use the RENAMES Clause now-a-days. Instead, one must opt for REDEFINES Clause.

Q. Show me a simple working example of the RENAMES Clause..

Given below is a basic COBOL Program, that shows how to use the RENAMES Clause.





In the above example, there are two copies of FIELD-B, one in record-1 and another in record-3. Note that both copies of FIELD-B will always contain the same value/contents. Any changes to FIELD-B will affect record-1 as well as record-3. Note that, unlike REDEFINES clause, RENAMES clause occupies actual physical storage space. Upon submitting the above COBOL Program LOAD, we get the following output in the SYSOUT Dataset.


1 comments:

Vatsalya said...

Very useful demo.Actually iam loooking for such kind since many days.Thanks a ton

Post a Comment

Related Posts with Thumbnails

Quick Links

Jump to :  

Note :

© Copyright – Quasar Chunawalla, 2010.
Note : The copyrights of all the material, text and pictures posted in this website belong to the author. Any instance of lifting the material from this website, shall be considered as an act of plagiarism. For any clarifications, please mail at quasar.chunawalla@gmail.com
 
back to top