社員ファイルを修正するプログラムです。追加、更新、削除を行います。
元のソースコード
******************************************************************
* Author:
* Date:
* Purpose:
* Tectonics: cobc
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTCOBOL5.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPF ASSIGN TO 'EMPFILE'
ORGANIZATION INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS EMPKEY.
*
DATA DIVISION.
FILE SECTION.
FD EMPF.
01 EMPF-REC.
03 EMPKEY PIC X(3).
03 EMPNO REDEFINES EMPKEY
PIC 9(3).
03 EMPNAME PIC X(10).
WORKING-STORAGE SECTION.
01 WORKAREA.
03 WRKNAME PIC X(10).
PROCEDURE DIVISION.
MAIN SECTION.
MAIN-PROCEDURE.
DISPLAY "社員ファイル修正".
PERFORM INIT-RTN.
PERFORM MAIN-RTN UNTIL EMPNO = 999.
PERFORM END-RTN.
STOP RUN.
MAIN-END.
EXIT.
INIT-RTN SECTION.
INIT-S.
OPEN I-O EMPF.
INIT-E.
EXIT.
MAIN-RTN SECTION.
MAIN-S.
DISPLAY "社員番号を入れてください".
ACCEPT EMPNO.
IF EMPNO = 999
DISPLAY "IF EMPNO = 999"
GO TO MAIN-E.
READ EMPF KEY IS EMPKEY
INVALID
DISPLAY "《追加》"
NOT INVALID
DISPLAY "NOT INVALID"
PERFORM UPD-RTN
DISPLAY "PERFORM UPD-RTN"
GO TO MAIN-E
END-READ.
DISPLAY "社員名をいれてください".
ACCEPT EMPNAME.
WRITE EMPF-REC.
MAIN-E.
DISPLAY "MAIN-E"
EXIT.
END-RTN SECTION.
END-S.
CLOSE EMPF.
END-E.
EXIT.
UPD-RTN SECTION.
UPD-S.
DISPLAY "《更新》".
DISPLAY "社員名をいれてください:" EMPNAME.
ACCEPT WRKNAME.
EVALUATE WRKNAME
WHEN ""
CONTINUE
WHEN "D"
DELETE EMPF
DISPLAY "削除しました"
WHEN OTHER
MOVE WRKNAME TO EMPNAME
REWRITE EMPF-REC
END-EVALUATE.
UPD-E.
EXIT.
END PROGRAM TESTCOBOL4.
フローチャート図で表現したもの
%%{init: {'theme':'base','themeVariables':{
'primaryColor':'white',
'primaryTextColor':'#000000',
'primaryBorderColor':'#000000',
'lineColor':'#000000',
'textColor':'#6A7FABCC',
'fontSize':'15px'}}}%%
%%{ init: { 'flowchart': { 'curve': 'basis' } } }%%
graph TD;
classDef default fill:#FFFFE0,stroke:#333,stroke-width:2px;
classDef clrPattern1 fill:#FFFF00,stroke:#333,stroke-width:2px;
classDef clrPattern2 fill:#FFA500,stroke:#333,stroke-width:2px;
classDef clrPattern3 fill:#ADFF2F,stroke:#333,stroke-width:2px;
classDef clrPattern4 fill:#FFC0CB,stroke:#333,stroke-width:2px;
classDef clrPattern5 fill:#ADD8E6,stroke:#333,stroke-width:2px;
linkStyle default stroke:#000000,stroke-width:2px;
%%データ定義
8("処理 開始")
9[/" 【出力】
31: DISPLAY ゛社員ファイル修正゛"/]:::clrPattern3
10[[" 【呼出】
32: PERFORM INIT-RTN"]]:::clrPattern5
11[/" 【繰返し文開始】
33: PERFORM MAIN-RTN
UNTIL EMPNO = 999
"\]:::clrPattern2
14[[" 【呼出】
33: PERFORM MAIN-RTN
UNTIL EMPNO = 999
"]]:::clrPattern5
15[\"33:繰返文終了"/]:::clrPattern2
16[[" 【呼出】
34: PERFORM END-RTN"]]:::clrPattern5
17[/"【STOP RUN】
35: STOP RUN"/]:::clrPattern3
18("処理 終了")
%%ルート
8-->9
9-->10
10-->11
11-->|ループ開始|14
14-->15
15-->|ループ終了|11
15-->|ループ継続|16
16-->17
17-->18
%%{init: {'theme':'base','themeVariables':{
'primaryColor':'white',
'primaryTextColor':'#000000',
'primaryBorderColor':'#000000',
'lineColor':'#000000',
'textColor':'#6A7FABCC',
'fontSize':'15px'}}}%%
%%{ init: { 'flowchart': { 'curve': 'basis' } } }%%
graph TD;
classDef default fill:#FFFFE0,stroke:#333,stroke-width:2px;
classDef clrPattern1 fill:#FFFF00,stroke:#333,stroke-width:2px;
classDef clrPattern2 fill:#FFA500,stroke:#333,stroke-width:2px;
classDef clrPattern3 fill:#ADFF2F,stroke:#333,stroke-width:2px;
classDef clrPattern4 fill:#FFC0CB,stroke:#333,stroke-width:2px;
classDef clrPattern5 fill:#ADD8E6,stroke:#333,stroke-width:2px;
linkStyle default stroke:#000000,stroke-width:2px;
%%データ定義
19("処理 開始")
20[/" 【入力】
40: OPEN I-O EMPF"/]:::clrPattern4
21("処理 終了")
%%ルート
19-->20
20-->21
%%{init: {'theme':'base','themeVariables':{
'primaryColor':'white',
'primaryTextColor':'#000000',
'primaryBorderColor':'#000000',
'lineColor':'#000000',
'textColor':'#6A7FABCC',
'fontSize':'15px'}}}%%
%%{ init: { 'flowchart': { 'curve': 'basis' } } }%%
graph TD;
classDef default fill:#FFFFE0,stroke:#333,stroke-width:2px;
classDef clrPattern1 fill:#FFFF00,stroke:#333,stroke-width:2px;
classDef clrPattern2 fill:#FFA500,stroke:#333,stroke-width:2px;
classDef clrPattern3 fill:#ADFF2F,stroke:#333,stroke-width:2px;
classDef clrPattern4 fill:#FFC0CB,stroke:#333,stroke-width:2px;
classDef clrPattern5 fill:#ADD8E6,stroke:#333,stroke-width:2px;
linkStyle default stroke:#000000,stroke-width:2px;
%%データ定義
22("処理 開始")
23[/" 【出力】
45: DISPLAY ゛社員番号を入れ
てください゛
"/]:::clrPattern3
24[/" 【入力】
46: ACCEPT EMPNO"/]:::clrPattern4
25{"47:条件文"}:::clrPattern1
28[/"【GOTO文】
48: GO TO MAIN-E"/]:::clrPattern3
29(("48:
ENDIF"))
30["49:
READ文開始"]
31{"50:
INVALID"}:::clrPattern1
34[/" 【出力】
51: DISPLAY ゛《追加》゛"/]:::clrPattern3
35["52: NOT INVALID"]
36[[" 【呼出】
53: PERFORM UPD-RTN"]]:::clrPattern5
37[/"【GOTO文】
54: GO TO MAIN-E"/]:::clrPattern3
38(("54:
END INVALID"))
39["55:
READ文終了"]
40[/" 【出力】
56: DISPLAY ゛社員名をいれてください゛"/]:::clrPattern3
41[/" 【入力】
57: ACCEPT EMPNAME"/]:::clrPattern4
42[/" 【出力】
58: WRITE EMPF-REC"/]:::clrPattern3
43[/" 【制御入力(GOTO先)】
59: MAIN-E"/]:::clrPattern4
44("処理 終了")
%%ルート
22-->23
23-->24
24-->25
25-->|真(TRUE)|28
25-->|偽(FALSE)|29
28-->43
29-->30
30-->31
31-->|データ妥当性検査
真|34
31-->|データ妥当性検査
偽|35
34-->38
35-->36
36-->37
37-->43
38-->39
39-->40
40-->41
41-->42
42-->43
43-->44
style sg1 color:red,fill-opacity:0, stroke-opacity:0;
subgraph sg1["IF EMPNO = 999"]
25
end
style sg2 color:red,fill-opacity:0, stroke-opacity:0;
subgraph sg2["INVALID"]
31
end
%%{init: {'theme':'base','themeVariables':{
'primaryColor':'white',
'primaryTextColor':'#000000',
'primaryBorderColor':'#000000',
'lineColor':'#000000',
'textColor':'#6A7FABCC',
'fontSize':'15px'}}}%%
%%{ init: { 'flowchart': { 'curve': 'basis' } } }%%
graph TD;
classDef default fill:#FFFFE0,stroke:#333,stroke-width:2px;
classDef clrPattern1 fill:#FFFF00,stroke:#333,stroke-width:2px;
classDef clrPattern2 fill:#FFA500,stroke:#333,stroke-width:2px;
classDef clrPattern3 fill:#ADFF2F,stroke:#333,stroke-width:2px;
classDef clrPattern4 fill:#FFC0CB,stroke:#333,stroke-width:2px;
classDef clrPattern5 fill:#ADD8E6,stroke:#333,stroke-width:2px;
linkStyle default stroke:#000000,stroke-width:2px;
%%データ定義
45("処理 開始")
46[/" 【CLOSE文】
63: CLOSE EMPF"/]:::clrPattern3
47("処理 終了")
%%ルート
45-->46
46-->47
%%{init: {'theme':'base','themeVariables':{
'primaryColor':'white',
'primaryTextColor':'#000000',
'primaryBorderColor':'#000000',
'lineColor':'#000000',
'textColor':'#6A7FABCC',
'fontSize':'15px'}}}%%
%%{ init: { 'flowchart': { 'curve': 'basis' } } }%%
graph TD;
classDef default fill:#FFFFE0,stroke:#333,stroke-width:2px;
classDef clrPattern1 fill:#FFFF00,stroke:#333,stroke-width:2px;
classDef clrPattern2 fill:#FFA500,stroke:#333,stroke-width:2px;
classDef clrPattern3 fill:#ADFF2F,stroke:#333,stroke-width:2px;
classDef clrPattern4 fill:#FFC0CB,stroke:#333,stroke-width:2px;
classDef clrPattern5 fill:#ADD8E6,stroke:#333,stroke-width:2px;
linkStyle default stroke:#000000,stroke-width:2px;
%%データ定義
48("処理 開始")
49[/" 【出力】
68: DISPLAY ゛《更新》゛"/]:::clrPattern3
50[/" 【出力】
69: DISPLAY ゛社員名をいれて
ください:゛ EMPNAME
"/]:::clrPattern3
51[/" 【入力】
70: ACCEPT WRKNAME"/]:::clrPattern4
52{"71:
EVALUATE
WRKNAME"}:::clrPattern1
53{"72:条件文"}:::clrPattern1
56["73: CONTINUE"]
57(("73:
ENDIF"))
58{"74:条件文"}:::clrPattern1
61[/" 【出力】
75: DELETE EMPF"/]:::clrPattern3
62[/" 【出力】
76: DISPLAY ゛削除しました゛"/]:::clrPattern3
63(("76:
ENDIF"))
64{"77:条件文"}:::clrPattern1
67["78: MOVE WRKNAME TO
EMPNAME
"]
68[/" 【出力】
79: REWRITE EMPF-REC"/]:::clrPattern3
69(("79:
ENDIF"))
70(("80:
END-EVALUATE."))
71("処理 終了")
%%ルート
48-->49
49-->50
50-->51
51-->52
52-->|WHEN|53
52-->|WHEN|58
52-->|WHEN|64
53-->56
56-->57
57-->70
58-->61
61-->62
62-->63
63-->70
64-->67
67-->68
68-->69
69-->70
70-->71
style sg1 color:red,fill-opacity:0, stroke-opacity:0;
subgraph sg1["WHEN “”“”"]
53
end
style sg2 color:red,fill-opacity:0, stroke-opacity:0;
subgraph sg2["WHEN “”D“”"]
58
end
style sg3 color:red,fill-opacity:0, stroke-opacity:0;
subgraph sg3["WHEN OTHER"]
64
end