*---------*---------------*-----------------*----------------*---------------* | CODE | FACTOR 1 | FACTOR 2 | RESULT | INDICATORS | | | | | FIELD | | *---------*---------------*-----------------*----------------*---------------* | CLEAR | *NOKEY | Structure or | | | | | | Variable | | | *---------*---------------*-----------------*----------------*---------------*
The CLEAR operation sets elements in a structure (record format, data structure, array, or table) or a variable (field, subfield, or indicator), to zero, blank or '0', depending on field type (numeric, character, or indicator). It allows you to clear structures on a global basis, as well as element by element, during run time.
Factor 1 must be blank unless factor 2 contains a DISK record format name; in which case, it can contain *NOKEY to indicate that all fields except key fields are to be cleared.
Factor 2 contains the structure or variable that is set to zero, blank, or '0'. It can contain: a record-format name, data-structure name, array name, table name, field name, subfield, array element, or indicator name. If you specify a record-format name or data structure, all fields are cleared in the order they are defined within the structure. If you have partially overlapping fields of different definitions, data that is not valid could exist in numeric fields. With a multiple-occurrence data structure, only those fields in the current occurrence are cleared. If you specify a table name, the current table element is cleared; if an array name, the entire array is cleared. If you specify an array element (including indicators) in factor 2 using an array index, only the element specified is cleared.
Note that when the CLEAR operation is applied to a record-format name, only output fields in the record format are affected. For WORKSTN file record formats, only fields with a usage of output or both are affected. All field-conditioning indicators are affect by this operation. Fields in DISK, SEQ, or PRINTER file record formats are affected only if those record formats are output in the program. Input-only fields are not affected by the CLEAR operation. By definition, they assume new values at the next input operation.
For more information see "Initialization" in chapter 9 of the RPG/400* User's Guide.
Figure "CLEAR Operation" shows an example of the CLEAR operation.
*...1....+....2....+....3....+....4....+....5....+....6....+....7... I....................................PFromTo++DField+L1M1FrPlMnZr... I* I* In the following example, CLEAR sets all subfields in the data I* structure DS1 to their defaults, CHAR to blank, NUM to zero. IDS1 DS I 2 50NUM I 20 30 CHAR *...1....+....2....+....3....+....4....+....5....+....6....+....7... CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++ C* C CLEARDS1
Figure 21. Field Initialization for the CLEAR Record Format
*...1....+....2....+....3....+....4....+....5....+....6....+....7... A* FLD1 and FLD2 are defined as output fields and can be A* affected by the CLEAR operation. Indicator 10 can also be A* changed by the CLEAR operation even though it conditions an A* input only field because field indicators are all treated A* as output fields. A* AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions++++++++++++++++++++* A R FMT01 A 10 FLD1 10A I 2 30 A FLD2 10A O 3 30 A FLD3 10A B 4 30 *...1....+....2....+....3....+....4....+....5....+....6....+....7... FFilenameIPEAF....RlenLK1AIOvKlocEDevice+......KExit++Entry+A....U1. FWORKSTN CF E WORKSTN *...1....+....2....+....3....+....4....+....5....+....6....+....7... I..............Namedconstant+++++++++C.........Fldnme......... .... I 'INPUT DATA' C IN *...1....+....2....+....3....+....4....+....5....+....6....+....7... CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++ C CLEARFMT01 C WRITEFMT01 C* C* The program will loop until PF03 is pressed. C* C *IN03 DOWEQ'0' C READ FMT01 LR C* C* PF04 will transfer input fields to output fields. C* C *IN04 IFEQ '1' C MOVELFLD003 FLD002 C MOVELFLD001 FLD003 C CLEAR*IN04 C ENDIF C MOVELIN FLD001 C* C* When PF11 is pressed, all the fields in the record format C* defined as output or both will be reset to the values they C* held after the initialization step. C* C *IN11 IFEQ '1' C RESETFMT01 C CLEAR*IN11 C ENDIF C* When PF12 is pressed, all the fields in the record C* format defined as output or both will be cleared. C* C *IN12 IFEQ '1' C CLEARFMT01 C CLEAR*IN12 C ENDIF C N03 WRITEFMT01 C ENDDO C SETON LR
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.