- Mainframes360.com shall be shortly migrated to ASP .NET, and shall feature a new Message Forum
- The new and amazing Mainframes360 logo was contributed by Prashant from Chennai, India
- Lots more tutorials on COBOL - Table Handling and File Handling
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
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.
0 comments:
Post a Comment