- 论坛徽章:
- 0
|
RPG/400 Help
OCUR (Set/Get Occurrence of a Data Structure)
*---------*---------------*-----------------*----------------*---------------*
| CODE | FACTOR 1 | FACTOR 2 | RESULT | INDICATORS |
| | | | FIELD | |
*---------*---------------*-----------------*----------------*---------------*
| OCUR | Occurrence | Data structure | Occurrence | _ ER _ |
| | value | | value | |
*---------*---------------*-----------------*----------------*---------------*
The OCUR operation code specifies the occurrence of the data structure that is to be used next within an RPG/400 program. If a data structure with multiple occurrences or a subfield of that data structure is specified in an operation, the first occurrence of the data structure is used until an OCUR operation is specified. After an OCUR operation is specified, the occurrence of the data structure that was established by the OCUR operation is used.
Factor 1 is optional; if specified, it can contain a numeric, zero decimal position literal, field name, named constant, or a data structure name. Factor 1 is used during the OCUR operation to set the occurrence of the data structure specified in factor 2. If factor 1 is blank, the value of the current occurrence of the data structure in factor 2 is placed in the result field during the OCUR operation.
If factor 1 is a data structure name, it must be a multiple occurrence data structure. The current occurrence of the data structure in factor 1 is used to set the occurrence of the data structure in factor 2.
Factor 2 is required and must be the name of a multiple occurrence data structure.
The result field is optional; if specified, it must be a numeric field name with no decimal positions. During the OCUR operation, the value of the current occurrence of the data structure specified in factor 2, after being set by any value or data structure that is optionally specified in factor 1, is placed in the result field.
You can specify a resulting indicator in positions 56 and 57 to be set on if the occurrence specified is outside the valid range set for the data structure. If the occurrence is outside the valid range, the occurrence of the data structure in factor 2 remains the same as before the OCUR operation was processed.
The OCUR operation establishes which occurrence of a multiple occurrence data structure is used next in a program. Only one occurrence can be used at a time.
Figure "Uses of the OCUR Operation" illustrates uses of the OCUR operation.
OCUR Examples
Figure 41. Uses of the OCUR Operation
*------*------* 50th *------*------*
| FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
| | | | | |
*------*------*-* 49th *------*------*-*
| FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
| | | | | |
*-------------*-* *-------------*-*
*-------------* *-------------*
*-------------* *-------------*
*-------------* *-------------*
*-------------* *-------------*
*------*------* 3rd *------*------*
| FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
| | | | | |
*------*------*-* 2nd *------*------*-*
| FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
| | | | | |
*------*------*-* 1st *------*------*-*
| FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
| | | | | |
*------*------* *------*------*
DS1 DS2
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
I....................................PFromTo++DField+L1M1FrPlMnZr...
I*
I* DS1 and DS2 are multiple occurrence data structures.
I* Each data structure has 50 occurrences.
IDS1 DS 50
I 1 5 FLDA
I 6 80FLDB
I*
IDS2 DS 50
I 1 6 FLDC
I 7 11 FLDD
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C* DS1 is set to the third occurrence. The subfields FLDA
C* and FLDB of the third occurrence can now be used. The MOVE
C* and Z-ADD operations change the contents of FLDA and FLDB,
C* respectively, in the third occurrence of DS1.
C 3 OCUR DS1
C MOVE 'ABCDE' FLDA
C Z-ADD22 FLDB
C*
C* DS1 is set to the fourth occurrence. Using the values in
C* FLDA and FLDB of the fourth occurrence of DS1, the MOVE
C* operation places the contents of FLDA in the result field,
C* FLDX, and the Z-ADD operation places the contents of FLDB
C* in the result field, FLDY.
C 4 OCUR DS1
C MOVE FLDA FLDX
C Z-ADDFLDB FLDY
C*
C* DS1 is set to the occurrence specified in field X.
C* For example, if X = 10, DS1 is set to the tenth occurrence.
C X OCUR DS1
C*
C* DS1 is set to the current occurrence of DS2. For example, if
C* the current occurrence of DS2 is the twelfth occurrence, DSI
C* is set to the twelfth occurrence.
C DS2 OCUR DS1
C*
C* The value of the current occurrence of DS1 is placed in the
C* result field, Z. Field Z must be numeric with zero decimal
C* positions. For example, if the current occurrence of DS1
C* is 15, field |
|