cobol学习之三文件的输入和输出

对文件进行读取,按照规定好的字节读取后进行复制给另一个文件,在另一个文件里面用空格隔开每一项的值

代码如下:

000010 IDENTIFICATION			DIVISION.
000020 PROGRAM-ID.			SAMPLE02-1.
000030 ENVIRONMENT			DIVISION.
000040  INPUT-OUTPUT			SECTION.
000050  FILE-CONTROL.			
000060     SELECT INPUT-FILE ASSIGN TO IFILE.
000070     SELECT PRINT-FILE ASSIGN TO PFILE.
000080 DATA				DIVISION.
000090  FILE	SECTION.
000100	FD INPUT-FILE LABEL RECORD IS STANDARD.
000110	01  GZQD-R.
000120    02  BH			PIC 9(6).
000130	  02  XM			PIC 9(10).
000140    02  JBGZ       		PIC 9(3)V99.
000150  FD  PRINT-FILE  LABEL  RECORD  IS  STANDARD.
000160  01  GZQD-P.  
000170    02  FILLER 			PIC X.
000180    02  BH-P			PIC 9(6).
000190    02  FILLER			PIC X.
000200	  02  XM-P			PIC 9(10).
000210    02  FILLER			PIC X.
000220    02  JBGZ-P			PIC 9(3).99.
000221    02  FILLER			PIC XX.
000222    02  SFGZ-P			PIC 9(6).99.
000230 PROCEDURE  DIVISION.
000240 K.  OPEN  INPUT  INPUT-FILE.
000250	   OPEN  OUTPUT  PRINT-FILE.
000260 D.  MOVE  SPACE			TO  GZQD-P.
000261     READ  INPUT-FILE
000262              AT  END  CLOSE INPUT-FILE, PRINT-FILE
000263			     STOP  RUN.
000264 S.  MOVE  BH			TO BH-P.
000265     MOVE  XM			TO XM-P.
000266     MOVE  JBGZ			TO JBGZ-P.
000267 SU. COMPUTE  SFGZ-P = BH + JBGZ.
000268 X.  WRITE GZQD-P AFTER 2.
000269     GO TO D.  
000270

原文件环境如下:

123456938394049323482812923849320239237293212392394023402324230128792374237428284298238729382728340298343

输出文件打开如下:


 123456 9383940493 234.82  123690.82

 812923 8493202392 372.93  813295.93

 212392 3940234023 242.30  212634.30

 128792 3742374282 842.98  129634.98

 238729 3827283402 983.43  239712.43


你可能感兴趣的:(cobol)