使用Easytrieve / Cobol删除/省略多个记录

时间:2015-05-18 17:27:09

标签: cobol mainframe easytrieve

让我们假设我有一个文件A有以下数据:

A1.01  
A2.02  
A4.03   
A6.01

文件B包含以下数据:

A2.02 xyshahaslsl  
A2.02 dkjhsldhsds  
A2.02 ewewhrewjws  
A4.03 wejwejwrewl  
A4.03 wejedededee  
A5.01 kdkgskhdgss  
A5.02 fljsdfjdfjd  
A5.03 sdjdhsdhsld  
A7.04 jhsdhskdhsd  
A7.07 dsjdhslkhds  

如果文件A中的记录与第二个文件的记录的前两个字母数据匹配,则需要从文件B中删除它们。

因此输出应如下所示:

A5.01 kdkgskhdgss  
A5.02 fljsdfjdfjd  
A5.03 sdjdhsdhsld  
A7.04 jhsdhskdhsd  
A7.07 dsjdhslkhds 

我的文件A有400条记录,文件B有50万条记录。我运行了一个COBOL程序但运行时间太长了。

cobol程序逻辑如下:
在这里,我将50万条记录文件记录为A.
并且该文件包含400条记录作为文件B.

WORKING-STORAGE SECTION.                         
01 WS-RECORDS-WRITTEN    PIC 9(8) VALUE ZEROES.  
01 WS-RECORDS-DELETED    PIC 9(8) VALUE ZEROES.  
01 WS-INSERT-FILE-STATUS PIC X(2).               
01 WS-EOFA PIC A(1) VALUE 'N'.                   
01 WS-EOFB PIC A(1) VALUE 'N'.                   
01 WS-FLAG-FOUND PIC A(1) VALUE 'N'. 



PROCEDURE DIVISION.                                    
MAIN-PARA.                                             
     OPEN INPUT IFILEA                                 
     OPEN OUTPUT OFILE                                 
     PERFORM PARA0 THRU PARA0-EXIT UNTIL WS-EOFA = "Y" 
     CLOSE IFILEA                                      
     CLOSE OFILE                                       
     STOP RUN.                                         
     EXIT.                                             
PARA0.                                                 
     READ IFILEA                                       
     AT END MOVE "Y" TO WS-EOFA                        
     END-READ                                          
     IF WS-EOFA = "N"                                  
        OPEN INPUT IFILEB                              
       MOVE "N" TO WS-EOFB                             
       MOVE "N" TO WS-FLAG-FOUND                       
         PERFORM PARA1 THRU PARA1-EXIT UNTIL WS-EOFB = "Y"  
             OR WS-FLAG-FOUND = "Y"                         
         IF WS-FLAG-FOUND = "N"                             
            WRITE F2RECORD FROM F0RECORD                    
         END-IF                                             
        CLOSE IFILEB                                        
      END-IF.                                               
 PARA0-EXIT.                                                
      EXIT.                                                 
 PARA1.                                                     
      READ IFILEB                                           
      AT END MOVE "Y" TO WS-EOFB                            
      END-READ                                              
      IF OSS024S-TRACKING-ID = OSS024V-REC                  
* SKIP THE RECORD                                           
        MOVE "Y" TO WS-FLAG-FOUND                           
      END-IF.                                               
 PARA1-EXIT.                                                
      EXIT.   

1 个答案:

答案 0 :(得分:3)

[为了清楚起见,添加了示例文件控制,文件部分和所需的工作存储 按照弹跳球的相关其他文件。引用的文件名是我的测试。样本只是为了简洁起见]

FILE-CONTROL.
    SELECT FILE-A ASSIGN TO "Q30309414.EXC"
            ORGANIZATION IS LINE SEQUENTIAL
        FILE STATUS  IS FILE-A-STATUS.
FILE SECTION.
FD  FILE-A.        
01  FILE-A-REC.
    05 FILE-A-FIELD    PIC X(02).
    05 FILLER          PIC X(18).
WORKING-STORAGE SECTION.
01  FILE-A-STATUS            PIC X(02).
    88 EOF-A                 VALUE '10'.
MAINLINE.
    OPEN INPUT FILE-A.
    OPEN INPUT FILE-B.
    OPEN OUTPUT FILE-O.
    MOVE LOW-VALUES          TO FILE-A-REC.
    PERFORM READ-AND-FILTER 
      UNTIL EOF-B.
    CLOSE FILE-A.
    CLOSE FILE-B.
    CLOSE FILE-O.
    STOP RUN.

READ-AND-FILTER.
    READ FILE-B AT END MOVE HIGH-VALUES TO FILE-B-REC.
    PERFORM READ-NEXT-FILTER
       UNTIL FILE-B-FIELD IS NOT GREATER THAN FILE-A-FIELD.
    IF FILE-B-FIELD IS LESS THAN FILE-A-FIELD
      WRITE FILE-O-REC FROM FILE-B-REC.

READ-NEXT-FILTER.
    IF FILE-B-FIELD IS GREATER THAN FILE-A-FIELD
      READ FILE-A
        AT END MOVE HIGH-VALUES TO FILE-A-REC.

不需要任何标志,只需要文件状态。当然不需要创建依赖于布局的代码的邪恶表演。

这假设您的数据按照您的指示进行排序。如果不是,则方法会有所不同 - 将有问题的排除文件字段(两个字符)读入工作存储表,对表进行排序和搜索,以便与读取的每个主文件记录进行匹配。