Handling Redefine Statements
What is a REDEFINES Statement?
In COBOL, the REDEFINES statement is used to define a storage area with multiple data descriptions. When certain data items are not used simultaneously, the same storage area can be repurposed for another data item. This allows the same storage area to be referenced with different data structures. Here's an example:
01 EMPLOYEE-RECORD.
05 DATA-TYPE-INDICATOR PIC X(01).
* Values:'R' for RAW , 'N' for Name, 'D' for Details
05 EMPLOYEE-RAW PIC X(50).
05 EMPLOYEE-NAME REDEFINES EMPLOYEE-RAW.
10 FIRST-NAME PIC X(20).
10 LAST-NAME PIC X(30).
05 EMPLOYEE-DETAILS REDEFINES EMPLOYEE-RAW.
10 EMP-ID PIC X(10).
10 EMP-DEPT PIC X(10).
10 EMP-SALARY PIC X(30).
Explanation:
In this example, EMPLOYEE-RAW
is a 50-byte storage area that can be interpreted in three different ways:
- EMPLOYEE-RAW: A 50-byte character string representing the employee (default field).
- EMPLOYEE-NAME: A 50-byte structure split into two subfields:
FIRST-NAME
(20 bytes).LAST-NAME
(30 bytes).
- EMPLOYEE-DETAILS: A 50-byte structure split into three subfields:
EMP-ID
(10 bytes).EMP-DEPT
(10 bytes).EMP-SALARY
(30 bytes).
Two Ways to Handle REDEFINES Fields in Assets
-
Locking as an Asset Variant
Choose one of the REDEFINES options and lock it as a predefined variant of the asset. -
Dynamic Handling via Indicator Field
If the COBOL program includes an indicator field (e.g.,DATA-TYPE-INDICATOR
), users can configure a dynamic REDEFINES field. This involves specifying runtime conditions to determine which REDEFINES option should be used to serialize the field.
Updated 3 months ago