How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

IBM i e-Book

A Developer’s Guide to Mastering IBM i Concepts

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. 1. Standard Data Queue(*STD): These data queues can mainly transfer data between different jobs and programs in a single IBM i system.
  2. 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. 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:

  1. *FIFO (First-in, first-out): The entry sent first to the data queue will be retrieved first.
  2. *LIFO (First-in, first-out): The entry sent last to the data queue will be retrieved first.
  3. *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. 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).   

  • 2. TYPE: Describes the type of the data queue object. The possible values of this parameter are: *STD, *DDM, *DSP.  Its default value is *STD.
  • 3. MAXLEN: Describes the maximum length of the data that can be sent in a data queue. A data queue of type *STD & *DSP cannot be created without giving this parameter value.
  • 4. SEQ: Describes the sequence in which data will be sent and retrieved in a data queue. The possible values of this parameter are: *FIFO, *LIFO, *KEYED.  Its default value is *FIFO.
  • 5. TEXT:  Describes the text description for the data queue object.
  • 6. RMTDTAQ: Describes the remote data queue name on the target system for the *DDM data queue.
  •   Library: If the library name is not specified *LIBL is taken as default value.
  • 7. RMTLOCNAME: Describes the remote system name in which the target data queue is located. *RDB is also a valid value for this parameter.
  • 8. RDB: Describes the relational database entry. This parameter is required when *RDB is specified in the RMTLOCNAME parameter.
  • 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. 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. 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. 3. Length: Describes the length of the data to be sent. This parameter data type is Packed and length 5,0.
    4. 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. 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. 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. 3. Length: Describes the length of the data to be received. This parameter data type is Packed, and the length is 5,0.
    4. 4. Data: This parameter will receive the data. Its data type is Char.
    5. 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

    1. – The maximum value for the MAXLEN parameter can be 64512.
    2. – Data queues can send and receive data of Character type only.
    3. – MAXLEN & SEQ parameter is not valid while creating a data queue of type *DDM.
    4. – 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.

    How can we help you?

    We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

    X

    Awards and Certifications

    company-logo
    company-logo
    company-logo
    company-logo
    company-logo
    company-logo
    company-logo
    company-logo
    company-logo
    company-logo