Examples

Hello World Program:

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.     HELLOWORLD.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
100600     STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800     EXIT.

Longer Sample Program:

This program takes in records of salesperson performance data and writes it to an output file in the format: ID number, name, sales (in dollars), and product returns (in dollars).

Sample output:

0005      BENNETT ROBERT           1,600.35         12.50
0016      LOCK ANDREW S              357.72         79.85
0080      PARKER JAMES E          18,200.00        165.00
0401      REDDING OLIVIA          16,123.99      2,301.75
1375      BENTON ALEX J            3,250.00         56.50
1442      ADAMS JUNE R             4,635.21        125.16
1842      COLE ROBERT N           14,285.14      6,385.29

000100 ID DIVISION.
000200 PROGRAM-ID.  SLS02.
000300 FILE-CONTROL.
000400     SELECT SALESPERSON-FILE
000500         ASSIGN TO DISK.
000600     SELECT REPORT-FILE
000700         ASSIGN TO PRINTER.
000800 DATA DIVISION.
000900 FILE SECTION.
001000 FD  SALESPERSON-FILE.
001100 01  SALESPERSON-RECORD.
001200     05  FILLER              PIC XX.
001300     05  SP-NUMBER           PIC X(4).
001400     05  SP-NAME             PIC X(18).
001500     05  FILLER              PIC X(21).
001600     05  SP-CURRENT-SALES    PIC 9(5)V99.
001700     05  SP-CURRENT-RETURNS  PIC 9(4)V99.
001800 FD  REPORT-FILE.
001900 01  REPORT-RECORD.
002000     05  FILLER              PIC X(10).
002100     05  RT-NUMBER           PIC X(4).
002200     05  FILLER              PIC X(6).
002300     05  RT-NAME             PIC X(18).
002400     05  FILLER              PIC X(6).
002500     05  RT-CURRENT-SALES    PIC ZZ,ZZZ.99.
002600     05  FILLER              PIC X(6).
002700     05  RT-CURRENT-RETURNS  PIC Z,ZZZ.99.
002800     05  FILLER              PIC X(65).
002900 WORKING-STORAGE SECTION.
003000 01  WS-EOF-FLAG             PIC X.
003100*
003200 PROCEDURE DIVISION.
003300*
003400 MAIN-ROUTINE.
003500     OPEN INPUT SALESPERSON-FILE
003600         OUTPUT REPORT-FILE
003700     MOVE "N" TO WS-EOF-FLAG
003800     READ SALESPERSON-FILE
003900         AT END MOVE "Y" TO WS-EOF-FLAG
004000     END-READ
004100*
004200 PERFORM UNTIL WS-EOF-FLAG IS EQUAL TO "Y"
004300     MOVE SPACES TO REPORT-RECORD
004400     MOVE SP-NUMBER TO RT-NUMBER
004500     MOVE SP-NAME TO RT-NAME
004600     MOVE SP-CURRENT-SALES TO RT-CURRENT-SALES
004700     MOVE SP-CURRENT-RETURNS TO RT-CURRENT-RETURNS
004800     WRITE REPORT-RECORD
004900     READ SALESPERSON-FILE
005000         AT END MOVE "Y" TO WS-EOF-FLAG
005100     END-READ
005200 END-PERFORM
005300*
005400 CLOSE SALESPERSON-FILE, REPORT-FILE
005500 STOP RUN.
Comments