新手入门之如何使用COBOL对VSAM进行读写(batch)


  • administrators

    vsam文件中
    key:5bates
    文件中先添加带'FFFFF'key值的记录
    用下面的cobol程序把记录重写。
    例如:
    运行前的内容是: FFFFFAAAAAAAAAAAAAAAAAAA
    运行后的内容是: FFFFFEEEEEEEEE

    ****** ***************************** Top of Data ******************************
    000100 000100   PROCESS TEST,MAP,LIST                                          
    008900 008900******************************************************************
    009000 009000*  IDENTIFICATION DIVISION                                        
    009100 009100******************************************************************
    009101 009101 IDENTIFICATION                  DIVISION.                        
    009102 009102 PROGRAM-ID.                     TESTVSAM.                        
    009103 009103******************************************************************
    009104 009104*  ENVIRONMENT    DIVISION                                        
    009105 009105******************************************************************
    009106 009106 ENVIRONMENT                     DIVISION.                        
    009107 009107 CONFIGURATION                   SECTION.                         
    009108 009108 INPUT-OUTPUT                    SECTION.                         
    009109 009109 FILE-CONTROL.                                                    
    009110 009110     SELECT  FILEV  ASSIGN       TO TESTVS                        
    009120 009120     ACCESS  MODE                IS RANDOM                        
    009130 009130     ORGANIZATION                IS INDEXED                       
    009140 009140     RECORD  KEY                 IS VS-KEY                        
    009141 009141     FILE    STATUS              IS WK-STATUS.                    
    009142 009142******************************************************************
    009143 009143*  DATA           DIVISION                                        
    009144 009144******************************************************************
    009145 009145 DATA                            DIVISION.                        
    009146 009146 FILE                            SECTION.                         
    009147 009147 FD FILEV.                                                        
    009148 009148 01 VS-REC.                                                       
    009149 009149    05 VS-KEY                    PIC X(05).                       
    009150 009150    05 VS-OTHER                  PIC X(75).                       
    009151 009151*                                                                 
    009152 009152 WORKING-STORAGE                 SECTION.                         
    009153 009153 01 WK-SWITCH                    PIC X(01).                       
    009154 009154    88 WK-SWH-ON                 VALUE '1'.                       
    009155 009155    88 WK-SWH-OFF                VALUE '0'.                       
    009156 009156 01 WK-COUNT.                                                     
    009157 009157    05 WK-CNT-RD                 PIC 9(03) COMP-3.                
    009158 009158    05 WK-CNT-WT                 PIC 9(03) COMP-3.                
    009159 009159 01 WK-COMM.                                                      
    009160 009160    05 WK-MSG                    PIC X(30).                       
    009161 009161    05 WK-STATUS                 PIC X(02).                       
    009162 009162******************************************************************
    009163 009163*  PROCEDURE      DIVISION                                        
    009164 009164******************************************************************
    009165 009165 PROCEDURE                       DIVISION.                        
    009166 009166*                                                                 
    009167 009167 MAIN                            SECTION.                         
    009168 009168 MAIN-S.                                                          
    009169 009169     PERFORM  1000-INIT.                                          
    009170 009170     PERFORM  2000-MAIN.                                          
    009180 009180     PERFORM  3000-END.                                           
    009200 009200 MAIN-E.                                                          
    009201 009201     EXIT.                                                        
    009202 009202******************************************************************
    009203 009203*  1000-INIT                                                      
    009204 009204******************************************************************
    009205 009205 1000-INIT                       SECTION.                         
    009206 009206 1000-INIT-S.                                                     
    009207 009207     OPEN I-O  FILEV.                                             
    009209 009209     IF  WK-STATUS NOT = '00'                                     
    009210 009210         MOVE  'OPEN ERROR,FILE STATUS IS '                       
    009211 009211                                 TO  WK-MSG                       
    009220 009220         PERFORM 9000-ERROR                                       
    009221 009221     END-IF.                                                      
    009222 009222 1000-INIT-E.                                                     
    009223 009223     EXIT.                                                        
    009224 009224******************************************************************
    009225 009225*  2000-MAIN                                                      
    009226 009226******************************************************************
    009227 009227 2000-MAIN                       SECTION.                         
    009228 009228 2000-MAIN-S.                                                     
    009229 009229     ADD   +1                    TO WK-CNT-RD.                    
    009230 009230     MOVE  'FFFFF'               TO VS-KEY.                       
    009240 009240     READ FILEV RECORD KEY       IS VS-KEY.                       
    009250 009250     IF  WK-STATUS = '00'                                         
    009260 009260         MOVE  'EEEEEEEEE'       TO VS-OTHER                      
    009270 009270     ELSE                                                         
    009280 009280         MOVE  'WRITE ERROR,FILE STATUS IS '                      
    009290 009290                                 TO  WK-MSG                       
    009300 009300         PERFORM 9000-ERROR                                       
    009301 009301     END-IF.                                                      
    009302 009302     REWRITE VS-REC.                                              
    009303 009303     ADD   +1                    TO WK-CNT-WT.                    
    021300 021300 2000-MAIN-E.                                                     
    021400 021400     EXIT.                                                        
    023300 023300******************************************************************
    023400 023400* 3000-END                                                        
    023500 023500******************************************************************
    023600 023600 3000-END                        SECTION.                         
    023601 023601 3000-END-S.                                                      
    023603 023603     DISPLAY 'READ : ' , WK-CNT-RD.                               
    023605 023605     DISPLAY 'WRITE: ' , WK-CNT-WT.                               
    023607 023607     CLOSE FILEV.                                                 
    023608 023608     STOP RUN.                                                    
    023609 023609 3000-END-E.                                                      
    023610 023610     EXIT.                                                        
    023611 023611******************************************************************
    023612 023612* 9000-ERROR                                                      
    023613 023613******************************************************************
    023614 023614 9000-ERROR                      SECTION.                         
    023615 023615 9000-ERROR-S.                                                    
    023616 023616     DISPLAY  WK-COMM.                                            
    023617 023617     PERFORM  3000-END.                                           
    023618 023618 9000-ERROR-E.                                                    
    023619 023619     EXIT.                                                        
    ****** **************************** Bottom of Data ****************************
    

Log in to reply
 

Looks like your connection to MainFrame was lost, please wait while we try to reconnect.