REDEFINES Clause

An item with REDEFINES clause uses the same storage as the item it redefines. For example:

01 ROOT. 
	 02 A PIC X. 
	 02 B PIC S9 REDEFINES A. 
	 

Item A and B use the same storage area. Depending on the application logic, either text item A or zoned item B may be present.

The Connector supports the REDEFINES clause. In the JSON schema, both A and B are present, but only one of the properties can be present at a time.

The behavior of Parse is affected by the @controlField, @controlValues, and @defaultRedefine annotations.

The behavior of Render is driven by the input mapping and @defaultRedefine when no mappings are established. Only one of the redefined items can be mapped at a time. In the given example either A or B can be mapped. If both are mapped, Render raise an error.

If A mapped, Render generate a PIC X value and if B is mapped, Render generates a zoned PIC S9 value.

@controlField:{item name} and @controlValues

This annotation is used by Parse to generate one of the redefined items based on a value of another item called control field. You can specify a set of values that causes a particular redefined item to be read and returned. For example:

01 ROOT.
    02 C PIC X.
*    @controlField: C
*    @controlValues: "A"; "1"
	02 A PIC X.
*    @controlValues: "B"; "2"
	02 B PIC S9 REDEFINES A.

When C contains values A or 1 Parse reads a PIC X item A and return property A in the output.

When C contains values B or 2 Parse reads a PIC S9 item B and return property B in the output.

A control field can be specified as a relative name, for example C. Or it can be specified as a qualified name that includes parent items, such as ROOT.C. In case of a multilayer hierarchy, some group items may be removed if the specification is not ambiguous. For example:

01 ROOT.
    02 ROOT2.
        03 C PIC X.
* @controlField: ROOT.ROOT2.C
	02 A PIC X.
	02 B PIC S9 REDEFINES A.

Here the control field is fully qualified.

01 ROOT.
    02 ROOT2.
        03 C PIC X.
* @controlField: ROOT.C
	02 A PIC X.
	02 B PIC S9 REDEFINES A.

In the above, ROOT2 is omitted but this is still a valid specification because there is only one C in the hierarchy of ROOT.

01 ROOT.
    02 C PIC X.
    02 ROOT2.
        03 C PIC X.
* @controlField: ROOT.C
	02 A PIC X.
	02 B PIC S9 REDEFINES A.

ROOT.C is ambiguous because there are two items named C in the ROOT hierarchy. Connector ignores @controlField in this case.

Control values can be specified in several formats. For more information, see Control Values.

@defaultRedefine

This annotation designates an item as a default. It affects the following:

  • If no control field is specified or a value of a control field is not on the values specified in @controlValues, Parse reads and returns this item. Only one of the redefined items can have a @defaultRedefine annotation. For example:
    01 ROOT.
        02 C PIC X.
    *    @controlField:C
    *    @controlValues: "A"; "1"
    *   @defaultRedefine
    	02 A PIC X.
    *    @controlValues: "B"; "2"
    *   @defaultRedefine
    	02 B PIC S9 REDEFINES A.
    

    @defaultRedefine before the item B is ignored because A was already designated as default.

  • If neither A or B are mapped to the input of Render, it initializes the area according to the rules of the format of the default item.
  • If @defaultRedefine is not specified on any of the items, the first item in the REDEFINE group is considered to be a default.