RPG/400 Help

DEFN (Field Definition)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| DEFN    | *LIKE         | Referenced      | Defined        |               |
|         |               | field           | field          |               |
*---------*---------------*-----------------*----------------*---------------*
| DEFN    | *NAMVAR       | Internal        | External       |               |
|         |               | program area    | data area      |               |
*---------*---------------*-----------------*----------------*---------------*

Depending on the factor 1 entry, the declarative DEFN operation can do either of the following:

You can specify the DEFN operation anywhere within calculations. The control level entry (positions 7 and 8) can be blank or can contain an L1 through L9 indicator, the LR indicator, or an L0 entry to group the statement within the appropriate section of the program. The control level entry is used for documentation only. Conditioning indicator entries (positions 9 through 17) are not permitted. See *LIKE DEFN and *NAMVAR DEFN.

See Figure "DEFN Operation" for examples of the DEFN operation.

*LIKE DEFN

The DEFN (Field Definition) operation with *LIKE in factor 1 defines a field based upon the attributes (length and decimal positions) of another field.

Factor 2 must contain the name of the field being referenced, and the result field must contain the name of the field being defined. The field specified in factor 2, which can be defined in the program or externally, provides the attributes for the field being defined. Factor 2 cannot be a literal or a named constant. If factor 2 is an array, an array element, or a table name, the attributes of an element of the array or table are used to define the field. The result field cannot be an array, an array element, a data structure, or a table name.

You can use positions 49 through 51 (field length) to make the result field entry longer or shorter than the factor 2 entry. A plus sign (+) in position 49 indicates a length increase; a minus sign (-) in position 49 indicates a length decrease. Positions 50 and 51 can contain the increase or decrease in length (right-adjusted) or can be blank. If positions 49 through 51 are blank, the result field entry is defined with the same length as the factor 2 entry. You cannot change the number of decimal positions for the field being defined.

See Figure "DEFN Operation" for examples of *LIKE DEFN.

*NAMVAR DEFN

The DEFN (Field Definition) operation with *NAMVAR in factor 1 associates a field, a data structure, a data-structure subfield, or a data-area data structure (within your RPG/400 program) with an AS/400 data area (outside your RPG/400 program).

In factor 2, specify the external name of a data area. Use *LDA for the name of the local data area or use *PDA for the Program Initialization Parameters (PIP) data area. If you leave factor 2 blank, the result field entry is both the RPG/400 name and the external name of the data area.

In the result field, specify the name of one of the following that you have defined in your program: a field, a data structure, a data structure subfield, or a data-area data structure. You use this name with the IN and OUT operations to retrieve data from and write data to the data area specified in factor 2. When you specify a data-area data structure in the result field, the RPG/400 program implicitly retrieves data from the data area at program start and writes data to the data area when the program ends.

The result field entry must not be the name of a file, a program-status data structure, a file-information data structure (INFDS), a multiple-occurrence data structure, an input record field, an array, an array element, or a table. It cannot be the name of a subfield of a multiple-occurrence data structure, of a data area data structure, of a program-status data structure, of a file-information data structure (INFDS), or of a data structure that appears on a *NAMVAR DEFN statement.

In positions 49 through 52, you can define the length and number of decimal positions for the entry in the result field. These specifications must match those for the external description of the data area specified in factor 2. The local data area is character data of length 1024, but within your program you can access the local data area as if it has a length of 1024 or less.

See Figure "DEFN Operation" for examples of the *NAMVAR DEFN statement.

DEFN Examples

Figure 24. DEFN Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
*
C*  FLDA is a 7-position character field.
C*  FLDB is a 5-digit field with 2 decimal positions.
C*
C*
C*  FLDP is a 7-position character field.
C           *LIKE     DEFN FLDA      FLDP
C*
C*  FLDQ is a 9-position character field.
C           *LIKE     DEFN FLDA      FLDQ  + 2
C*
C*  FLDR is a 6-position character field.
C           *LIKE     DEFN FLDA      FLDR  - 1
C*
C*  FLDS is a 5-position numeric field with 2 decimal positions.
C           *LIKE     DEFN FLDB      FLDS
C*
C*  FLDT is a 6-position numeric field with 2 decimal positions.
C           *LIKE     DEFN FLDB      FLDT  + 1
C*
C*  FLDU is a 3-position numeric field with 2 decimal positions.
C           *LIKE     DEFN FLDB      FLDU  - 2
C*
C*  FLDX is a 3-position numeric field with 2 decimal positions.
C           *LIKE     DEFN FLDU      FLDX
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  If specified, the attributes (length and decimal positions) of
C*  the data area (TOTGRS) must be the same as those for the
C*  external data area.
C           *NAMVAR   DEFN           TOTGRS 102
C*
C*  The result field entry (TOTNET) is the name of the data area to
C*  be used within the RPG/400 program.  The factor 2 entry (TOTAL)
C*  is the name of the data area as defined to the system.
C           *NAMVAR   DEFN TOTAL     TOTNET
C*
C*  The result field entry (SAVTOT) is the name of the data area to
C*  be used within the RPG/400 program.  The factor 2 entry (*LDA)
C*  indicates the use of the local data area.
C           *NAMVAR   DEFN *LDA      SAVTOT


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