In this topic, we described about the below sections -
INITIALIZE sets the data items to the predefined values based on the data types. It is functionally equivalent to one or more MOVE statements.
INITIALIZE can initialize single data item or a group of data items. INITIALIZE sets the predefined values based on data types shown below in identifier-1.
If the data type is alphabetic/alphanumeric/alphanumeric-edited, those data items gets initialized with SPACES. If the data type is numeric/numeric-edited, those data items gets initialized with ZEROES.
FILLER and OCCURS DEPENDING ON items don’t get effected with INITIALIZE.
Receiving item. Must reference one of the following -
- An alphanumeric group items
- An elementary data item of one of the following categories -
- External floating-point
- Internal floating-point
A subscripted item can be specified for identifier-1. A complete table can be initialized if identifier-1 specified as a group item that contains the complete table.
Sending item. Identifier-2 must reference a valid elementary data item as a sending operand in a MOVE statement with identifier-1 as the receiving operand.
literal-1 must be a valid literal as a sending operand in a MOVE statement with identifier-1 as the receiving operand.
REPLACING phrase -
REPLACING clause is optional in INTIALIZE. REPLACING is used to replace value (other than predefined value) based on data type during the initialization.
If the REPLACING is not specified, the predefined values used to initialize the data items according to the data type. If the REPLACING phrase is specified -
- identifier-2 must be a valid category as a sending operand to the corresponding category specified in the REPLACING phrase.
- literal-1 must be a valid category as a sending operand in a MOVE statement to the corresponding category specified in the REPLACING phrase.
If the REPLACING phrase is not specified -
- SPACE is the implied sending item for receiving items of category alphabetic, alphanumeric or alphanumeric-edited.
- ZERO is the implied sending item for receiving items of category numeric or numeric-edited.
Practical Example - COPY
IDENTIFICATION DIVISION. PROGRAM-ID. SAMPCOPY. AUTHOR. MTH. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 STD-REC. COPY STDRECD. PROCEDURE DIVISION. INITIALIZE STD-REC. ACCEPT STD-NUM. ACCEPT STD-NAME. ACCEPT STD-PERCENT. DISPLAY ‘STUDENT DETAILS : ‘ STD-REC. STOP RUN.