REDEFINE
|
|
operand1 ( |
|
nX
|
|
) |
|
| operand2 |
This document covers the following topics:
For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.
Belongs to Function Group: Reporting Mode Statements
The REDEFINE statement is used to redefine a field. The resulting definition
may consist of one or more user-defined variables.
With one REDEFINE statement, several fields may be redefined.
The REDEFINE statement is only valid in reporting mode. To redefine a field
in structured mode, use the REDEFINE clause of the DEFINE DATA statement.
Operand Definition Table:
| Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
S | A | G | A | U | N | P | I | F | B | D | T | L | C | yes | no | ||||
operand2
|
S | A | G | A | N | P | I | F | B | D | T | L | C | yes | yes | |||||
Syntax Element Description:
| Syntax Element | Description |
|---|---|
REDEFINE
operand1
operand2 |
Method of Redefinition:
The byte positions of The format of Further Redefinition:
Fields defined using a |
nX |
Filler Notation:
The |
The user-defined variable #A (format/length A10) contains the value
123ABCDEFG.
REDEFINE #A (#A1(N3) #A2(A7))
The value in #A1 is 123. The value in #A2 is
ABCDEFG.
The user-defined variable #B (format/length A10) contains the value (shown
in hexadecimal format) 12345CC1C2C3C4C5C6C7.
REDEFINE #B (#B1(P4) #B2(A7))
The value in #B1 is 12345C (in hexadecimal format).
The value in #B2 is C1C2C3C4C5C6C7 (in hexadecimal
format).
REDEFINE #B (#BB1(B2)8X)) or REDEFINE #B(#BB1(B2))
The value in #BB1 is 1234 (in hexadecimal format).
Note
For packed data (Format P), the number of decimal positions required must be
specified. The following formula can be used to determine the number of bytes that the
packed number occupies:
Number of bytes = (number of decimal positions + 1) / 2, rounded upwards
to full bytes.
COMPUTE #V (N8.2) = #Y (N10) = ... REDEFINE #V (3X #A(N3) 2X #P (N2)) #Y (#B(N3) 7X)

This example redefines the value of the system variable *DATN, which is in the form
YYYYMMDD, and displays the result as three separate fields in the order
day/month/year:
MOVE *DATN TO #DATINT (N8) REDEFINE #DATINT (#YEAR (N4) #MONTH (N2) #DAY (N2)) DISPLAY NOTITLE #DATINT #DAY #MONTH #YEAR END
#DATINT #DAY #MONTH #YEAR
--------- ---- ------ -----
20140326 26 3 2014
When an alphanumeric field containing characters and numeric values is redefined as
numeric, accessing a value that is not valid for the numeric format may cause an
abnormal termination. If you need to check for a numeric value in an alphanumeric field,
it is recommended that you use the IS option. The numeric value can then be obtained using the
VAL function.
For example:
DEFINE DATA LOCAL 1 #A (A4) 1 REDEFINE #A 2 #N(N4) END-DEFINE #A := '-123' IF #A IS (N4) THEN /* check if #A can be converted to numeric format #N := VAL(#A) /* get the numeric value WRITE "TRUE" ELSE WRITE "FALSE" / * #A contains non-numeric characters and cannot be converted. END-IF END
In the above example, #A contains the character value '-123'.
Although #A is defined as an alphanumeric field, the IS (N4)
condition checks whether its content can be interpreted as a numeric value. Since
'-123' is a valid numeric value, the condition is true, and
VAL(#A) can be used to obtain its numeric value in #N.
IF #N = -123 ... END-IF
The above example demonstrates that an access to a numeric defined field which contains
non-numeric characters can cause an abnormal behavior. Therefore, the IS
and VAL functions are recommended when accessing a redefined numeric
field.