COBOL

 

l       Countine Gogack 的使用

l       COBOL程序分为四个division,其中environmentdata division是可选的

l       Identification division 通常包含PROGRAM-ID, AUTHOR, INSTALLATION, WRRTTEN-DATE, COMPLIED-DATE. 其中programid必须在改division的第一行,名字必须和文件名字一致。其它则是可选的,编译时当作注释了。

l       Environment division 通常包含 configuration secionsourcecomputerobjectomputerinputoutput sectionfile control

l       Data division:通常包含file sectionworkingstorage section 前者是描述用于发射到或者接收来自外设的数据(用FD结构),后者定义本程序要用到的数据

l       所有的division section paragraph nameFD entry01 level entryA区开始,其余B区开始。

l       COBOL5中基本数据类型: alphabeticnumericalphanumericedited numericedited alphanumeric

l       COBOL3lateralnumericnonnumericFigurative。对于numeric的,最长不能超过18为,小数点不能在最右边,如果有符号,只能在最左边。对于nonnumeric是用引号括起来,最长160位。对于figurative常有:ZERO(S) ZEROES, SPACE(S), HIGH-VALUE(S), LOW-VALUE(S), QUOTE(S)(单引号), ALL

l       COBOLdata name3部分组成:level numberpicvalueLevel number 66rename clause77 independent item 88condition clause

l       PIC中常用符号:9,A,X,V,S,另外在pic中可以使用以下edit 符号: Z,*, , +,-,CR,DB,B,$,/,.BLANK

l       ADD时:ADD NUM1, NUM2,…NUMn to RES1,RES2….RESn GIVING GIV1GIV2…GIVn)。的意思是先把NUM1, NUM2,…NUMn加起来然后再把这个值分别加上RES1,RES2….RESn或者把结果分别赋值给GIV1GIV2…GIVn,同理退到SUBTRACT

l       MULTIP a BY b Giving c.

l       DIVIDE A BY B 21/3=7, DIVIDE B INTO A: 21/3=7, DIVIDE A BY B GIVING C REMAINDER D.  (A=21, B=3).

l       MOVE,如果移动的是alphabetalphanumeric则均是从左到右填充(可以在pic后面用JUSTIFIED RIGHT强制从右向左),右边要么被裁减,要么保留原来的值(部分替换),但是如果是numeric或者edited numeric则是全部被替换,一小数点位置对齐(如果没有明确的小数点位置,则认为最右边是小数点)向两边扩展,多了则剪裁,少了则加0或者blank。三种格式: move 。。。to 。。。;move。。。of。。。to。。。of。。。; move。。。correspondingcorr

l       GO TO PARAGRAPH_NAME,程序跳转指令

l       COBOL中的四种条件:关系条件(用关系运算符【>,GREATER THAN…】比较大小,可以结合ANDOR形成组合条件), 符号条件(identifier is not POSITIVE/NEGATIVE/ZERO),类型条件(identifier is not ALPAHBETIC, NUMERIC, ALPHABETIC-LOWER, ALPHABETIC-UPPER, UerDefinedClassName),条件变量(用88 level number定义的)

l       条件变量的定义: 由两部分组成 group item 88 level item。前者可以必须由pic,可以有value,后者定义格式:88 identifier  VALUE (IS/ARE) XXX(THRU XXX).

l       PERFORM 共有7中变体,分别是simple performPERFORM + PARAGRAPH_NAME, inline perform(PERFORM + 指令语句),嵌套performperform paragraph_name through paragraph_name, perform xxx N TIMES, perform xxx UNITL…, perform xxx varying x from x by x until x. 前面4中的任何一种结构都可以用于后面三种中去。

l       Cobol中控制流程结束STOP RUN.

l       REDEFINE: 即是对同一块内存区域进行重定义。用两个或者更多的变量指向通过一个内存区域,redefine不能由于对6688file section中的01level

l       RENAME则是用于对用一个group中的连续定义的item进行捆绑。格式: 66  xxx rename xxx 1THRU xxx2。且xxx1xxx2不能为01 level,也不能有occur子句

l       USAGE: 用于指明数据存贮格式: USAGE IS DISPLAY/COMPUTATIONAL/COMP-1/COMP-2/COMP-3. 其中COMP-3也叫packeddecimal(每个字符占用半个字节,符号存于最右边的半个字节)。

l       COBOL对文件的读写操作:涉及到三个概念FIELDRECORDFILE。需要用到record buffer,在DATA DIVISIONFILE SECTIONFD中定义。每个文件对应一个record buffer。打开文件,则其在内存中自动被创建,关闭文件,则自动被删除。

l       COBOL对文件的操作: OPEN, READ, WRITE, REWRITE, CLOSE. DELETE

l       COBOL中操作的文件类型常有sequential file(顺序组织,顺序访问,不能insertdelete),index sequential file(由两个文件组成,data fileindex filedata file有两个fieldsindexdata,而index file 也有两个域,index和在data file中对应的地址,组织方式:indexed,可以sequentialrandom)relative file依靠relative record number定位,组织方式:relative,访问方式:sequentialrandom

l       OPEN XXX FILE_NAME. 其中打开模式: inputio for readOUTPUT, EXTEND FOR WRITE, I-O FOR REWRITE. 对不同类型的文件,格式有所不同。

l       无论哪种文件类型CLOSE格式均是一样:CLOSE filename1 [WITH LOCK]

l       sequential文件操作

l       Filecontrol的格式:

SELECT file-name ASSIGN TO implementor-name

[ ORGANIZATION IS SEQUENTIAL ]

[ ACCESS MODE IS SEQUENTIAL]

[ FILE STATUS IS identifier ].

l       READ格式:

READ file-name [ NEXT RECORD ] [ INTO identifier ]

[ AT END imperative statement-1 ]

[ NOT AT END imperative statement-2 ]

[ END-READ ].

l       WRITE格式:

WRITE record-name [ FROM identifier-1 ]

[ { BEFORE, AFTER } ADVANCING

{{ integer-1, identifier-2 } { LINE, LINES }}.

l       REWRITE格式:REWRITE record-name [ FROM identifier-1 ]

l       indexed sequential file的操作

l       Filecontrol的格式:

SELECT file-name ASSIGN TO { implementor-name }

ORGANIZATION IS INDEXED

ACCESS MODE IS { SEQUENTIAL, RANDOM }

RECORD KEY IS data-name-1

[ ALTERNATE RECORD KEY IS data-name-2

WITH DUPLICATES]

[ FILE STATUS IS data-name-3 ].

l       READ格式:

READ file-name [ NEXT RECORD ] [ INTO identifier-1 ]

[ KEY IS identifier-2 ]

[ INVALID KEY imperative-statement-1 ]

[ NOT INVALID KEY imperative-statement-2 ]

[ END-READ ]

l       WRITE格式:

WRITE record-name [ FROM identifier-1 ]

[ INVALID KEY imperative-statement-1 ]

[ NOT INVALID KEY imperative-statement-2]

[ END-WRITE ].

l       REWRITE格式:

REWRITE record-name [ FROM identifier-1 ]

[ INVALID KEY imperative-statement-1 ]

[ NOT INVALID KEY imperative-statement-2]

[ END-REWRITE ].

l       DELETE格式:

DELETE file-name RECORD

[ INVALID KEY imperative-statement-1 ]

[ NOT INVALID KEY imperative-statement-2]

[END-DELETE].

l       START:可以人为指定读取文件的开始位置。

START file-name

[ KEY IS { =, >, < } data-name]

[ INVALID KEY imperative-statement-1]

[ NOT INVALID KEY imperative-statement-2 ]

[END-START].

l       relative file 的操作:

l       Filecontrol格式:

SELECT file-name ASSIGN TO { implementor-name }

ORGANIZATION IS RELATIVE

ACCESS MODE IS { SEQUENTIAL, RANDOM }

RELATIVE KEY IS data-name-1

[ FILE STATUS IS data-name-2 ].

l       READ的格式: 如果是sequential访问,read格式和对sequential fileread格式一样。如果为random访问,格式如下

READ file-name RECORD ] [ INTO identifier ]

[ INVALID KEY imperative-statement-1 ]

[ NOT INVALID KEY imperative-statement-2]

[ END-READ ].

l       WRITE格式:和对indexed sequential文件的write格式一致

l       REWRITE格式:和对indexed sequential文件的rewrite格式一致

l       DELETE格式:和对indexed sequential文件的delete格式一致

l       COPY: 发生在编译阶段,首先把要copy的文件放入到copylib下,然后使用copy指令,格式如下: copy file_name 或者 COPY FILE_NAME REPLACING XXX BY XXX.

l       CALL:函数调用,支持两种调用方式: by referenceby content,缺损为by content。被调用程序必须满足:如果有参数传递,则要有一个linkage section,且在workingstorage section之后定义,linkage section中的变量顺序顺便,procedure division之后要用using 指明被传入的参数,用exit program代替stop run

你可能感兴趣的:(cobol,file,random,delete,duplicates,access,Mainframe)