OPEN-COBOL

COBOLはcommon business oriented languageの略で、書式のルールが厳格です。文末がピリオドで、大文字です。

DIVISION > SECTION

cobol

開発環境に必要となるファイルをインストールしていきましょう。

# yum -y install gcc
# yum -y install gmp-devel
# yum -y install ncurses-devel
# yum -y install db4-devel
# wget http://downloads.sourceforge.net/open-cobol/open-cobol-1.0.tar.gz
# tar zxvf open-cobol-1.0.tar.gz
# cd open-cobol-1.0
# ./configure
# make
# make install
# ln -s /usr/local/lib/libcob.so.1.0.0 /usr/lib/libcob.so.1
# ln -s /usr/local/lib/libcob.so.1.0.0 /usr/lib/libcob.so
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/li

自由書式です。

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
  MAIN SECTION.
    DISPLAY 'HELLO WORLD!'.
    STOP RUN.
[vagrant@localhost cobol]$ cobc -x --free hello.cob
[vagrant@localhost cobol]$ ls
hello  hello.cob
[vagrant@localhost cobol]$ ./hello
HELLO WORLD!

変数

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
 WORKING-STORAGE SECTION.
  01 MY-DATA1 PIC X(20).
PROCEDURE DIVISION.
  MAIN SECTION.
    MOVE 'HELLO WORLD!' TO MY-DATA1.
    DISPLAY MY-DATA1.
    STOP RUN.

数値の変数

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
 WORKING-STORAGE SECTION.
  01 MY-DATA1 PIC X(20).
  01 MY-DATA2 PIC 99999.
PROCEDURE DIVISION.
  MAIN SECTION.
    MOVE 120 TO MY-DATA2.
    MOVE 'HELLO WORLD!' TO MY-DATA1.
    DISPLAY MY-DATA2.
    STOP RUN.

集合項目

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
 WORKING-STORAGE SECTION.
  01 MY-PRODUCT.
    03 PRODUCT-ID PIC X(5).
    03 PRODUCT-PRICE PIC 9(5).
PROCEDURE DIVISION.
  MAIN SECTION.
    MOVE "ID-12" TO PRODUCT-ID.
    MOVE 2980 TO PRODUCT-PRICE.
    DISPLAY PRODUCT-PRICE.
    DISPLAY MY-PRODUCT.
    STOP RUN.