COBOL Initialize

COBOL Go Back COBOL Inspect Statement

Advertisements


INITIALIZE sets the data items to the predefined values based on the data types.

INITIALIZE can initialize single data item or a group of data items.

INITIALIZE set the predefined values based on data types like below.

If the data type is alphabetic/alphanumeric/alphanumeric-edited, those data items will be initialized with SPACES.

If the data type is numeric/numeric-edited, those data items will be initialized with ZEROES.

During the INITIALIZE, FILLER and OCCURS DEPENDING ON items will not be effected.


Syntax:

INITIALIZE identifier-1
[REPLACING {ALPHABETIC/ALPHANUMERIC/NUMERIC}	
	DATA BY identifier-2.

REPLACING clause is optional in INTIALIZE.

REPLACING is used to replace particular value(other than predefined value) based on data type during the initialization.


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.

COBOL Go Back COBOL Inspect Statement

Advertisements