Skip to main content

View Job Queue Info from SQL - IBM i

Job Queue

Dealing with Job Queues (JOBQ) is part of day to day life when working with IBM i. There comes many situations where we need to check if a JOBQ is Held or Released, Which subsystem the JOBQ is attached to, No of active/held/released/scheduled jobs in JOBQ, Maximum number of active jobs etc. 

Different commands (WRKJOBQ, WRKJOBQD, WRKSBSD) are available to view this information. 

There is another easier way to access this information is by using SQL view JOB_QUEUE_INFO in QSYS2 (system name - JOBQ_INFO). 

One thing to note is, User should either have read authority to the JOBQ or have one of the special authorities *JOBCTL, *SPLCTL.

This view is helpful in many different ways like, 
  • List of Job queues present in a library. 
  • List of Job queues HELD/RELEASED in a library.
  • Retrieve Subsystem a JOBQ is attached to. 
  • List of Job queues in a Subsystem. 
  • Retrieve maximum number of active jobs in a Job queue. 
  • Retrieve number of Active/Held/Released/Scheduled jobs in a Job queue. 
E.g.:

List of Job queues present in a library. 

SELECT * FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY'

List of Job queues HELD/RELEASED in a library.

SELECT * FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_STATUS = 'RELEASED'

Retrieve Subsystem a JOBQ is attached to. 

SELECT SUBSYSTEM_NAME, SUBSYSTEM_LIBRARY_NAME FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_NAME = 'TESTJOBQ'

List of Job queues in a Subsystem. 

SELECT * FROM QSYS2/JOB_QUEUE_INFO WHERE SUBSYSTEM_NAME = 'TESTSBS' AND SUBSYSTEM_LIBRARY_NAME = 'PREDDY'

Retrieve maximum number of active jobs in a Job queue. 

SELECT MAXIMUM_ACTIVE_JOBS FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_NAME = 'TESTJOBQ' 

Retrieve number of Active/Held/Released/Scheduled jobs in a Job queue. 

SELECT ACTIVE_JOBS, HELD_JOBS, RELEASED_JOBS, SCHEDULED_JOBS FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_NAME = 'TESTJOBQ' 

In addition to these number of active/held/released/scheduled job information by priority can be found. 

Below are the important columns present in this view. 

JOB_QUEUE_NAME (JOBQ) - The name of the job queue.

JOB_QUEUE_LIBRARY (JOBQ_LIB) - The name of the library that contains the job queue.

JOB_QUEUE_STATUS (STATUS) - The status of the job queue. HELD (The queue is held), RELEASED (The queue is released)

NUMBER_OF_JOBS (JOBS) - The number of jobs in the queue.

SUBSYSTEM_NAME  (SUB_NAME) - The name of the subsystem that can receive jobs from this job queue. Contains the null value if this job queue is not associated with an active subsystem.

SUBSYSTEM_LIBRARY_NAME (SUBLIB_NAM) - The library in which the subsystem description resides. Contains the null value if this job queue is not associated with an active subsystem.

SEQUENCE_NUMBER (SEQNO) - The job queue entry sequence number. The subsystem uses this number to determine the order in which job queues are processed. Jobs from the queue with the lowest sequence number are processed first. Contains the null value if this job queue is not associated with an active subsystem.

MAXIMUM_ACTIVE_JOBS (MAX_JOBS) - The maximum number of jobs that can be active at the same time through this job queue entry. A value of -1 indicates *NOMAX, no maximum number of jobs is defined. Contains the null value if this job queue is not associated with an active subsystem.

ACTIVE_JOBS (ACT_JOBS) - The current number of jobs that are active that came through this job queue entry. Contains the null value if this job queue is not associated with an active subsystem.

HELD_JOBS (HELD_JOBS) - The current number of jobs that are in *HELD status. 

RELEASED_JOBS (RLS_JOBS) - The current number of jobs that are in *RELEASED status. 

SCHEDULED_JOBS (SCHED_JOBS) - The current number of jobs that are in *SCHEDULED status. 

TEXT_DESCRIPTION (TEXT) - Text that describes the job queue. Contains the null value if there is no text description for the job queue.

OPERATOR_CONTROLLED (OPR_CTRL) - Whether users with job control authority are allowed to control this job queue and manage the jobs on the queue. Users have job control authority if SPCAUT(*JOBCTL) is specified in their user profile. *NO - This queue and its jobs cannot be controlled by users with job control authority unless they also have other special authority. *YES - Users with job control authority can control the queue and manage the jobs on the queue.

AUTHORITY_TO_CHECK (ALL_AUTH) - Whether the user must be the owner of the queue in order to control the queue by holding or releasing the queue. *DTAAUT - Any user with *READ, *ADD, or *DELETE authority to the job queue can control the queue. *OWNER - Only the owner of the job queue can control the queue.


If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form. 

Comments

Popular posts from this blog

All about READ in RPGLE & Why we use it with SETLL/SETGT?

READ READ is one of the most used Opcodes in RPGLE. As the name suggests main purpose of this Opcode is to read a record from Database file. What are the different READ Opcodes? To list, Below are the five Opcodes.  READ - Read a Record READC - Read Next Changed Record READE - Read Equal Key Record READP - Read Prior Record READPE - Read Prior Equal Record We will see more about each of these later in this article. Before that, We will see a bit about SETLL/SETGT .  SETLL (Set Lower Limit) SETLL accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Corresponding Record (or Next Record if exact match isn't found).  SETGT (Set Greater Than) SETGT accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Next Record (Greater Than the Key value). Syntax: SETLL SEARCH-ARGUMENTS/KEYFIELDS FILENAME SETGT  SEARCH-ARGUMENTS/KEYFIELDS FILENAME One of the below can be passed as Search Arguments. Key Fiel

What we need to know about CHAIN (RPGLE) & How is it different from READ?

CHAIN READ & CHAIN, These are one of the most used (& useful) Opcodes by any RPG developer. These Opcodes are used to read a record from file. So, What's the difference between CHAIN & READ?   CHAIN operation retrieves a record based on the Key specified. It's more like Retrieving Random record from a Database file based on the Key fields.  READ operation reads the record currently pointed to from a Database file. There are multiple Opcodes that start with READ and all are used to read a record but with slight difference. We will see more about different Opcodes and How they are different from each other (and CHAIN) in another article. Few differences to note.  CHAIN requires Key fields to read a record where as READ would read the record currently pointed to (SETLL or SETGT are used to point a Record).  If there are multiple records with the same Key data, CHAIN would return the same record every time. READE can be used to read all the records with the specified Ke

Extract a portion of a Date/Time/Timestamp in RPGLE - IBM i

%SUBDT Extracting Year, Month, Day, Hour, Minutes, Seconds or Milli seconds of a given Date/Time/Timestamp is required most of the times.  This can be extracted easily by using %SUBDT. BIF name looks more similar to %SUBST which is used to extract a portion of string by passing from and two positions of the original string. Instead, We would need to pass a value (i.e., Date, Time or Timestamp ) and Unit (i.e., *YEARS, *MONTHS, *DAYS, *HOURS, *MINUTES, *SECONDS or *MSECONDS) to %SUBDT.  Valid unit should be passed for the type of the value passed. Below are the valid values for each type. Date - *DAYS, *MONTHS, *YEARS Time - *HOURS, *MINUTES, *SECONDS Timestamp - *DAYS, *MONTHS, *YEARS, *HOURS, *MINUTES, *SECONDS, *MSECONDS Syntax: %SUBDT(value : unit { : digits { : decpos} }) Value and Unit are the mandatory arguments.  Digits and Decimal positions are optional and can only be used with *SECONDS for Timestamp. We can either pass the full form for the unit or use the short form. Below i