search results

Devel(UP) Your Skills

Wednesday, April 7, 2021

Retrieve list of Open files for a Job from SQL - IBM i

 

Retrieve list of Open files for a Job from SQL - IBM i


The list of open files for a job can be seen by using the command WRKJOB (Work with Job) or DSPJOB (Display Job) and then by taking option '14'. Or, by using the API 'QDMLOPNF' (List Open Files). 

One other easier way to do this is from SQL by using the table function OPEN_FILES. 

This function accepts a single parameter 'Job Name'.

Job Name (JOB_NAME) - Name of the job (qualified) for which the list of open files are to be retrieved. If current job, '*' can be passed instead of the job name. 

One thing to note here is 'Job Control (*JOBCTL)' authority is required to retrieve the list of files opened by other user's jobs. And, no special authority is required to retrieve our own jobs. 

One advantage of having SQL table function to retrieve the the list of open files based on the specific condition as required. 

E.g.: 
  • Retrieve the list of open physical files.        
Retrieve list of open files from SQL - IBM i
  • Retrieve the list of files opened in OUTPUT mode. 
Retrieve list of open files from SQL - IBM i
  • Retrieve the current RRN number of a specific file opened. 
Retrieve list of open files from SQL - IBM i

and much more as required. 

Below are the some of the key columns present in this table function. 

Library Name (LIBRARY_NAME) - Name of the library that contains the open file.


File Name (FILE_NAME) - Name of the open file.


File Type (FILE_TYPE) - Type of the open file. Below are the valid file types.

  • BSCF - Binary Synchronous Communications (BSC) file
  • CMNF - Communications file
  • DDMF - Distributed Data Management file
  • DKTF - Diskette file (spooled and non-spooled)
  • DSPF - Display file
  • ICFF - Intersystem Communications Function file
  • LF - Logical file
  • MXDF - Mixed file
  • PF - Physical file 
  • PRTF - Printer file (spooled and non-spooled)
  • SAVF - Save file
  • TAPF - Tape file
  • *INLINE - Inline data file

Member Name (MEMBER_NAME) - Name of the database member, If FILE_TYPE is physical (PF) or logical (LF). If multiple member processing is being performed, the value is *ALL.


Record Format (RECORD_FORMAT) - Name of the last record format that was used for an I/O operation to the file.


Activation Group Name (ACTIVATION_GROUP_NAME) - Name of the activation group to which the open file is scoped.

  • *DFTACTGRP - The file is scoped to the default activation group.
  • *NEW - The file is scoped to a *NEW activation group.
  • Contains the null value for a file scoped to the job, not a specific activation group.


Thread ID (THREAD_ID) - Thread handle assigned by the system which identifies the thread in which the file was opened.


Open Option (OPEN_OPTION) - Type of open operation that was performed.

  • ALL - The file was opened for all operations (input, output, update, and delete).
  • INPUT - The file was opened for input operations only.
  • OUTPUT - The file was opened for output operations only.


RRN (RELATIVE_RECORD_NUMBER) - Relative record number of the last record referred to by an I/O or open operation for database files.


For full list of columns present in this table have a look at this link


*This function is only available since IBM i 7.3 TR9 and IBM i 7.4 TR3.

No comments:

Country calling code