INITIALIZE VERB

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
mainframe5
Active Member
Posts: 59
Joined: Tue Jul 24, 2007 7:25 pm

INITIALIZE VERB

Post by mainframe5 » Fri Nov 16, 2007 5:58 pm

what is INITIALIZE VERB .give me example.

User avatar
DavidatK
Active Member
Posts: 65
Joined: Tue Mar 27, 2007 8:41 am
Location: Troy, MI USA

Post by DavidatK » Mon Nov 19, 2007 6:46 am

You can read more about the INITIALIZE Statement in the COBOL Manual

The INITAILIZE statement is used to initialize one or more variables to a pre-determined value. It is equivalent to one move statement for each variable.

Given the following code structure:

Code: Select all

01  RECORD-OUT-AREA.
    05  ACCOUNT-NUMBER       PIC S9(9) COMP-3.
    05  FILLER               PIC X.
    05  ACCOUNT-BALANCE      PIC 9,999,999.99
    05  FILLER               PIC X.
    05  NEXT-DUE-DATE.
        15  MM               PIC XX.
        15  DD               PIC XX.
        15  YYYY             PIC XXXX.
        

01  OUTPUT-RECORD-COUNT      PIC S9(9) COMP-3.

Code: Select all

(ex 1)
    INITIALIZE               RECORD-OUT-AREA.

(ex 2)
    INITIALIZE               OUTPUT-RECORD-COUNT.

(ex 3)    
    INITIALIZE               ACCOUNT-BALALNCE.
Is equivalent to:

Code: Select all


(ex 1)
    MOVE 0                   TO ACCOUNT-NUMBER.
    MOVE 0.00                TO ACCOUNT-BALANCE.
    MOVE SPACES              TO MM.
    MOVE SPACES              TO DD.
    MOVE SPACES              TO YYYY. 

(ex 2)
    MOVE 0                   TO OUTPUT-RECORD-COUNT.

(ex 3)
    MOVE 0.00                TO ACCOUNT-BALANCE.
There are issues with the INITIALIZE statement however. INITIALIZE does nothing with FILLER areas and creates a move statement for every variable.

If the OUTPUT-RECORD-AREA was a table item INITIALIZE would create a MOVE for every variable for every table subscript.

Now imagine a structure that may have hundreds or thousands of valuables in it. I think you can see that the over use of the INITIALIZE statement can have a dramatic affect on the performance of the program.

A better way to get the same results, with much better performance is to INITIALIZE the structure once at the start of you program; you should have an initialization paragraph. After doing the INITIALIZE, move the structure to a save area of the same structure, it can be all filler, as below:

Code: Select all

01  RECORD-OUT-AREA-INIT_SAVE.
    05  FILLER               PIC S9(9) COMP-3.
    05  FILLER               PIC X.
    05  FILLER               PIC 9,999,999.99
    05  FILLER               PIC X.
    05  FILLER.
        15  FILLER           PIC XX.
        15  FILLER           PIC XX.
        15  FILLER           PIC XXXX.


INITIALIZE RECORD-OUT-AREA.
MOVE RECORD-OUT-AREA  TO RECORD-OUT-AREA-INIT-SAVE.
Then, whenever you need to initialize the RECORD-OUT-AREA, simply

Code: Select all

MOVE RECORD-OUT-AREA-INIT-SAVE TO RECORD-OUT-AREA.
There are other options for the INITIALIZE Statement, but not normally used. You can read about those in the manual.

Dave

academyindia4

Topic deleted by Admin

Post by academyindia4 » Wed Jan 27, 2016 8:14 pm

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Feb 01, 2016 10:20 pm

<< Content deleted By Admin >>

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others