Example: Find the queries that accessed a specific file

This example illustrates how to find queries that accessed a specified file.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
GETQRY
              PGM        PARM(&LIBRARY &FILE)                            
              DCL        VAR(&LIBRARY) TYPE(*CHAR) LEN(10)               
              DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)                  
              DCLF       FILE(QTEMP/QRYOBJS)                             
              DLTF       FILE(QTEMP/QRYOBJS)                             
              MONMSG     CPF0000                                         
              DLTF       FILE(QTEMP/&LIBRARY)                            
              MONMSG     CPF0000                                         
 CRTSRCPF   FILE(QTEMP/&LIBRARY)                            
  DSPOBJD    OBJ(&LIBRARY/*ALL) OBJTYPE(*QRYDFN) +           
                           DETAIL(*FULL) OUTPUT(*OUTFILE) +       
                            OUTFILE(QTEMP/QRYOBJS)                        
   BEGIN:   RCVF      /* GET QUERY NAME AND LIBRARY NAME */            
                  /* IF END OF FILE REACHED, EXIT LOOP        */ 
             MONMSG   CPF0864  EXEC(GOTO EOF)                           
 RTVQMQRY   QMQRY(&OLDBNM/&ODOBNM) +                        
                                    SRCFILE(QTEMP/&LIBRARY) ALWQRYDFN(*ONLY)      
          GOTO       CMDLBL(BEGIN)                                   
 EOF:    FNDSTRPDM  STRING(&FILE) FILE(QTEMP/&LIBRARY) 
 MBR(*ALL)  OPTION(*NONE) PRTMBRLIST(*YES)                
             ENDPGM            
Note: To create an output file in QTEMP, use the Display Object Description (DSPOBJD) command. While in programming development manager (PDM), press CMD18 to change defaults, and change the Compile in Batch option to N. Compile GETQRY. Then set the compile option default back to Y.
GETQRYPRM
              PGM        PARM(&LIBRARY &FILE)                            
              DCL        VAR(&LIBRARY) TYPE(*CHAR) LEN(10)               
              DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)                  
              SBMJOB     CMD(CALL PGM(GETQRY) PARM(&LIBRARY &FILE))      
              ENDPGM                                                    
 

Compile program GETQRYPRM.