INITIALIZE
A COBOL statement that resets every field in a group to a default value suited to its type.
Also written INITIALIZE REPLACING
INITIALIZE sets fields back to sensible defaults in one statement. INITIALIZE WS-ACCOUNT-RECORD goes through every field in the group and sets text fields to spaces and numeric fields to zeros.
That is different from MOVE SPACES TO WS-ACCOUNT-RECORD, which fills the whole group with spaces, numeric fields included. A numeric field full of spaces is not a valid number, and using it later can cause an S0C7. INITIALIZE avoids that by treating each field according to its type.
By default, INITIALIZE does not change FILLER items, and it skips fields that redefine another field. The REPLACING phrase lets you choose different values, for example REPLACING NUMERIC DATA BY 1.
Programs commonly initialise an output record before building each new one, so nothing is left over from the previous record. For very large groups processed many times, INITIALIZE can take noticeable processor time, and some sites copy a prepared empty record instead.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- MOVEThe COBOL statement that copies a value into a field, converting it to fit the receiving field's format.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.