Querying data queues with QMHQRDQD

Someone recently asked me if I knew of an API that could be used to retrieve the number of entries in a data queue without pulling the entries from the data queue.

I didn’t, but a quick search turned up QMHQRDQD.:

The Retrieve Data Queue Description (QMHQRDQD) API retrieves the description and attributes of a data queue. Examples include the number of entries currently on the data queue, the text description of the data queue, whether the queue includes sender ID information, and whether the data queue is keyed.

The attributes of a distributed data management (DDM) data queue can be retrieved with this API.

So here’s an example of the QMHQRDQD api in action.

       // --------------------------------------------------------------------
       // Program     : DSPDTAQSIZ
       // Description : Retrieve data queue size
       // --------------------------------------------------------------------
        ctl-opt main(Main) dftactgrp(*no) actgrp(*new) bnddir('QC2LE');

       // --------------------------------------------------------------------
       // Prototype declarations
       // --------------------------------------------------------------------
        dcl-pr Main extpgm('DSPDTAQSIZ');
            DTAQ Char(10) const;
            DTAQLIB char(10) const;
        end-pr;


        dcl-pr GetDtaqD extpgm('QMHQRDQD');
            RtnVariable char(2000) Options(*VarSize);
            RtnVarLen int(10) const;
            Format char(8) const;
            QDTAQ char(20) const;
        end-pr;

       // --------------------------------------------------------------------
       // Main Procedure
       // --------------------------------------------------------------------
        dcl-proc Main;

            dcl-pi Main;
                DTAQ Char(10) const;
                DTAQLIB char(10) const;
            end-pi;

           // ----------------------------------------------------------------
           // Data structures
           // ----------------------------------------------------------------
            dcl-ds F1 qualified inz;
                BytesRtn int(10);
                BytesAvail int(10) inz(%size(F1));
                Max_Len int(10);
                Key_Len int(10);
                Q_Seq char(1);
                Sender_ID char(1);
                Force_Write char(1);
                TextDesc char(50);
                DtaQ_Type char(1);
                Auto_Rcl char(1);
                Reserved1 char(1);
                Cur_Msgs int(10);
                CurEntry_Cap int(10);
                DtaQName char(10);
                DtaQLib char(10);
                Max_Entry int(10);
                Init_Entry int(10);
            end-ds;

           // ----------------------------------------------------------------
           // Standalone fields
           // ----------------------------------------------------------------
            dcl-s QualDtaQ char(20);
            dcl-s OutText char(30);
        
           // ----------------------------------------------------------------
           // Procedure mainline
           // ----------------------------------------------------------------
            
            // Qualified Data queue name is Data Queue Name + Library
            QualDtaQ = DTAQ + DTAQLIB;

            // Retrieve the data queue description
            GetDtaQD(F1: %size(F1): 'RDQD0100' : QualDtaQ );

            OutText = 'Current Messages: ' + %trim(%char(F1.Cur_Msgs));
            dsply OutText;

        end-proc;   
       // --------------------------------------------------------------------

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.