A compiler for cobol.



Example Program
  1. IDENTIFICATION DIVISION.
  2. PROGRAM-ID. PRODUCE-REORDER-LISTING.
  3. ENVIRONMENT DIVISION.
  4. CONFIGURATION SECTION.
  5. SOURCE-COMPUTER. DEC-VAX.
  6. OBJECT-COMPUTER. DEC-VAX.
  7. INPUT-OUTPUT SECTION.
  8. FILE-CONTROL.
  9. SELECT BAL-FWD-FILE ASSIGN TO READER.
  10. SELECT REORDER-LISTING ASSIGN TO LOCAL-PRINTER.
  11. DATA DIVISION.
  12. FILE SECTION.
  13. FD BAL-FWD-FILE
  14. LABEL RECORDS ARE STANDARD
  15. RECORD CONTAINS 80 CHARACTERS.
  16. 01 BAL-FWD-CARD.
  17. 02 BAL-ITEM-NO PICTURE IS 9(5).
  18. 02 BAL-ITEM-DESC PICTURE IS X(20).
  19. 02 FILLER PICTURE IS X(5).
  20. 02 BAL-UNIT-PRICE PICTURE IS 999V99.
  21. 02 BAL-REORDER-POINT PICTURE IS 9(5).
  22. 02 BAL-ON-HAND PICTURE IS 9(5).
  23. 02 BAL-ON-ORDER PICTURE IS 9(5).
  24. 02 FILLER PICTURE IS X(30).
  25. FD REORDER-LISTING
  26. LABEL RECORDS ARE STANDARD
  27. RECORD CONTAINS 132 CHARACTERS.
  28. 01 REORDER-LINE.
  29. 2.6 Computerizing Business Records: COBOL 6162 Chapter 2 Evolution of the Major Programming Languages
  30. 02 RL-ITEM-NO PICTURE IS Z(5).
  31. 02 FILLER PICTURE IS X(5).
  32. 02 RL-ITEM-DESC PICTURE IS X(20).
  33. 02 FILLER PICTURE IS X(5).
  34. 02 RL-UNIT-PRICE PICTURE IS ZZZ.99.
  35. 02 FILLER PICTURE IS X(5).
  36. 02 RL-AVAILABLE-STOCK PICTURE IS Z(5).
  37. 02 FILLER PICTURE IS X(5).
  38. 02 RL-REORDER-POINT PICTURE IS Z(5).
  39. 02 FILLER PICTURE IS X(71).
  40. WORKING-STORAGE SECTION.
  41. 01 SWITCHES.
  42. 02 CARD-EOF-SWITCH PICTURE IS X.
  43. 01 WORK-FIELDS.
  44. 02 AVAILABLE-STOCK PICTURE IS 9(5).
  45. PROCEDURE DIVISION.
  46. 000-PRODUCE-REORDER-LISTING.
  47. OPEN INPUT BAL-FWD-FILE.
  48. OPEN OUTPUT REORDER-LISTING.
  49. MOVE "N" TO CARD-EOF-SWITCH.
  50. PERFORM 100-PRODUCE-REORDER-LINE
  51. UNTIL CARD-EOF-SWITCH IS EQUAL TO "Y".
  52. CLOSE BAL-FWD-FILE.
  53. CLOSE REORDER-LISTING.
  54. STOP RUN.
  55. 100-PRODUCE-REORDER-LINE.
  56. PERFORM 110-READ-INVENTORY-RECORD.
  57. IF CARD-EOF-SWITCH IS NOT EQUAL TO "Y"]
  58. PERFORM 120-CALCULATE-AVAILABLE-STOCK
  59. IF AVAILABLE-STOCK IS LESS THAN BAL-REORDER-POINT
  60. PERFORM 130-PRINT-REORDER-LINE.
  61. 110-READ-INVENTORY-RECORD.
  62. READ BAL-FWD-FILE RECORD
  63. AT END
  64. MOVE "Y" TO CARD-EOF-SWITCH.
  65. 120-CALCULATE-AVAILABLE-STOCK.
  66. ADD BAL-ON-HAND BAL-ON-ORDER
  67. GIVING AVAILABLE-STOCK.
  68. 130-PRINT-REORDER-LINE.
  69. MOVE SPACE TO REORDER-LINE. MOVE BAL-ITEM-NO TO RL-ITEM-NO.
  70. MOVE BAL-ITEM-DESC TO RL-ITEM-DESC.
  71. MOVE BAL-UNIT-PRICE TO RL-UNIT-PRICE.
  72. MOVE AVAILABLE-STOCK TO RL-AVAILABLE-STOCK.
  73. MOVE BAL-REORDER-POINT TO RL-REORDER-POINT.
  74. WRITE REORDER-LINE.


Readability Example

"By the numbers"

  1. $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-If.
  2. AUTHOR. Michael Coughlan.
  3. DATA DIVISION.
  4. WORKING-STORAGE SECTION.
  5. 01 Num1 PIC 9 VALUE ZEROS.
  6. 01 Num2 PIC 9 VALUE ZEROS.
  7. 01 Result PIC 99 VALUE ZEROS.
  8. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator.
  9. PERFORM 3 TIMES DISPLAY "Enter First Number : " WITH NO ADVANCING
  10. ACCEPT Num1
  11. DISPLAY "Enter Second Number : " WITH NO ADVANCING ACCEPT Num2
  12. DISPLAY "Enter operator (+ or *) : " WITH NO ADVANCING ACCEPT Operator
  13. IF
  14. Operator = "+" THEN ADD Num1, Num2 GIVING Result
  15. END-IF
  16. IF
  17. Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF
  18. DISPLAY "Result is = ", Result
  19. END-PERFORM.
  20. STOP RUN.