IBM Support

Example of the QRCVDTAQ and QSNDDTAQ API in CL

Troubleshooting


Problem

This document provides an example of a CL program that calls the QRCVDTAQ and QSNDDTAQ APIs.

Resolving The Problem

Following is an example of a CL program that is calling the QRCVDTAQ and QSNDDTAQ APIs. Use the CRTDTAQ command to create a data queue if one does not currently exist. For this example, you would want the data queue name to be FILEINFO in library QGPL and the MAXLEN set to 100.

Example
 
             PGM                                                     
             /* Data queue and library */                            
             DCL        VAR(&DQNAME) TYPE(*CHAR) LEN(10) +           
                          VALUE('FILEINFO')                          
             DCL        VAR(&DQLIB) TYPE(*CHAR) LEN(10) VALUE('QGPL')
             /* QSNDDTAQ parameters */                               
             DCL        VAR(&DQSNDLEN) TYPE(*DEC) LEN(5 0) VALUE(14) 
             DCL        VAR(&DQSNDDATA) TYPE(*CHAR) LEN(100)         
             /* QRCVDTAQ parameters */                               
             DCL        VAR(&DQLEN) TYPE(*DEC) LEN(5 0)              
             DCL        VAR(&DQDATA) TYPE(*CHAR) LEN(100)            
             DCL        VAR(&DQWAIT) TYPE(*DEC) LEN(5 0) VALUE(0)    
                                                                     
             CHGVAR     VAR(&DQSNDDATA) VALUE('THIS IS A TEST')      
                                                                     
             CALL       PGM(QSNDDTAQ) PARM((&DQNAME) (&DQLIB) +      
                          (&DQSNDLEN) (&DQSNDDATA))                  
                                                                     
             CALL       PGM(QRCVDTAQ) PARM((&DQNAME) (&DQLIB) +      
                          (&DQLEN) (&DQDATA) (&DQWAIT))              
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&DQDATA) 
             ENDPGM                                                  
With IBM i 7.3 and up, the DTAQ APIs have been exposed via SQL function calls:
 
You should find example SQL Scripts in ACS Run SQL Scripts function under Edit -> Examples -> Insert from Examples...
Here is a DDM data queue example:
-- create a _DDM_ data queue on the local system which points to a remote IBM i:
cl: CRTDTAQ DTAQ(MYLIB/ddmdataq) TYPE(*DDM) RMTDTAQ(MYRMTLIB/INPUT) 
RMTLOCNAME(*RDB) RDB(MyRMTSYS) TEXT('DDM data queue to access DATAQ INPUT on remote sys');
stop;

--On the DDM target system (MyRMTSYS), create a standard data queue:
--CRTDTAQ DTAQ(MYRMTLIB/INPUT) MAXLEN(128);

-- review the state and status of the data queue
select *
  from qsys2.data_queue_info
  where data_queue_library = 'MYLIB';
stop;

-- Send a (character) message to the data queue. data_queue and library are CaSe SeNsItIvE
call qsys2.send_data_queue(
  message_data       => 'Hello World... today is ' concat current date, 
  data_queue         => 'DDMDATAQ',
  data_queue_library => 'MYLIB');
stop;

-- Retrieve the message from the data queue. Once retrieved, it is no longer on the queue. 
select *
  from table (
      qsys2.receive_data_queue(
        data_queue => 'DDMDATAQ', data_queue_library => 'MYLIB')
    );

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p0000006x8GAAQ","label":"CL"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

353981239

Document Information

Modified date:
10 December 2024

UID

nas8N1015880