Cobol Vsam KSDS匹配并合并

时间:2016-04-24 21:44:19

标签: cobol mainframe

遇到程序问题。我已经找到了如何读取VSAM KSDS文件,但我需要匹配并合并正常的顺序文件。有人可以帮忙吗?

规格如下:

  • 在源库中创建COBOL基础程序
  • 对于VSAM文件,请在COBOL程序的相应位置使用以下副本 - VSAMFD,VSAMRC,VSAMSEL。
  • 定义INPUT(SELECT,FD,OPEN,READ,CLOSE)
  • 定义OUTPUT(SELECT,FD,OPEN,WRITE,CLOSE)
  • 编写必要的PROCEDURE DIVISION语句以读取所有输入文件。对于每个记录,填充输出记录并将记录写入输出打印文件。
  • 使用VSAM文件的读取键获取毕业年份的记录。从VSAM文件输入填充毕业年份。
  • 如果找不到VSAM记录(VSAMRC不='00' - 移动'????'到O / P记录的毕业年份。
  • 找到后,填写输出记录并写入相应的O / P记录。

Cobol计划:

   IDENTIFICATION DIVISION.
   PROGRAM-ID. SU43PGM5.
   ENVIRONMENT DIVISION.
   CONFIGURATION SECTION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
       SELECT VSAM-KSDS-FILE ASSIGN IFILE2
          ORGANIZATION IS INDEXED
          ACCESS MODE IS SEQUENTIAL
          RECORD KEY IS VSAM-KSDS-RECORD-KEY
          FILE STATUS  IS VSAM-STATUS-CODE
                          VSAM-EXTENDED-STATUS-CODE.
        SELECT IN-FILE   ASSIGN TO IFILE.
        SELECT IN-FILE-2 ASSIGN TO IFILE2.
        SELECT OUT-FILE  ASSIGN TO OFILE.

 ***** NEED TO HAVE SELECTS FOR REGULAR FILES AS WELL
 ***** PURPOSE OF THIS PROGRAM - COMBINE THE REGULAR FILES WITH VSAM

   DATA DIVISION.
   FILE SECTION.
   FD  IN-FILE
       RECORDING MODE IS F
       RECORD CONTAINS 500 CHARACTERS

   01  IN-REC.
       05  IN-NAME        PIC X(20).
       05  IN-ADDRESS     PIC X(20).
       05  IN-SSN         PIC 9(9).
       05  IN-YR-GRAD     PIC X(2).
       05  FILLER         PIC X(25).

   FD  IN-FILE-2.
   01  IN-REC-2.
       05  IN-SSN-2       PIC 9(9).
       05  IN-CREDITS-2   PIC XX.

   FD  OUT-FILE.
   01  OUT-REC.
       05  OUT-NAME        PIC X(20).
       05  OUT-ADDRESS     PIC X(20).
       05  OUT-SSN         PIC 9(9).
       05  OUT-YR-GRAD     PIC X(2).
       05  FILLER          PIC X(25).

   FD  VSAM-KSDS-FILE.
   01  VSAM-KSDS-RECORD.
       05  VSAM-KSDS-RECORD-KEY    PIC X(20).
       05  VSAM-KSDS-EMP-INFO      PIC X(60).
   WORKING-STORAGE SECTION.

   01  WS-WORK-AREA.
       05  IN-CTR         PIC 9(5)  COMP-3  VALUE 0.
       05  OUT-CTR        PIC 9(5)  COMP-3  VALUE 0.
       05  EOF-SW         PIC X             VALUE SPACES.
       05  EOF-SW-2       PIC X             VALUE SPACES.
       05  MATCH-SWITCH   PIC X             VALUE SPACES.

   01  VSAM-STATUS-CODE.
       05 VSAM-STATUS-CODE-BYTE1   PIC X.
       05 VSAM-STATUS-CODE-BYTE2   PIC X.

   01  VSAM-EXTENDED-STATUS-CODE.
       05 VSAM-EXTENDED-RETURN-CODE   PIC S9(4) COMP.
       05 VSAM-EXTENDED-FUNCTION-CODE PIC S9(4) COMP.
       05 VSAM-EXTENDED-FEEDBACK-CODE PIC S9(4) COMP.

   01  SWITCHES.
        05  FILE-AT-END     PIC X  VALUE 'N'.

   PROCEDURE DIVISION.
       PERFORM INITIALIZATION
       PERFORM PROCESS-ALL
           UNTIL FILE-AT-END = 'Y'
       PERFORM TERMINATION
       GOBACK.

    OPEN-FILES-RTN.
       OPEN INPUT IN-FILE.

       OPEN OUTPUT OUT-FILE.

       READ IN-FILE
         AT END MOVE 'F' TO EOF-SW.
   OPEN-FILES-RTN-EXIT. EXIT.

   INITIALIZATION.
       OPEN INPUT VSAM-KSDS-FILE
       IF VSAM-STATUS-CODE IS NOT EQUAL TO '00'
       THEN GO TO ERROR-EXIT
       END-IF
       PERFORM READ-PAR.

   PROCESS-ALL.
  *    THIS PROGRAM IS SIMPLE.
  *    IT JUST DISPLAYS THE RECORDS OF THE VSAM FILE
  *    OTHER PROGRAMS WOULD DO MORE INVOLVED PROCESSING
       DISPLAY VSAM-KSDS-RECORD
       PERFORM READ-PAR.

   TERMINATION.
       CLOSE VSAM-KSDS-FILE.
   READ-PAR.
       READ VSAM-KSDS-FILE
       AT END MOVE 'Y' TO FILE-AT-END
       NOT AT END
        IF VSAM-STATUS-CODE IS NOT EQUAL TO '00'
        THEN GO TO ERROR-EXIT
        END-IF
       END-READ.


   ERROR-EXIT.

1 个答案:

答案 0 :(得分:0)

Why does it have to be a COBOL program?

You could probably achieve all this with DFSORT (or Syncsort if that's what your site has). JOINKEYS would, I think, do the matching.

If this is a class assignment (and no disrespect either way) you might get extra credit if you present both the COBOL and DFSORT / Syncsort solution.

Of it's not then the approach I suggest might outperform and be more maintainable.

Just a thought.