FILE STATUS 47 - COBOL-DB2 PROGRAM



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

FILE STATUS 47 - COBOL-DB2 PROGRAM

Postby Sandeep1311 » Sun May 31, 2020 12:23 pm

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.
Sandeep1311
 
Posts: 6
Joined: Mon Apr 13, 2020 6:44 am
Has thanked: 1 time
Been thanked: 0 time

Re: FILE STATUS 47 - COBOL-DB2 PROGRAM

Postby NicC » Sun May 31, 2020 6:41 pm

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
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: FILE STATUS 47 - COBOL-DB2 PROGRAM

Postby Sandeep1311 » Sun May 31, 2020 7:38 pm

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.          
Sandeep1311
 
Posts: 6
Joined: Mon Apr 13, 2020 6:44 am
Has thanked: 1 time
Been thanked: 0 time

Re: FILE STATUS 47 - COBOL-DB2 PROGRAM

Postby Robert Sample » Tue Jun 02, 2020 7:21 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post