Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Read data from data queue using QRCVDTAQ api in RPG AS400

Read data from data queue using QRCVDTAQ api in RPG AS400
Read data  from data queue using QRCVDTAQ api in RPG AS400, data queue, DTAQ, QRCVDTAQ, receive data queue,  data queue in as400, read data from data queue in RPGLE, introduction, about, what, what is, as400,ibmi
Read data  from data queue using QRCVDTAQ API in RPG AS400

Receive Data Queue (QRCVDTAQ) API

The Receive Data Queue (QRCVDTAQ) API receives data from the specified data queue.

A data queue entry sent to the data queue is received by only one prorgram at a time even if multiple program are waiting for the entry.

We can use QRCVDTAQ API to receive data from the DDM data queues as well which is located on the remote system.

Technically speaking, when a Job uses this API a cache is created to allow faster access to the Data queue.

Required Parameters

  1. Data Queue Name: Input parm and Char(10)
  2. Library Name: Input parm and Char(10)
  3. Length of Data: Output parm and Packed(5,0)
  4. Data: output parm and Char(*)
  5. Wait Time: input parm and Packed(5,0)

There are some optional parameters as well which are discussed here in this blog.

Coding QRCVDTAQ API in RPGLE Fixed, /Free and Fully Free format

RPG Code in Fixed format for Reading data from data queue using QRCVDTAQ api in RPG AS400
     D main            pr                  extpgm('EXTPGM5')   
     D                               10a                       
     D                               10a                       
     D                               20a                       
     D main            pi                                      
     D dtquenam                      10a                       
     D dtquelib                      10a                       
     D receive                       20a                       
     D len             s              5P 0 inz                 
     D waittime        s              5p 0 inz(10)             
                                                               
     C                   EVAL      receive = ' '               
     C                   CALL      'QRCVDTAQ'                  
     C                   PARM                    dtquenam      
     C                   PARM                    dtquelib      
     C                   PARM                    len           
     C                   PARM                    receive       
     C                   PARM                    waittime      
     C     RECEIVE       DSPLY                                 
     C     LEN           DSPLY                                             
     C                   SETON                                        LR   
     C                   RETURN                                                                                                      
RPG Code in /Free format for Reading data from data queue using QRCVDTAQ api in RPG AS400
     D QRCVDTAQ        PR                  extpgm('QRCVDTAQ')      
     D dtquenam                      10A   const                   
     D dtquelib                      10A   const                   
     D datalen                        5P 0 const                   
     D databuf                    32767A   const options(*varsize) 
     D waittime                       5P 0 const                   
                                                                   
     D main            pr                  extpgm('EXTPGM6')       
     D                               10a                           
     D                               10a                           
     D                               20a                           
     D main            pi                                          
     D dtquenam                      10a                           
     D dtquelib                      10a                           
     D receive                       20a                           
     D len             s              5P 0 inz                     
     D waittime        c                   const(10)               
      /Free                                                        
        receive = ' ';                                             
         QRCVDTAQ(dtquenam:dtquelib:len:receive:waittime);   
         dsply receive;
         dsply len;                                                    
         *INLR = *ON;                                        
         return;                                             
       /End-Free                                                                                                                                                                                                      
RPG Code in fully Free format for Reading data from data queue using QRCVDTAQ api in RPG AS400
**FREE                                              
dcl-pr QRCVDTAQ extpgm ;                            
  *n char(10) const;                                
  *n char(10) const;                                
  *n packed(5:0) const;                             
  *n char(32767) const options(*varsize);        
  *n packed(5:0) const;    
end-pr;                                             
                                                    
dcl-pi *N;                                          
  dtquenam char(10);                                
  dtquelib char(10);                                
  receive char(20);                                    
end-pi;                 

dcl-s len packed(5:0) inz;
dcl-c waittime const(10);
   
receive = ' ';                                                                                  
QRCVDTAQ(dtquenam:dtquelib:len:receive:waittime);  
DSPLY receive; 
DSPLY len;                                                         
*INLR = *ON;                                        
return;                                                                                                             

Compile the program EXTPGM6 using option 14 against the SQLRPGLE source member or using the command CRTSQLRPGI.

Execute the QRCVDTAQ code

For testing the above code, we first need to create the data queue and some program using QSNDDTAQ to send entry to data queue using the below link.

Create Data Queue and send entry to Data Queue using QSNDDTAQ API
CALL PGM(EXTPGM6) PARM('DATAQUEUE1' 'EASYCLASS1' ' ')

Data being read from the data queue named DATAQUEUE1 and displyed the data and its length.

DSPLY  HELLO WORLD 
DSPLY     11       

Related Post

Data Queue in AS400
Write data to data queue using QSNDDTAQ API in RPG AS400

Post a Comment

© AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain