从VSAM文件中删除记录的逻辑

时间:2018-01-31 08:45:39

标签: vsam cobol85

我有输入文件作为VSAM文件和从JCL传递的Parm值。如果这两个匹配,则需要从输入的VSAM文件中删除记录。 请你能为我提供Cobol代码中的逻辑。

1 个答案:

答案 0 :(得分:1)

我已经确定从JCL传递的PARM值是VSAM文件的主键。请仔细阅读以下代码并检查它是否符合您的要求。

在VSAM文件中,您将拥有一个6字节字段用于员工ID(充当密钥)和20字节字段用于员工姓名。从JCL传递的PARM值是Employee ID。 VSAM文件的访问模式是随机的,PARM值用于删除VSAM文件中的记录(如果存在)。

ID DIVISION.                             
PROGRAM-ID. VSAM01.                      
ENVIRONMENT DIVISION.                    
INPUT-OUTPUT SECTION.                    
FILE-CONTROL.                            
    SELECT VSAMKSDS ASSIGN TO VSAMKSDS   
    ORGANIZATION IS INDEXED              
    ACCESS MODE IS RANDOM               
    RECORD KEY IS ASSOC-ID               
    FILE STATUS IS WS-VSAM-ST.           
DATA DIVISION.                           
FILE SECTION.                            
FD VSAMKSDS.                             
01 IN-RECORD.                            
   05 ASSOC-ID          PIC X(6).        
   05 FILLER            PIC X(1).        
   05 ASSOC-NAME        PIC X(20).       
WORKING-STORAGE SECTION.                 
01 WS-SWITCHES.                          
   05 WS-EOF            PIC X(1).        
      88 EOF            VALUE 'Y'.       
      88 NOT-EOF        VALUE 'N'.       
01 WS-DELETE            PIC 9(2) VALUE 0.
01 WS-VSAM-ST           PIC X(2).        
LINKAGE SECTION.                       
01 LS-PARM-INFO.                       
   05 WS-PARM-LENGTH    PIC S9(4) COMP.
   05 WS-PARM           PIC X(6).      
PROCEDURE DIVISION USING LS-PARM-INFO. 
    PERFORM OPEN-PARA.                 
    PERFORM PROCESS-PARA.              
    PERFORM CLOSE-PARA.                

OPEN-PARA.                             
    OPEN I-O VSAMKSDS                  
    IF WS-VSAM-ST NOT EQUAL '00'       
    PERFORM ERROR-PARA.                

PROCESS-PARA.                          
    MOVE WS-PARM TO ASSOC-ID.          
    DELETE VSAMKSDS.                   
    EVALUATE WS-VSAM-ST                
    WHEN '00'                          
    DISPLAY 'RECORD DELETED'           
    ADD 1 TO WS-DELETE                 
    WHEN '23'                          
    DISPLAY 'NOT FOUND:' WS-PARM       
    WHEN OTHER                         
    PERFORM ERROR-PARA                 
    END-EVALUATE.                      

CLOSE-PARA.                            
    CLOSE VSAMKSDS. 
    STOP RUN.                   

ERROR-PARA.                            
    DISPLAY 'VSAM STATUS:' WS-VSAM-ST. 
    CLOSE VSAMKSDS.
    STOP RUN.