In RPG, you can use the CLEAR operation to clear all fields in a record format. However, this works only if the file is opened for output, update, or input with add (A in column 66). If the file is opened for input only, you can use the CLEAR operation against the file's record format, but it won't do anything.
I found a way to use the CLEAR operation to clear all the fields in a record format even when the file is opened for input only. You'll find an example of this technique in 7. The trick is to define an externally described data structure using the name of the file that contains the fields you want to clear, then use the CLEAR operation on the data structure name. This technique can be useful when you want to clear all fields in a file after an unsuccessful CHAIN operation.
I found a way to use the CLEAR operation to clear all the fields in a record format even when the file is opened for input only. You'll find an example of this technique in Figure 7. The trick is to define an externally described data structure using the name of the file that contains the fields you want to clear, then use the CLEAR operation on the data structure name. This technique can be useful when you want to clear all fields in a file after an unsuccessful CHAIN operation.
In the example code, you can see that the file IIML01 has been defined as input only. An externally described data structure called IIMDS has also been defined using the IIML01 file. In the C-specs, the program CHAINs to the IIML01 file. If a record is not found, the program uses the CLEAR operation against the IIMDS data structure. This clears all of the fields in the IIML01 file even though the file was opened for input only.
- Andrew Nortje
TechTalk: Use the CLEAR operation against files opened for input.
Figure 7: Using CLEAR with an Input File
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FIIML01 IF E K DISK * IIIMDS E DSIIML01 * * Get IIML01 record C PROD CHAINIIML01 99 * * If not found then clear all fields C *IN99 IFEQ *ON C CLEARIIMDS C ENDIF
LATEST COMMENTS
MC Press Online