IBM i e-Book
A Developer’s Guide to Mastering IBM i Concepts
IBM i Index
Control Language (CL)
Handling Data Queues
Data Queues(*DTAQ) are the objects useful to carry out data transfer within a job or between multiple jobs. Once a data Queue is created, it can be utilized to send and receive data multiple times asynchronously.
Data Queues are mainly of 3 types:
- 1. Standard Data Queue(*STD): These data queues can mainly transfer data between different jobs and programs in a single IBM i system.
- 2. Distributed data management Data Queue(*DDM): These data queues are created for the scenarios when communication between two different IBM i systems is required.
- 3. Display Data Queue(*DSP): If a program wants to access data from a data queue while using display files then this data queue can be created. To make use of these data queues, we can specify the name of the data queue in the DTAQ parameter while creating a display file.
The sequence of storing and retrieving entries on a data queue is as follows:
- *FIFO (First-in, first-out): The entry sent first to the data queue will be retrieved first.
- *LIFO (First-in, first-out): The entry sent last to the data queue will be retrieved first.
- *KEYED: The sequence of retrieving the entries will depend on the key value.
Usage
There are multiple commands and APIs available in IBM i to create, delete and work with the data queues. Using Data Queue enhances the overall performance of an interactive program by reducing the response time.
Useful Commands
Commands available in IBM i to handle Data Queues:
- CRTDTAQ (Create Data Queue): This command will create a Data Queue object in particular library.
Command Syntax for *STD data queue:
CRTDTAQ DTAQ(*CURLIB/PIOSTDDTAQ)
TYPE(*STD)
MAXLEN(1000)
SEQ(*FIFO)
TEXT(‘STD DATA QUEUE')
Command Syntax for *DDM data queue:
CRTDTAQ DTAQ(*CURLIB/ PIODDMDTAQ)
TYPE(*DDM)
RMTDTAQ(LIBNAME/RMTDTAQ1)
RMTLOCNAME(*RDB)
RDB(RDBNAME)
TEXT(‘DDM DATA QUEUE')
Command Syntax for *DSP data queue:
CRTDTAQ DTAQ(*CURLIB/ PIODSPDTAQ)
TYPE(*DSP)
MAXLEN(100)
TEXT(‘DSP DATA QUEUE')
Important parameters of this command are as follows:
- 1. DTAQ:
Data queue: Describes the name of the data queue object to be created.
Library: Describes the library name in which the data queue object will be created. Its default value is *CURLIB (The current library of the job).
CALL PGM(QSNDDTAQ): This command will call an API ‘QSNDDTAQ’, through which we can send data to a data queue.
Command Syntax:
CALL PGM(QSNDDTAQ) PARM(<dataQueue> <Library> <LengthOfData> <Data>)
Example-
CALL PGM(QSNDDTAQ) PARM(‘PIODTAQ’ ‘PIOLIB’ ‘10’ ‘TEST DATA QUEUE’)
Important parameters of this command are as follows:
- 1. Data Queue: Describes the name of the data queue object to which data will be sent. This parameter data type is Char, and the length is 10.
- 2. Library: Describes the library name in which the data queue object is present. This parameter data type is Char, and the length is 10.
- 3. Length: Describes the length of the data to be sent. This parameter data type is Packed and length 5,0.
- 4. Data: Describes the data to be sent to the data queue. This parameter data type is Char.
CALL PGM(QRCVDTAQ): This command will call an API ‘QRCVDTAQ’, through which we can receive data to a data queue.
Command Syntax:
CALL PGM(QRCVDTAQ) PARM(<dataQueue> <Library> <Length> <Data> <waitTime>)
Example:
CALL PGM(QRCVDTAQ) PARM(‘PIODTAQ’ ‘PIOLIB’ ‘10’ ‘’ ‘0’)
Important parameters of this command are as follows:
- 1. Data Queue: Describes the name of the data queue object from which data will be received. This parameter data type is Char, and the length is 10.
- 2. Library: Describes the library name in which the data queue object is present. This parameter data type is Char, and the length is 10.
- 3. Length: Describes the length of the data to be received. This parameter data type is Packed, and the length is 5,0.
- 4. Data: This parameter will receive the data. Its data type is Char.
- 5. WaitTime: Describes the delay to be made while receiving data from a data queue. This parameter data type is Packed, and the length is 5,0.
Note: If WaitTime is -1, the data will be received from data queue as soon as it enters the data queue.
- DLTDTAQ (Delete Data Queue): This command will delete the Data Queue object present in particular library.
Command Syntax:
DLTDTAQ DTAQ(PIOLIB/PIODTAQ)
Restrictions
- – The maximum value for the MAXLEN parameter can be 64512.
- – Data queues can send and receive data of Character type only.
- – MAXLEN & SEQ parameter is not valid while creating a data queue of type *DDM.
- – A *DSP data queue cannot be created with the sequence as *KEYED.
Code Example:
The above code example is a CLLE program that creates a data queue of type *STD & sequence as *FIFO.
Then ‘QSNDDTAQ’ API is called to send the data to the PIODTAQ data queue.
We can send data to a single data queue multiple time. Data from the VAR1 variable is sent first & then data from the VAR2 variable is sent.
The second code example is a CLLE program that will receive the data from the data queue by calling the ‘QRCVDTAQ’ API.
When the ‘QRCVDTAQ’ API is called for the first time in the above program, data sent from VAR1 will be retrieved first & the same will be displayed while executing the SNDUSRMSG command for the first time.
When the ‘QRCVDTAQ’ API is called for the second time in the above program, data sent after VAR1, i.e. VAR2 will be retrieved & the same will be displayed while executing the SNDUSRMSG command for the second time.
This is because PIODTAQ will retrieve data in *FIFO sequence.