Version 6.3.8 for Windows
 —  Programming Guide  —

Initial Values (and the RESET Statement)

This document describes the default initial values of user-defined variables, explains how you can assign an initial value to a user-defined variable and how you can use the RESET statement to reset the field value to its default initial value or the initial value defined for that variable in the DEFINE DATA statement.

This document covers the following topics:


Default Initial Value of a User-Defined Variable/Array

If you specify no initial value for a field, the field will be initialized with a default initial value depending on its format:

Format Default Initial Value
B, F, I, N, P 0
A, U blank
L F(ALSE)
D D' '
T T'00:00:00'
C (AD=D)
GUI Handle NULL-HANDLE
Object Handle NULL-HANDLE

Top of page

Assigning an Initial Value to a User-Defined Variable/Array

In the DEFINE DATA statement, you can assign an initial value to a user-defined variable. If the initial value is alphanumeric, it must be enclosed in apostrophes.

Assigning a Modifiable Initial Value

If the variable/array is to be assigned a modifiable initial value, you specify the initial value in angle brackets with the keyword INIT after the variable definition in the DEFINE DATA statement. The value(s) assigned will be used each time the variable/array is referenced. The value(s) assigned can be modified during program execution.

Example:

DEFINE DATA LOCAL 
1 #FIELDA (N3) INIT <100> 
1 #FIELDB (A20) INIT <'ABC'> 
END-DEFINE 
...

Assigning a Constant Initial Value

If the variable/array is to be treated as a named constant, you specify the initial value in angle brackets with the keyword CONSTANT after the variable definition in the DEFINE DATA statement. The constant value(s) assigned will be used each time the variable/array is referenced. The value(s) assigned cannot be modified during program execution.

Example:

DEFINE DATA LOCAL 
1 #FIELDA (N3) CONST <100> 
1 #FIELDB (A20) CONST <'ABC'> 
END-DEFINE 
...

Assigning a Natural System Variable as Initial Value

The initial value for a field may also be the value of a Natural system variable.

Example:

In this example, the system variable *DATX is used to provide the initial value.

DEFINE DATA LOCAL 
1 #MYDATE (D) INIT <*DATX> 
END-DEFINE 
...

Assigning Characters as Initial Value for Alphanumeric Variables

As initial value, a variable can also be filled, entirely or partially, with a specific single character or string of characters (only possible for alphanumeric variables).

Top of page

Resetting a User-Defined Variable to its Initial Value

The RESET statement is used to reset the value of a field. Two options are available:

Notes:

  1. A field declared with a CONSTANT clause in the DEFINE DATA statement may not be referenced in a RESET statement, since its content cannot be changed.
  2. In reporting mode, the RESET statement may also be used to define a variable, provided that the program contains no DEFINE DATA LOCAL statement.

Reset to Default Initial Value

RESET (without INITIAL) sets the content of each specified field to its default initial value depending on its format.

Example:

DEFINE DATA LOCAL 
1 #FIELDA (N3)  INIT <100> 
1 #FIELDB (A20) INIT <'ABC'> 
1 #FIELDC (I4)  INIT <5> 
END-DEFINE 
... 
... 
RESET #FIELDA                    /* resets field value to default initial value 
... 

Reset to Initial Value Defined in DEFINE DATA

RESET INITIAL sets each specified field to the initial value as defined for the field in the DEFINE DATA statement.

For a field declared without INIT clause in the DEFINE DATA statement, RESET INITIAL has the same effect as RESET (without INITIAL).

Example:

DEFINE DATA LOCAL 
1 #FIELDA (N3)  INIT <100> 
1 #FIELDB (A20) INIT <'ABC'> 
1 #FIELDC (I4)  INIT <5> 
END-DEFINE 
... 
RESET INITIAL #FIELDA #FIELDB #FIELDC /* resets field values to initial values as defined in DEFINE DATA
...

Top of page