新手入门之如何读文件的COBOL程序


  • administrators

    input: 40bates record format= FB
    output:40bates record format= FB
    WK-CNT-RD读文件的计数器
    WK-CNT-WT写文件的计数器

    用到的JCL

    //KOKHEL1 JOB CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1),                        
    //             NOTIFY=&SYSUID                                           
    //STEP010  EXEC PROC=IGYWCL                                             
    //COBOL.SYSIN DD DSN=KOK.COBOL.LIB(TESTFILE),DISP=SHR                     
    //LKED.SYSLMOD DD DSN=KOK.LOAD.LIB(TESTFILE),DISP=SHR 
    //STEP020  EXEC PGM=TESTFILE                                
    //STEPLIB DD DSN=KOK.LOAD.LIB,DISP=SHR                
    //TESTFA   DD DSN=KOK.PS.TESTAA,DISP=SHR            
    //TESTFB   DD DSN=KOK.PS.TESTBB,DISP=SHR            
    //SYSPRINT DD SYSOUT=*                                      
    //CEEDUMP  DD SYSOUT=*                                      
    //SYSDUMP  DD SYSOUT=*                                      
    //SYSOUT   DD SYSOUT=*                                      
    //  
    

    创建PS的参数

       Menu  RefList  Utilities  Help                                               
    ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss 
                                 Allocate New Data Set                              
    Command ===>                                                                   
                                                                        More:     + 
    Data Set Name  . . . : KOK.PS.TESTAA                                  
                                                                                    
    Management class . . .                (Blank for default management class)     
    Storage class  . . . .                (Blank for default storage class)        
      Volume serial . . . .                (Blank for system default volume) **     
      Device type . . . . .                (Generic unit or device address) **      
    Data class . . . . . .                (Blank for default data class)           
      Space units . . . . . BLKS           (BLKS, TRKS, CYLS, KB, MB, BYTES         
                                            or RECORDS)                             
      Average record unit                  (M, K, or U)                             
      Primary quantity  . . 1              (In above units)                         
      Secondary quantity    1              (In above units)                         
      Directory blocks  . . 0              (Zero for sequential data set) *         
      Record format . . . . FB                                                      
      Record length . . . . 40                                                      
      Block size  . . . . . 4000                                                    
      Data set name type                   (LIBRARY, HFS, PDS, LARGE, BASIC, *      
                                            EXTREQ, EXTPREF or blank)               
      Expiration date . . .                (YY/MM/DD, YYYY/MM/DD                    
    Enter "/" to select option             YY.DDD, YYYY.DDD in Julian form         
        Allocate Multiple Volumes           DDDD for retention period in days       
                                            or blank)                               
                                                                                    
    ( * Specifying LIBRARY may override zero directory block)                      
                                                                                    
      F1=Help      F2=Split     F3=Exit      F7=Backward  F8=Forward   F9=Swap      
    F10=Actions  F12=Cancel                                                        
    

    COBOL代码

    ****** ***************************** Top of Data ******************************
    000100 000100   PROCESS TEST,MAP                                               
    008900 008900******************************************************************
    009000 009000*  IDENTIFICATION DIVISION                                        
    009100 009100******************************************************************
    009101 009101 IDENTIFICATION                  DIVISION.                        
    009102 009102 PROGRAM-ID.                     TESTFILE.                        
    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  FILEA  ASSIGN       TO TESTFA.                       
    009111 009111     SELECT  FILEB  ASSIGN       TO TESTFB.                       
    009112 009112******************************************************************
    009113 009113*  DATA           DIVISION                                        
    009114 009114******************************************************************
    009115 009115 DATA                            DIVISION.                        
    009116 009116 FILE                            SECTION.                         
    009117 009117 FD FILEA.                                                        
    009121 009121 01 FA-REC.                                                       
    009122 009122    05 FA-INFO                   PIC X(40).                       
    009123 009123*                                                                 
    009124 009124 FD FILEB.                                                        
    009127 009127 01 FB-REC.                                                       
    009128 009128    05 FB-INFO                   PIC X(40).                       
    009129 009129*                                                                 
    009130 009130 WORKING-STORAGE                 SECTION.                         
    009131 009131 01 WK-SWITCH                    PIC X(01).                       
    009132 009132    88 WK-SWH-ON                 VALUE '1'.                       
    009133 009133    88 WK-SWH-OFF                VALUE '0'.                       
    009134 009134 01 WK-COUNT.                                                     
    009135 009135    05 WK-CNT-RD                 PIC 9(03) COMP-3.                
    009136 009136    05 WK-CNT-WT                 PIC 9(03) COMP-3.                
    009137 009137******************************************************************
    009138 009138*  PROCEDURE      DIVISION                                        
    009139 009139******************************************************************
    009140 009140 PROCEDURE                       DIVISION.                        
    009141 009141*                                                                 
    009142 009142     PERFORM  1000-INIT.                                          
    009143 009143     PERFORM  2000-MAIN.                                          
    009144 009144     PERFORM  3000-END.                                           
    009145 009145******************************************************************
    009146 009146*  1000-INIT                                                      
    009147 009147******************************************************************
    009200 009200 1000-INIT                       SECTION.                         
    009201 009201 1000-INIT-S.                                                     
    009202 009202     OPEN INPUT  FILEA.                                           
    009203 009203     OPEN OUTPUT FILEB.                                           
    009204 009204 1000-INIT-E.                                                     
    009205 009205     EXIT.                                                        
    009206 009206******************************************************************
    009207 009207*  2000-MAIN                                                      
    009208 009208******************************************************************
    009209 009209 2000-MAIN                       SECTION.                         
    009210 009210 2000-MAIN-S.                                                     
    009211 009211     ADD   +1                    TO WK-CNT-RD.                    
    009212 009212     READ FILEA                                                   
    009213 009213       AT END                                                     
    009214 009214         SET   WK-SWH-ON         TO TRUE                          
    009216 009216       NOT AT END                                                 
    009217 009217         MOVE  FA-INFO           TO FB-INFO                       
    009219 009219         WRITE FB-REC                                             
    009220 009220         ADD   +1                TO WK-CNT-WT                     
    009221 009221     END-READ.                                                    
    009230 009230*                                                                 
    020700 020700     PERFORM  UNTIL WK-SWH-ON                                     
    020710 020710       ADD  +1                   TO WK-CNT-RD                     
    020800 020800       READ FILEA                                                 
    020900 020900         AT END                                                   
    020910 020910           SET   WK-SWH-ON       TO TRUE                          
    021000 021000         NOT AT END                                               
    021002 021002           MOVE  FA-INFO         TO FB-INFO                       
    021020 021020           WRITE FB-REC                                           
    021030 021030           ADD   +1              TO WK-CNT-WT                     
    021100 021100       END-READ                                                   
    021200 021200     END-PERFORM.                                                 
    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 FILEA , FILEB.                                         
    023608 023608     STOP RUN.                                                    
    023609 023609 3000-END-E.                                                      
    023610 023610     EXIT.                                                        
    ****** **************************** Bottom of Data ****************************
    

    input:

    ****** ***************************** Top of Data ******************************
    =COLS> ----+----1----+----2----+----3----+----4                                
    000001 AAAAAAAAA AAAAAAAAA AAAAAAAAA AAAAAAAAAA                                
    000002 BBBBBBBBB BBBBBBBBB BBBBBBBBB BBBBBBBBBB                                
    000003 CCCCCCCCC CCCCCCCCC CCCCCCCCC CCCCCCCCCC                                
    000004 DDDDDDDDD DDDDDDDDD DDDDDDDDD DDDDDDDDDD                                
    000005 EEEEEEEEE EEEEEEEEE EEEEEEEEE EEEEEEEEEE                                
    000006 FFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFFF                                
    ****** **************************** Bottom of Data ****************************
    

    output:

    ****** ***************************** Top of Data ******************************
    =COLS> ----+----1----+----2----+----3----+----4                                
    000001 AAAAAAAAA AAAAAAAAA AAAAAAAAA AAAAAAAAAA                                
    000002 BBBBBBBBB BBBBBBBBB BBBBBBBBB BBBBBBBBBB                                
    000003 CCCCCCCCC CCCCCCCCC CCCCCCCCC CCCCCCCCCC                                
    000004 DDDDDDDDD DDDDDDDDD DDDDDDDDD DDDDDDDDDD                                
    000005 EEEEEEEEE EEEEEEEEE EEEEEEEEE EEEEEEEEEE                                
    000006 FFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFFF                                
    ****** **************************** Bottom of Data ****************************
    

    注:程序里面定义的FILEA的长度是40,所以相应的Record length也要40,不要会发生abend。
    Record format使用FB


Log in to reply
 

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