cobolmainframejcl

Error compiling COBOL program with sequential files


I have this COBOL program in my mainframe:

       IDENTIFICATION DIVISION.                                          
       PROGRAM-ID. TEST2.                                                
       ENVIRONMENT DIVISION.                                             
       INPUT-OUTPUT SECTION.                                             
       FILE-CONTROL.                                                     
           SELECT DATOS ASSIGN TO INPUTFL.                               
       DATA DIVISION.                                                    
       FILE SECTION.                                                     
       FD DATOS.                                                         
          01  REG-DAT.                                                   
              05  ID-LB           PIC 9(10).                             
              05  TITULO          PIC X(16).                             
              05  GEN-1           PIC X(8).                              
              05  GEN-2           PIC X(11).                             
              05  STOCK           PIC 99.                                
              05  FILLER          PIC X(33).                             
       WORKING-STORAGE SECTION.                                          
           01  FIN      PIC X VALUE 'N'.                                 
       PROCEDURE DIVISION.                                               
       1000-ABRIR.                                                       
           OPEN INPUT DATOS                                             
                PERFORM 2000-LEER UNTIL FIN = 'S'                       
           CLOSE DATOS                                                  
           STOP RUN.                                                    
       2000-LEER.                                                       
           READ DATOS                                                   
                AT END MOVE 'S' TO FIN                                  
                NOT AT END PERFORM 2100-MOSTRAR.                                                    
       2100-MOSTRAR.                                                    
           DISPLAY 'ID LIBRO: ' ID-LB.                                  
           DISPLAY 'TITULO: ' TITULO.                                   
           DISPLAY 'GENERO PRINCIPAL: ' GEN-1.                          
           DISPLAY 'GENERO SECUNDARIO: ' GEN-2.                         
           DISPLAY 'STOCK: ' STOCK.                                     
           DISPLAY '--------------------------------'.                             

Before testing it I must compile it but when I run the JCL it pops me a 0012 error. This is the JCL:

//HERC0101 JOB (COBOL),                                              
//             'COBOL COMPILATION',                                  
//             CLASS=A,                                              
//             MSGCLASS=H,                                           
//             REGION=8M,TIME=1440,                                  
//             NOTIFY=HERC01,                                        
//             MSGLEVEL=(1,1)                                        
//****************************************************************** 
//*                                                                  
//* THIS JOB HAS AS PURPOSE COMPILE THE COBOL CODE                   
//* PROCEDURE LOCATED @ SYS2.PROCLIB(COBOL)                          
//*                                                                  
//****************************************************************** 
//COMPILE  EXEC COBOL,                                               
//         PROG='TEST2',                                             
//         PDSF='MBVT.APPLICBC.SRC',                                 
//         PDSL='MBVT.APPLICBC.LOAD'                                 
/*                                                                   
//                                                                   

I've tried using another and simpler code, like this one:

       IDENTIFICATION DIVISION.     
       PROGRAM-ID. TEST2.            
       ENVIRONMENT DIVISION.        
       DATA DIVISION.               
       PROCEDURE DIVISION.          
           DISPLAY 'HOLA MUNDO!!'.  
           STOP RUN.                

And the JCL compiled it correctly, but with the other it showed me this error: IEF202I HERC0101 LKED COMPILE - STEP WAS NOT RUN BECAUSE OF CONDITION CODES The log shows all the procedure and after showing the code it shows this:

                                                                                
 6      IKF1155I-W     DEVICE CLASS INVALID IN SYSTEM-NAME. SKIPPING TO NEXT FIE
6      IKF1141I-W     FILE ORGANIZATION FIELD INVALID IN SYSTEM-NAME.  SEQUENTI
6      IKF1157I-E     EXTERNAL-NAME NOT PRESENT IN SYSTEM-NAME.                
6      IKF2133I-W     LABEL RECORDS CLAUSE MISSING. DD CARD OPTION WILL BE TAKE
27     IKF4052I-E     NOT    MAY NOT BE TARGET FIELD FOR ALPHANUMERIC LITERAL  
                      AND IS DISCARDED.                                        
27     IKF4052I-E     AT    MAY NOT BE TARGET FIELD FOR ALPHANUMERIC LITERAL  (
                      AND IS DISCARDED.                                        
27     IKF4052I-E     END    MAY NOT BE TARGET FIELD FOR ALPHANUMERIC LITERAL  
                      AND IS DISCARDED.                                        
28     IKF4072I-W     EXIT FROM PERFORMED PROCEDURE ASSUMED BEFORE PROCEDURE-NA
                                                                                

Solution

  • NOT AT END was added with COBOL85, so that may not be available on very old emulators.
    The compiler then applies these to the MOVE statement with multiple targets as if you have coded

            MOVE 'S' TO FIN
            MOVE 'S' TO NOT
            MOVE 'S' TO AT
            MOVE 'S' TO END
    

    and therefore outputs IKF4052I-E on that line three times

    NOT    MAY NOT BE TARGET FIELD FOR ALPHANUMERIC LITERAL AND IS DISCARDED.
    AT     MAY NOT BE TARGET FIELD FOR ALPHANUMERIC LITERAL AND IS DISCARDED.
    END    MAY NOT BE TARGET FIELD FOR ALPHANUMERIC LITERAL AND IS DISCARDED.
    

    If you really need to use that ancient compiler recode the READ as follows:

               READ DATOS                                                   
                    AT END MOVE 'S' TO FIN.                                 
               IF FIN NOT = 'S'                                             
                  PERFORM 2100-MOSTRAR.                                     
    

    As Kolusu pointed out, you need a device class "UT" utility device = disk and organization identifier "S" sequential:

           FILE-CONTROL.                                                     
               SELECT DATOS ASSIGN TO UT-S-INPUTFL.                            
    

    To fix the label records warning change the FD to read:

           FD DATOS LABEL RECORDS ARE STANDARD.                              
    

    In any case you should start the level 01 in col 8-11, so move the FIN declaration at least one column left:

           WORKING-STORAGE SECTION.                                          
              01  FIN      PIC X VALUE 'N'.                                  
    

    To fix the last warning you may try to add the following:

           2095-LEER-EX.                                                    
               EXIT.