本文主要是介绍COBOL排序问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
*SORT排序文件文件超长,将主键保存在临时文件里,超长的数据从数组里面去检索获取。
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST002.
*
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. 11.
OBJECT-COMPUTER. 11.
*
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*
SELECT OUT-CSV-F ASSIGN TO CVCSV1
FILE STATUS IS FILE-STTS
ORGANIZATION IS LINE SEQUENTIAL.
*
SELECT SROT-INF ASSIGN TO SORTIN
FILE STATUS IS SRT-FILE-STTS
ORGANIZATION IS LINE SEQUENTIAL.
SELECT TMP-FILE ASSIGN TO TMP-FILE.
SELECT SROT-OUTF ASSIGN TO SORTOUT
FILE STATUS IS STO-FILE-STTS.
*
DATA DIVISION.
FILE SECTION.
/
FD OUT-CSV-F RECORD IS VARYING IN SIZE
FROM 0 TO 32752 CHARACTERS DEPENDING ON OUT-CSV-SIZE.
01 OUT-CSV-REC.
03 OUT-KEY.
* *** 年月,USER ID,実行日時 ***
05 KEY-REQ-YM PIC X(06).
05 KEY-USER-ID PIC X(10).
05 KEY-JIKKO-HT PIC X(14).
*
03 OUT-NAIYOU PIC X(20000).
* ソート キーファイル
FD SROT-INF.
01 SROT-IN-REC.
03 FILLER PIC X(30).
*
* sort用TMPファイル
SD TMP-FILE LABEL RECORD STANDARD.
01 TMP-SORT-REC.
* *** 年月 ***
03 TMP-REQ-YM PIC X(06).
* *** USER ID ***
03 TMP-USER-ID PIC X(10).
* *** 実行日時 ***
03 TMP-JIKKO-HT PIC X(14).
*
FD SROT-OUTF LABEL RECORD STANDARD.
01 SROT-OUT-REC.
03 FILLER PIC X(30).
*
/
WORKING-STORAGE SECTION.
******************************************************************
* 定数領域 *
******************************************************************
01 WK-AREA.
*
03 OUT-CSV-SIZE PIC 9(08).
*
03 TB1-TABLE.
05 TB-RECORD OCCURS 10 TIMES INDEXED BY TB-IDX.
* *** 年月 ***
07 TB-REQ-YM PIC X(06).
* *** USER ID ***
07 TB-USER-ID PIC X(10).
* *** 実行日時 ***
07 TB-JIKKO-HT PIC X(14).
* *** 他項目 ***
07 TB-NAIYOU PIC X(20000).
******************************************************************
* フラグ領域 *
******************************************************************
01 FLG-AREA.
03 FLG-RD-END PIC 9(01).
03 FILE-STTS PIC 9(02).
03 SRT-FILE-STTS PIC 9(02).
03 STO-FILE-STTS PIC 9(02).
LINKAGE SECTION.
******************************************************************
* リンケージ領域 *
******************************************************************
01 PARAMETER.
03 LENG PIC 9(04) BINARY.
03 PARM-AREA.
* *** 開始年月 ***
05 PARM-SKK-KAK-ST-YM PIC X(06).
* *** 終了年月 ***
/
PROCEDURE DIVISION USING PARAMETER.
*
SORT TMP-FILE ON DESCENDING KEY TMP-REQ-YM
ON ASCENDING KEY TMP-USER-ID
ON DESCENDING KEY TMP-JIKKO-HT
USING SROT-INF GIVING SROT-OUTF.
*
OPEN OUTPUT OUT-CSV-F.
OPEN INPUT SROT-OUTF.
*
PERFORM SROT-OUT-SEC UNTIL FLG-RD-END = 1
*
CLOSE OUT-CSV-F.
CLOSE SROT-OUTF.
STOP RUN.
/
***************************************************************
SROT-OUT-SEC SECTION.
***************************************************************
* *** ソート後明細を読込 ***
READ SROT-OUTF
AT END
MOVE 1 TO FLG-RD-END
GO TO SROT-OUT-EXIT.
*
MOVE SROT-OUT-REC TO OUT-KEY.
*
* *** その他項目 設定 ***
SET TB-IDX TO 1.
SEARCH TB-RECORD
AT END
DISPLAY 'RECORD NOT FOUND' UPON SYSOUT
WHEN TB-REQ-YM (TB-IDX)
= KEY-REQ-YM
AND TB-USER-ID (TB-IDX) = KEY-USER-ID
AND TB-JIKKO-HT (TB-IDX)
= KEY-JIKKO-HT
MOVE TB-NAIYOU (TB-IDX)
TO OUT-NAIYOU
END-SEARCH.
*
* *** 明細出力 ***
MOVE SPACE TO OUT-CSV-REC.
MOVE ZERO TO OUT-CSV-SIZE.
MOVE OUT-CSV-REC TO OUT-CSV-REC.
MOVE FUNCTION LENG (OUT-CSV-REC)
TO OUT-CSV-SIZE.
WRITE OUT-CSV-REC.
*
SROT-OUT-EXIT.
EXIT.
这篇关于COBOL排序问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!