000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. JACK01.
000300 ENVIRONMENT DIVISION.
000400 DATA DIVISION.
000500
000600 WORKING-STORAGE SECTION.
000700
000800 01 THE-MESSAGE PIC X(50).
000900 01 THE-NUMBER PIC 9(2).
001000
001100 PROCEDURE DIVISION.
001200 PROGRAM-BEGIN.
001300
001400* Set up and display line 1
001500 MOVE 1 TO THE-NUMBER.
001600 MOVE "Jack be nimble," TO THE-MESSAGE.
001700 DISPLAY THE-NUMBER " " THE-MESSAGE.
001800
001900* Set up and Display line 2
002000 ADD 1 TO THE-NUMBER.
002100 MOVE "Jack be quick," TO THE-MESSAGE.
002200 DISPLAY THE-NUMBER " " THE-MESSAGE.
002300
002400* Set up and display line 3
002500 ADD 1 TO THE-NUMBER.
002600 MOVE "Jack jump over the candlestick." TO THE-MESSAGE.
002700 DISPLAY THE-NUMBER " " THE-MESSAGE.
002800
002900 PROGRAM-DONE.
003000 STOP RUN.
003100
OUTPUT:
01 Jack be nimble,
02 Jack be quick,
03 Jack jump over the candlestick.
C>
C>
ANALYSIS: It is possible to use a variable as though it were a constant. In Listing 2.9, an additional variable, A-SPACE, is created. This variable is set to a value at the start of the program and then used in each message. The output of jack02.cbl should be identical to that of jack02.cbl.
New Term: Setting a variable to a starting value is called initializing.
TYPE: Listing 2.9. Another method of formatting.
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. JACK02.
000300 ENVIRONMENT DIVISION.
000400 DATA DIVISION.
000500
000600 WORKING-STORAGE SECTION.
000700
000800 01 THE-MESSAGE PIC X(50).
000900 01 THE-NUMBER PIC 9(2).
001000 01 A-SPACE PIC X.
001100
001200 PROCEDURE DIVISION.
001300 PROGRAM-BEGIN.
001400
001500* Initialize the space variable
001600 MOVE " " TO A-SPACE.
001700
001800* Set up and display line 1
001900 MOVE 1 TO THE-NUMBER.
002000 MOVE "Jack be nimble," TO THE-MESSAGE.
002100 DISPLAY THE-NUMBER A-SPACE THE-MESSAGE.
002200
002300* Set up and Display line 2
002400 ADD 1 TO THE-NUMBER.
002500 MOVE "Jack be quick," TO THE-MESSAGE.
002600 DISPLAY THE-NUMBER A-SPACE THE-MESSAGE.
002700
002800* Set up and display line 3
002900 ADD 1 TO THE-NUMBER.
003000 MOVE "Jack jump over the candlestick." TO THE-MESSAGE.
003100 DISPLAY THE-NUMBER A-SPACE THE-MESSAGE.
003200
003300 PROGRAM-DONE.
003400 STOP RUN.
003500