Version 6.3.13 for Windows
 —  Programming Guide  —

Redefining Fields

Redefinition is used to change the format of a field, or to divide a single field into segments.

This document covers the following topics:


Using the REDEFINE Option of DEFINE DATA

The REDEFINE option of the DEFINE DATA statement can be used to redefine a single field - either a user-defined variable or a database field - as one or more new fields. A group can also be redefined.

Important:
Dynamic variables are not allowed in a redefinition.

The REDEFINE option redefines byte positions of a field from left to right, regardless of the format. Byte positions must match between original field and redefined field(s).

The redefinition must be specified immediately after the definition of the original field.

Example 1:

In the following example, the database field BIRTH is redefined as three new user-defined variables:

DEFINE DATA LOCAL                 
01 EMPLOY-VIEW VIEW OF STAFFDDM  
  02 NAME                        
  02 BIRTH                       
  02 REDEFINE BIRTH              
     03 #BIRTH-YEAR  (N4)          
     03 #BIRTH-MONTH (N2)         
     03 #BIRTH-DAY   (N2)           
END-DEFINE 
   ...

Example 2:

In the following example, the group #VAR2, which consists of two user-defined variables of format N and P respectively, is redefined as a variable of format A:

DEFINE DATA LOCAL                    
01 #VAR1 (A15)                  
01 #VAR2                        
  02 #VAR2A (N4.1)             
  02 #VAR2B (P6.2)             
01 REDEFINE #VAR2 
  02 #VAR2RD (A10)
END-DEFINE 
   ...

With the notation FILLER nX you can define n filler bytes - that is, segments which are not to be used - in the field that is being redefined. (The definition of trailing filler bytes is optional.)

Example 3:

In the following example, the user-defined variable #FIELD is redefined as three new user-defined variables, each of format/length A2. The FILLER notations indicate that the 3rd and 4th and 7th to 10th bytes of the original field are not be used.

DEFINE DATA LOCAL 
1 #FIELD (A12)                       
1 REDEFINE #FIELD 
  2 #RFIELD1 (A2) 
  2 FILLER 2X 
  2 #RFIELD2 (A2) 
  2 FILLER 4X 
  2 #RFIELD3 (A2) 
END-DEFINE 
...

Top of page

Example Program Illustrating the Use of a Redefinition

The following program illustrates the use of a redefinition:

** Example 'DDATAX01': DEFINE DATA
************************************************************************
DEFINE DATA LOCAL
01 VIEWEMP VIEW OF EMPLOYEES
  02 NAME
  02 FIRST-NAME
  02 SALARY   (1:1)
*
01 #PAY       (N9)
01 REDEFINE #PAY
  02 FILLER   3X
  02 #USD     (N3)
  02 #OOO     (N3)
END-DEFINE
*
READ (3) VIEWEMP BY NAME STARTING FROM 'JONES'
  MOVE SALARY (1) TO #PAY
  DISPLAY NAME FIRST-NAME #PAY #USD #OOO
END-READ
END

Output of Program DDATAX01:

Note how #PAY and the fields resulting from its definition are displayed:

Page      1                                                  04-11-11  14:15:54
 
        NAME              FIRST-NAME         #PAY    #USD #OOO
-------------------- -------------------- ---------- ---- ----
 
JONES                VIRGINIA                  46000   46    0
JONES                MARSHA                    50000   50    0
JONES                ROBERT                    31000   31    0              
            

Top of page