Page 1 of 1

FILE STATUS 47 - COBOL-DB2 PROGRAM

PostPosted: Sun May 31, 2020 12:23 pm
by Sandeep1311
Hi,

I am trying to run a COBOL-DB2 program, to get employee data from the database, on which computation is done to find total salary.

in this, the COBOL program takes a single input from PS Dataset and passes it to where the condition of the cursor, for each record from the cursor computes the total salary and writes in an output PS Dataset.

while execution I am facing a file status code 47 while trying to read the input dataset.

PC(Precompilier)
COBOL(compilier)
LKED(link)
BIND is fine during the run.

COBOL code:

File control:

FILE-CONTROL.                                
*                                            
     SELECT DEPTFILE ASSIGN TO DEPTFILE      
         ACCESS IS SEQUENTIAL                
         FILE STATUS  IS  WS-DEPTFILE-STATUS.
*                                            
     SELECT EMPRPT ASSIGN TO EMPRPT          
        ACCESS IS SEQUENTIAL                  
         FILE STATUS  IS  WS-EMPRPT-STATUS.  


100-OPEN-FILES.                                  
      OPEN INPUT DEPTFILE                        
           OUTPUT EMPRPT.                        
*                                                
 110-READ-INPUT-FILE.                            
*                                                
      READ DEPTFILE.                              
        DISPLAY "FILE STATUS" WS-DEPTFILE-STATUS.
        DISPLAY "WORK-DEPT" WORK-DEPT            
         IF WS-DEPTFILE-STATUS = 0                
           MOVE WORK-DEPT TO WS-WORK-DEPT        
           PERFORM 200-PROCESS-CURSOR.            

JCL code:

//BIND     EXEC PGM=IKJEFT01                          
//STEPLIB  DD DSN=DSNC10.SDSNLOAD,DISP=SHR            
//         DD DISP=SHR,DSN=&SYSUID..LOAD(CBLDB21)      
//DBRMLIB  DD DSN=&SYSUID..DBRMLIB(CBLDB21),DISP=SHR  
//SYSUDUMP DD DUMMY                                    
//SYSTSPRT DD SYSOUT=*                                
//SYSPRINT DD SYSOUT=*                                
//SYSTSIN  DD *                                        
  DSN SYSTEM(DBCG)                                    
  RUN PROGRAM(CBLDB21) PLAN(CBLDB21)                  
  END                                                  
//SYSIN    DD *                                                                        
//*****************************************************
//*  EXECUTE DB2 PROGRAM                              
//*****************************************************
//CBLRUN   EXEC PGM=CBLDB21                            
//STEPLIB  DD DSN=&SYSUID..LOAD(CBLDB21),DISP=SHR      
//                                                    
//SYSPRINT DD SYSOUT=*                                
//* INPUT  FILE                                        
//DEPTFILE DD DSN=Z56117.EMPLOYEE.DEPT,DISP=SHR        
//* OUTPUT FILE                                        
//EMPRPT   DD DSN=Z56117.EMPLOYEE.DEPT.REPORT,DISP=OLD
//SYSOUT   DD SYSOUT=*      


please advice.

Re: FILE STATUS 47 - COBOL-DB2 PROGRAM

PostPosted: Sun May 31, 2020 6:41 pm
by NicC
1) check your file status after EVERY file action including OPEN
2) Read the documentation to find out what a file status of 47 means - a google with 'cobol file status 47' should get uo there or even locating the documentation via the link on this page

Re: FILE STATUS 47 - COBOL-DB2 PROGRAM

PostPosted: Sun May 31, 2020 7:38 pm
by Sandeep1311
On Open DEPTFILE
it has file status as 35, but the file is cataloged and defined in the system.

//DEPTFILE DD DSN=Z56117.EMPLOYEE.DEPT,DISP=SHR                                      
//EMPRPT   DD DSN=Z56117.EMPLOYEE.DEPT.REPORT,DISP=SHR


       100-OPEN-FILES.                                        
       *                                                      
             OPEN INPUT DEPTFILE.                              
             OPEN OUTPUT EMPRPT.                              
       *                                                      
               DISPLAY "FILE STATUS OPEN" WS-DEPTFILE-STATUS.  
               DISPLAY "FILE STATUS OPEN" WS-EMPRPT-STATUS.    
       *                                                      
        100-OPEN-FILES-EX.                                    
            EXIT.          

Re: FILE STATUS 47 - COBOL-DB2 PROGRAM

PostPosted: Tue Jun 02, 2020 7:21 pm
by Robert Sample
The Enterprise COBOL Language Reference manual says for file status 35:
An OPEN statement with the INPUT, I-O, or EXTEND phrase was attempted on a nonoptional file that was unavailable.
So while you say
it has file status as 35, but the file is cataloged and defined in the system.
the system is telling you that the cataloged / defined data set you think you are using is not the file COBOL is attempting to use. Until and unless you resolve the file status 35, you will continue to get file status 47 on every attempt to use the file in your program.

And why are you not checking for a valid open in your code? For a sequential file in COBOL, if the OPEN file status is not 00 then you need to abort your program and figure out why you cannot access the data set. For VSAM data sets, file status 02 and 97 can also indicate successful opens but any other code means the program isn't going to work and again you need to stop the code without attempting to use the file and figure out what is going on.

Looking at what you posted, the following lines should NOT be in your execution JCL:
//SYSIN    DD *                                                                        
//*****************************************************
//*  EXECUTE DB2 PROGRAM                              
//*****************************************************
//CBLRUN   EXEC PGM=CBLDB21                            
//STEPLIB  DD DSN=&SYSUID..LOAD(CBLDB21),DISP=SHR      
//  
The last line, in particular, indicates that your JCL is complete. Hence your //DEPTFILE and //EMPRPT DD statements are not accessible to the program. So, as the file status 35 indicates, you did not provide a DD reference for DEPTFILE when the program attempted to open it.