Thursday, 14 August 2014

COBOL REDEFINE Clause | REDEFINE in COBOL Example and rules.

COBOL
COBOL REDEFINE Tutorial
Another important statement/feature of COBOL in REDEFINES clause. The Redefines clause lets you define a field in storage in two or more ways. 

When used, this clause must have the same level number as the data item it is redefining and it must come right after that item.

The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.   

Always remember, the definition and the redefinition both refer to the same bytes of storage, you can code a Value clause only on the original definition. 
Syntax : 
01-49  data-name-1 REDEFINES data-name-2

Example 1: A Redefines clause that redefines a date field

Add a note hereAdd a note here05  WS-TDY-DTE       PIC 9(08).
05  WS-TDY-DTE-X     REDEFINES WS-TDY-DTE.
    10  TDY-YR       PIC 9(04).
    10  TDY-MNTH     PIC 9(02).
    10  TDY-DAY      PIC 9(02).

Example 2 : A Redefines clause that redefines a print field

Add a note hereAdd a note here05  WS-CHG-PERNT     PIC ZZ9.9-.
05  WS-CHG-PERNT-X   REDEFINES WS-CHG-PERNT
                     PIC X(6).

Example 3 : A Redefines clause that redefines alphanumeric with numeric.

     05  WS-EMP-REC       PIC X(20).
  05  WS-SAL-AMT       REDEFINES     WS-EMP-REC.
      10 WS-EMP-SALE   PIC 9(05)v99. 
      10 WS-EMP-TAX    PIC 9(02)v99. 

Rule : 
  1. Level number, data-name-1, and FILLER are not part of the REDEFINES clause itself and are included in the format only for clarity.
  2. Level-numbers of data-name-1 and data-name-2 must be identical and must not be level 66 or level 88.
  3. Data-name-1, FILLER identifies an alternate description for the same area and is the redefining item or the REDEFINES subject.
  4. Data description entry for the redefined item cannot contain an OCCURS clause.
  5. More than one redefinition of the same storage area is permitted. The entries giving the new descriptions of the storage area must immediately follow the description of the redefined area without intervening entries that define new character positions.
  6. Multiple redefinitions must all use the data-name of the original entry that defined this storage area.
  7. Redefining entry (identified by data-name-1) and any subordinate entries, must not contain any VALUE clauses.

START CLAUSE EXAMPLE

Have a look of COBOL Start Statement?



No comments:

Post a Comment