RPG/400 Help

RESET (Reset)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| RESET   | *NOKEY        | Structure or    |                |               |
|         |               | Variable        |                |               |
*---------*---------------*-----------------*----------------*---------------*

The RESET operation sets elements in a structure (record format, data structure, array, or table), or a variable (field, subfield, or indicator) to its initial value. The initial value for a variable is the value the variable had at the end of the *INIT operation of the program. This value can be set using data structure initialization, or you can use the initialization subroutine to assign an initial value to the structure or variable. When RESET is specified for a structure or variable, a snapshot of the initial value of that variable or structure is taken at the end of the *INIT operation after *INZSR (initialization subroutine) is processed. This value is then used to reset the structure or variable.

Factor 1 must be blank unless factor 2 contains a record format name. In this case, factor 1 can contain *NOKEY, which indicates that all fields except key fields are to be reset to their initial values.

Factor 2 contains the structure or variable to be reset to its initial value. It can contain one of: a record format, data structure name, array name, table name, field name, subfield, array element, or indicator name. If a record format name or a single occurrence data structure is specified, all fields are reset (in the order they are declared within the structure). In the case of a multiple-occurrence data structure, all fields in the current occurrence are reset. If a table name is specified, the current table element is reset; in the case of an array name, the entire array is reset. If an array element (including indicators) is specified in factor 2 using an array index, only the element specified is reset.

When the RESET operation is applied to a record format name, only those fields that are output in that record format are affected. For WORKSTN (positions 40-46) file record formats, only those fields with a usage of output or both are affected. All field-conditioning indicators are affected by the operation. Fields in DISK, SEQ, or PRINTER file record formats are affected only if the record format is output in the program. Input-only fields are not affected by the RESET operation. By definition, they assume new values at the next input operation.

The RESET operation is used in conjunction with data structure initialization and the initialization subroutine (*INZSR). You can use both data structure initialization and the *INZSR to set the initial value of a field or structure. The value is then used to reset the field or structure if it appears in factor 2 of a RESET operation. For example, you can use the *INZSR to set the values of several fields in a record format, and then later in the program use the RESET operation against the record format to reset the values of the fields. The snapshot of the field value for the RESET operation is taken at the end of the initialization step in the program, after the *INZSR is run. Any changes made to the values of variables in the *INZSR override any data structure initialization, and the value the variable has at the end of the initialization step is used to save the reset snapshot.

This operation results in an increase in the amount of storage required by the program because the initial values of all structures and variables that are reset must be saved. However, the amount of storage declared is reduced where possible. For example, if a data structure is reset and a subfield within that data structure is also reset, the save area for the subfield is based on the same storage as the data structure save area. Note that, if a single occurrence of a multiple-occurrence data structure is reset, a save area for the entire data structure (all occurrences) is declared. A save area is created for a structure or variable only if it appears in factor 2 of a RESET operation. If no RESET operations are coded in the program, then no additional storage is required. If a RESET occurs during the initialization routine of the program, an error message will be issued at run time. If a GOTO or CABxx is used to leave subroutine calculations during processing of the *INZSR, or if control passes to another part of the cycle as the result of error processing, the part of the initialization step which initializes the save areas will never be reached. In this case, an error message will be issued for all RESET operations in the program at run time.

Figure "RESET Operation" shows an example of the RESET operation.

RESET Example

Figure 49. RESET Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
FFilenameIPEAF....RlenLK1AIOvKlocEDevice+......KExit++Entry+A....U..
FEXTFILE O   E                    DISK
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
I..............Namedconstant+++++++++C.........Fldnme.............
I*
I* The file EXTFILE contains one record format RECFMT containing
I* the character fields CHAR1 and CHAR2 and the numeric fields
I* NUM1 and NUM2.
IDS1        IDS
I I            'MONDAY'                  1   8 DAY1
I I            'THURSDAY'                9  16 DAY2
I                                       17  22 JDATE
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C* The following operation blank DAY1, DAY2, and JDATE.
C                     CLEARDS1
C* The following operation will set DAY1, DAY2, and JDATE to their
C* initial values of 'MONDAY', 'THURSDAY', and UDATE respectively.
C* The initial value of UDATE for JDATE is set in the *INZSR.
C                     RESETDS1
C* The following operation will set CHAR1 and CHAR2 to blanks and
C* NUM1 and NUM2 to zero.
C                     CLEARRECFMT
C* The following operation will set CHAR1, CHAR2, NUM1, and
C* NUM2 to their initial values of 'NAME', 'ADDRESS', 1, and 2
C* respectively. These initial values are set in the *INZSR.
C*
C                     RESETRECFMT
C*
C           *INZSR    BEGSR
C                     MOVELUDATE     JDATE
C                     MOVEL'NAME    'CHAR1
C                     MOVEL'ADDRESS 'CHAR2
C                     Z-ADD1         NUM1
C                     Z-ADD2         NUM2
C                     ENDSR


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