DHJJ DHJJ [Hatsune's Journal Japan]

とある言語(COBOL)の再定義(レデファイン)

とある言語(COBOL)の再定義(レデファイン)

01

OpenCOBOL

03

MinGW-5.1.6.exe

Minimal GNU for WIndows

09

Downloading mingwrt-3.17-mingw32-dev.tar.gz

12

MSYS-1.0.11.exe

Setup - Minimal SYStem

18

MSYS - MinGWの設定
C:\bin\msys\1.0\postinstall>..\bin\sh.exe pi.sh

This is a post install process that will try to normalize between
your MinGW install if any as well as your previous MSYS installs
if any.  I don't have any traps as aborts will not hurt anything.
Do you wish to continue with the post install? [yn ] y

Do you have MinGW installed? [yn ] y

Please answer the following in the form of c:/foo/bar.
Where is your MinGW installation? C:/bin/MinGW

Creating /etc/fstab with mingw mount bindings.
        Normalizing your MSYS environment.

You have script /bin/awk
You have script /bin/cmd
You have script /bin/echo
You have script /bin/egrep
You have script /bin/fgrep
You have script /bin/printf
You have script /bin/pwd

Oh joy, you do not have c:/bin/MinGW/bin/make.exe. Keep it that way.

C:\bin\msys\1.0\postinstall>pause
続行するには何かキーを押してください . . .

Open COBOLの導入

ZIPファイルを展開してMinGW環境へ上書き
環境変数の設定
PATH
c:\bin\MinGW\bin;c:\bin\msys\1.0\bin;……
COB_CONFIG_DIR
c:\bin\MinGW\share\open-cobol\config

COBOLでHello WORLD

ソースコードのカラム

30

A領域から書き始めなければならないもの

31

Hello Worldのソースコード
000100*----------------------
000110*  Hello World
000120*----------------------
000200 IDENTIFICATION         DIVISION.
000300   PROGRAM-ID.          hello.
000400   AUTHOR.              HATSUNE Akira.
000500 ENVIRONMENT            DIVISION.
000600 DATA                   DIVISION.
001000 PROCEDURE              DIVISION.
001100      DISPLAY "Hello World!".
001200 STOP RUN.
999999 END PROGRAM            hello.
実行時にはノートンのSONARをとめる

33

Hello Worldのコンパイル&実行

34

4つのDIVISION

IDENTIFICATION DIVISION

37

ENVIRONMENT DIVISION

38

39

40

DATA DIVISION

41

42

43

PROCEDURE DIVISION

44

COBOLの命令

45

COBOLの四則演算

46

COBOLの条件式
010100      IF A >= B THEN
010200        IF A NOT = B THEN
010300          NEXT SENTENCE
010400        ELSE
010500          IF A < B THEN
010600            MOVE 1 TO CNT
010700          END-IF
010800        END-IF
010900      ELSE
010900        NEXT SENTENCE
010900      END-IF.

COBOLのサンプルコード

ファイル内容を表示するサンプルその1
010000 PROCEDURE              DIVISION.
010100      ACCEPT WK-FILENAME FROM ARGUMENT-VALUE.
010200      OPEN OUTPUT OUT-FILE.
010300      OPEN INPUT  IN-FILE.
010500      PERFORM WITH NO LIMIT
010700         READ IN-FILE INTO IN-RECORD
010710              AT END EXIT PERFORM END-READ
010600         WRITE OUT-RECORD FROM IN-RECORD
010800      END-PERFORM.
010900      CLOSE IN-FILE.
011000      CLOSE OUT-FILE.
010400      STOP RUN.
999999 END PROGRAM            typeCOB.
ファイル内容を表示するサンプルその2
010000 PROCEDURE              DIVISION.
010100      ACCEPT WK-FILENAME FROM ARGUMENT-VALUE.
010200      OPEN OUTPUT OUT-FILE.
010300      OPEN INPUT  IN-FILE.
010400      PERFORM UNTIL 1<>1
010500         READ IN-FILE INTO IN-RECORD
010510              AT END EXIT PERFORM END-READ
010600         WRITE OUT-RECORD FROM IN-RECORD
010700      END-PERFORM.
010800      CLOSE IN-FILE.
010900      CLOSE OUT-FILE.
011000      STOP RUN.
999999 END PROGRAM            typeCOB.
FILLER REDEFINES OCCURS
001000 DATA                   DIVISION.
002000 WORKING-STORAGE        SECTION.
002100 01 ALP                 PIC X(26).
002200 01 FILLER              REDEFINES ALP.
002300   02 ALP-CHR           OCCURS 26 TIMES PIC X.
002400 01 CNT                 PIC 9(02) BINARY.
010000 PROCEDURE              DIVISION.
010100      MOVE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO ALP.
010200      PERFORM TEST BEFORE 
010210      VARYING CNT FROM 1 BY 1 UNTIL CNT > 26
010300         DISPLAY ALP-CHR(CNT)
010400      END-PERFORM.
011000      STOP RUN.
PICTURE指定と表示
000200 IDENTIFICATION         DIVISION.
000300   PROGRAM-ID.          pic-sample.
000400   AUTHOR.              HATSUNE Akira.
001000 DATA                   DIVISION.
002000 WORKING-STORAGE        SECTION.
002100 01 NUM1                PIC 99999999.
002200 01 NUM2                PIC ZZZZZZZ9.
010000 PROCEDURE              DIVISION.
010100      MOVE 12345        TO NUM1.
010100      MOVE NUM1         TO NUM2.
010200      DISPLAY NUM1.
010200      DISPLAY NUM2.
011000      STOP RUN.
999999 END PROGRAM            pic-sample.
変数の修飾
000200 IDENTIFICATION         DIVISION.
000300   PROGRAM-ID.          dataOf.
001000 DATA                   DIVISION.
002000 WORKING-STORAGE        SECTION.
002100 01 TODAY.
002200   02 YYYY              PIC 9(4).
002300   02 MM                PIC 99.
002400   02 DD                PIC 99.
010000 PROCEDURE              DIVISION.
010100      MOVE FUNCTION CURRENT-DATE TO TODAY.
010200      DISPLAY "今年は" YYYY OF TODAY.
011000      STOP RUN.
999999 END PROGRAM            dataOf.
プログラム間連携

53

参考文献

Net COBOL for Windows V8.0 文法書

COPYRIGHT (C) 2008 初音玲 All rights reserved. / Running .NET Framework 4.0.30319.42000