Variable Initialization

You can initialize data with the INZ{(initial value)} keyword on the definition specification. Specify an initial value as a parameter on the INZ keyword, or specify the keyword without a parameter and use the default initial values. If the initialization is too complicated to express using the INZ keyword, you can further initialize data in the initialization subroutine.

Default initial values for the various data types are described in Chapter 9. Data Types and Data Formats. See Chapter 8. Using Arrays and Tables for information on initializing arrays.

To reinitialize data while the program is running, use the CLEAR and RESET operations.

The CLEAR operation code sets a record format or variable (field, subfield, indicator, data structure, array, or table) to its default value. All fields in a record format, data structure, or array are cleared in the order in which they are declared.

The RESET operation code restores a variable to its reset value. The reset value for a global variable is the value it had at the end of the initialization step in the RPG IV cycle, after the initialization subroutine has been invoked.

You can use the initialization subroutine to assign initial values to a global variable and then later use RESET to set the variable back to this value. This applies only to the initialization subroutine when it is run automatically as a part of the initialization step.

For local variables the reset value is the value of the variable when the subprocedure was first called, but before the calculations begin.



[ Top of Page | Previous Page | Next Page | Contents | Index ]