掌握Mainframe系列之 10分鐘學習COBOL

桂江發表於2020-12-06

開個坑 打算把掌握Mainframe裡有趣的教程搬過來 今天先搬COBOL

About COBOL

COBOL is not a general purpose programming language. You wouldn’t write an operating system, AI algorithm, or racing sim in it. Where it excels is turning out high-precision business transactions like the ones you find in banks, credit card processors, and other financial institutions. Its rigid structure and adherence to a very specific specification mean that it’s also easy to read and trace through, something that helps with audits and compliance. Today, COBOL runs much of the world’s highest-earning businesses, and once you start to see how it was architected, you’ll begin to see just why.

COBOL 嚴謹的結構具有易讀性以及良好的程式碼可追蹤性;有利於審計與商業執行。 因此今天許多需求高精度的商業領域如銀行、信用卡機構等普遍採用COBOL作為事務處理語言。

十分鐘學習COBOL 視訊

在這裡插入程式碼片
示例程式碼

```cobol
IDENTIFICATION DIVISION.
       PROGRAM-ID.    ADDONE.
       AUTHOR.        STUDENT.
      *
       ENVIRONMENT DIVISION.
      *
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT PRT-LINE ASSIGN TO PRTLINE.
           SELECT PRT-DONE ASSIGN TO PRTDONE.

       DATA DIVISION.
       FILE SECTION.
       FD  PRT-LINE RECORD CONTAINS 80 CHARACTERS RECORDING MODE F.
       01  PRT-REC        PIC X(80) VALUE SPACES.

       FD  PRT-DONE RECORD CONTAINS 80 CHARACTERS RECORDING MODE F.
       01  PRT-REC-DONE.
           05  PRT-DATE     PIC X(8)  VALUE SPACES.
           05  FILLER       PIC X(1)  VALUE SPACES.
           05  PRT-TIME     PIC X(4)  VALUE SPACES.
           05  FILLER       PIC X(2)  VALUE SPACES.
           05  PRT-COMMENT  PIC X(27) VALUE SPACES.
           05  FILLER       PIC X(2)  VALUE SPACES.
           05  PRT-MY-NAME  PIC X(36) VALUE SPACES.

       WORKING-STORAGE SECTION.

       01  PGM-VARIABLES.
           05  PGM-COUNT    PIC 9(05).

       01  YYYYMMDD         PIC 9(8).

       01  INTEGER-FORM     PIC S9(9).

       01  REFMOD-TIME-ITEM PIC X(8).

      ****************************************************************
      *                  PROCEDURE DIVISION                          *
      ****************************************************************
       PROCEDURE DIVISION.
      *
       A000-START.
           OPEN OUTPUT PRT-LINE.
           PERFORM A000-COUNT 10 TIMES.
           PERFORM A000-DONE.
           CLOSE   PRT-LINE.
           STOP RUN.
      *
       A000-COUNT.
           ADD 1 TO PGM-COUNT.
      *    DISPLAY PGM-COUNT.
           WRITE PRT-REC FROM PGM-COUNT.
      *
       A000-DONE.
           OPEN OUTPUT PRT-DONE.
           MOVE SPACES TO PRT-REC-DONE.
           ACCEPT REFMOD-TIME-ITEM FROM TIME.
           MOVE FUNCTION CURRENT-DATE(1:8) TO YYYYMMDD.
           MOVE YYYYMMDD         TO PRT-DATE.
           MOVE REFMOD-TIME-ITEM (1:4) TO PRT-TIME.
           MOVE "My first z/OS COBOL program" TO PRT-COMMENT.
           WRITE PRT-REC-DONE.
           CLOSE PRT-DONE.


相關文章