COBOL: structure

สำหรับ COBOL ใน Mainframe จะต้องมีโครงสร้าง column เข้ามาร่วมด้วย ดังนี้

  1. column 1-6 เป็น sequence number
  2. column 7 ไว้ใส่ตัวอักษรที่มีความหมายพิเศษ
    • * แสดงว่าบรรทัดนั้นเป็น comment
    • - แสดงว่าบรรทัดนี้ต่อมาจากบรรทัดข้างบน
  3. column 8-11 เป็น area A ซึ่งไว้ใส่ division ในโปรแกรม
  4. column 12-72 เป็น area B ไว้ใส่ code อื่นๆ นอกจาก division
  5. column 73-80 เป็น optional ที่แสดง program identification or comments
ซึ่งโครงสร้างด้านล่าง จะละ column 1-7 ไว้ (เนื่องจากไม่ได้ใส่ comment) code จะเริ่มที่ column 8 เป็นต้นไป


IDENTIFICATION DIVISION.
PROGRAM-ID
ProgName.
[AUTHOR
Desc.]
[INSTALLATION
Desc.]
[DATE-WRITTEN
Desc.]
[DATE-COMPILED
Desc.]
[SECURITY
Desc.]

[
ENVIRONMENT DIVISION.

[INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT
FileName
[ASSIGN [TO] DISK|PRINTER.]
[ORGANIZATION IS SEQUENTIAL|LINE SEQUENTIAL|RELATIVE|INDEXED.]
[ACCESS MODE IS SEQUENTIAL|RANDOM|DYNAMIC.]]]

DATA DIVISION.
[FILE SECTION.
FD
FileName [RECORD MODE [IS] BINARY|DECIMAL LOW|HIGH|HYPER DENSITY]
LABEL RECORD|RECORDS IS|ARE STANDARD|OMITTED
[VALUE OF FILE-ID IS [
DataName |Literal ]
[BLOCK CONTAINS
Integer CHARACTERS|RECORDS]
[RECORD CONTAINS
Integer CHARACTERS]
[DATA RECORD IS|RECORDS ARE
DataName1[, DataName2, ...]]

[
LevelNo DataName |FILLER
[REDEFINES
DataName ]
[PIC|PICTURE [IS]
Pattern ]
[OCCURS [
Interger TO] Integer TIMES
[DEPEND ON
DataName1 ]
[ASCENDING|DESCENDING [KEY] [IS]
DataName2 [, DataName3, ...]]
[INDEXED [BY]
IndexName1 [, IndexName2, ...]]
[RENAMES
DataName [THRU DataName2 ]]
[VALUE [IS|ARE]
Literal1 [THRU Literal2 ] [Literal3 [THRU Literal4]] ...
[JUST|JUSTIFIED RIGHT]
[SIZE [IS]
Integer CHARACTERS|DIGITS]
[CLASS [IS] NUMERIC|ALPHABETIC|ALPHANUMERIC]
[USAGE [IS] COMP|COMPUTATIONAL 1|COMP-1|COMPUTATION-1|DISPLAY|INDEX]
[BLANK WHEN ZERO]]

WORKING-STORAGE SECTION.
[77
DataName PIC|PICTURE [IS] Pattern.]
...
[
LevelNo DataName |FILLER
[REDEFINES
DataName ]
[PIC|PICTURE [IS]
Pattern ]
[OCCURS [
Interger TO] Integer TIMES
[DEPEND ON
DataName1 ]
[ASCENDING|DESCENDING [KEY] [IS]
DataName2 [, DataName3, ...]]
[INDEXED [BY]
IndexName1 [, IndexName2, ...]]
[RENAMES
DataName [THRU DataName2 ]]
[VALUE [IS|ARE]
Literal1 [THRU Literal2 ] [Literal3 [THRU Literal4]] ...
[JUST|JUSTIFIED RIGHT]
[SIZE [IS]
Integer CHARACTERS|DIGITS]
[CLASS [IS] NUMERIC|ALPHABETIC|ALPHANUMERIC]
[USAGE [IS] COMP|COMPUTATIONAL 1|COMP-1|COMPUTATION-1|DISPLAY|INDEX]
[BLANK WHEN ZERO]]
...

[LINKAGE SECTION.
[77
DataName PIC|PICTURE [IS] Pattern.]
...
[
LevelNo DataName |FILLER
[REDEFINES
DataName ]
[PIC|PICTURE [IS]
Pattern ]
[OCCURS [
Interger TO] Integer TIMES
[DEPEND ON
DataName1 ]
[ASCENDING|DESCENDING [KEY] [IS]
DataName2 [, DataName3, ...]]
[INDEXED [BY]
IndexName1 [, IndexName2, ...]]
[RENAMES
DataName [THRU DataName2 ]]
[VALUE [IS|ARE]
Literal1 [THRU Literal2 ] [Literal3 [THRU Literal4]] ...
[JUST|JUSTIFIED RIGHT]
[SIZE [IS]
Integer CHARACTERS|DIGITS]
[CLASS [IS] NUMERIC|ALPHABETIC|ALPHANUMERIC]
[USAGE [IS] COMP|COMPUTATIONAL 1|COMP-1|COMPUTATION-1|DISPLAY|INDEX]
[BLANK WHEN ZERO]]
...]

[SCREEN SECTION.
LevelNo [ScreenName] [BLANK-SCREEN]
[LINE [NUMBER] [IS] [PLUS]
Integer]
[LINE [NUMBER] [IS] [PLUS] Integer]
[BLANK LINE]
[BELL] [HIGHLIGHT|BLINK]
[VALUE [IS] Literal | PIC|PICTURE [IS]
Pattern FROM Literal2 | Identifier1 |TO Identifier2 |USING Identifier3
[BLANK WHEN ZERO]
[JUST|JUSTIFIED RIGHT]
[AUTO]
[SECURE]]

PROCEDURE DIVISION.

ParagraphName1.
Statement.
....

No comments:

Post a Comment