I find it very important to initialize first data fields that are to be used in the program to make certain that it will not contain any trash. INITIALIZE statement is like MOVE statement. It is like you are moving spaces to alphanumeric data fields and zeroes to numeric data fields. Consider the following example:
01 WS-EMPLOYEE-RECORD.
05 WS-NAME PIC X(20).
05 WS-BIRTHDAY PIC 9(8).
05 WS-ADDRESS PIC X(30).
05 WS-RATE   PIC 9(4)V99.
05 WS-HOURS PIC 9(4)99.
INITIALIZE WS-EMPLOYEE-RECORD.
The above statement will move spaces to WS-NAME and WS-ADDRESS while zeroes will be moved to WS-BIRTHDAY, WS-RATE and WS-HOURS.
Aside from INITIALIZE statement, VALUE clause and MOVE statement can also be used to initialize a data field.
If the value of a data field will not change until the end of the program, use the VALUE clause to lessen the execution time.
01 WS-RATE PIC 9(4)V99 VALUE 0100.50.
Use MOVE statement if a data field will continually change.
MOVE 12251979 TO WS-BIRTHDAY.
According to the book 'Structured COBOL First Course' by M. B. Khan, less execution time for VALUE clause for it assigns the value during compilation whereas the MOVE statement assigns it during execution time.
By experience, if I'm not moving anything to a data field using MOVE statement, VALUE clause and INITIALIZE statement it will contain LOW-VALUES.
Sunday, October 19, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment