895 pts.
 data queue
Hi,

I want to write programs which will read from a data queue a string of bytes delimited by '|' and update the database. how to achieve this..this is the first time i'm dealing with data queues...

Thanks,

Nutan



Software/Hardware used:
AS400
ASKED: August 31, 2009  3:32 PM
UPDATED: September 4, 2009  2:45 PM

Answer Wiki:
In your RPG Program call a program QRcvDtaQ Call 'QRcvDtaQ' Parm qname <-- 10 Parm qlib <-- 10 Parm flen <-- 5p 0 -- length of RcvFQ Parm RcvFQ <----- actual character field to receive queue value width = width of queue parm WaitQ <-- 5p 0 number of seconds to wait for entry on Queue negative value wait forever 0 do not wait postive value wait nn seconds If the data queue is "keyed" which means that you only want to get entries with a specific key value then there are more parameters. When you rcv an entry it is removed from the queue. You will then need to parse the character string. Phil --------------------- You're saying the dataqueue is keyed on the timestamp???? Then you would have to have the timestamp inorder to retrieve the entry. Keyed fields are added below Call 'QRcvDtaQ' Parm qname <-- 10 Parm qlib <-- 10 Parm flen <-- 5p 0 -- length of RcvFQ Parm RcvFQ <----- actual character field to receive queue value width = width of queue parm WaitQ <-- 5p 0 number of seconds to wait for entry on Queue negative value wait forever 0 do not wait postive value wait nn seconds parm krule 'EQ' parm klen 3 P0 length of key parm keyval KeyValue parm SdrLen 3p 0 - length of sender data to capture parm SdrVal includes sender job name, user, number, user Prf ------------- You could write a short program calling QSndDtaQ ------------------- One more time .. keyed by timestamp?? -- keying a dataqueue isn't to put the data in a specific order but providing a tool for extracting specific entries from the queue. To extract an entry from your queue your program will need to get the timestamp value somehow before it attempts to receive the entry. If you want a queue which delivers the data in entry sequence create it as *FIFO not keyed!!! Phil ------------ I think Teandy links were www.itjungle.com/mpo/mpo052302-story02.html www.itjungle.com/mpo/mpo052302-story05.html http://tutorialindia.com/articles/as400/data_queue.php Phil
Last Wiki Answer Submitted:  September 3, 2009  6:03 pm  by  philpl1jb   44,630 pts.
All Answer Wiki Contributors:  philpl1jb   44,630 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

I am assuming since the data is delimited, the data will be of varying length ?

I’ve never tried it myself, but as Phil says, you probably need to read it in as a single record and parse it by the delimiter. Let me know how this works,

 1,245 pts.

 

thanks Phil. yes it is keyed data…timestamp is the key…
i have to use stored procedure interface for update.

 895 pts.

 

Thanks…the next question is how to test this kinda programs in which, i have to pick up something from a dataq and put it into the database….

is it something i have to load the dataque and then call my program to pick it up …if yes then how will i load the data q……

 895 pts.

 

 

I cant access those links…

 895 pts.

 

You can use data queues to retrieve data in a specific order.

Here’s an example from a print program where the incoming data is disparate:

D #qq             S             10                                     
D #qql            S             10                                     
D #qfl            S              5  0                                  
D #qf             S           1024                                     
D #qwt            S              5  0                                  
D #qord           S              2                                     
D #qkl            S              3  0 inz(%len(dta_0))                 
D #qk             S            256                                     
D #qsl            S              3  0                                  
D #qs             S             44                                     
                                                                       
D Dta_0           Ds                  inz                              
D  @svc_iso                      8  0                                  
D   @trndy                       4  0 overlay(@svc_iso)                
D   @trndm                       2  0 overlay(@svc_iso: *next)         
D   @trndd                       2  0 overlay(@svc_iso: *next)         
D  @grp                                                                
D  @chg#                         7  0                                  
D  @act#                        11  0                                  
D  @seq#                         5  0                                  
                                                                       
D Dta_1           Ds                  inz                              
D  @pst_iso                      8  0                                  
D   @tpsdy                       4  0 overlay(@pst_iso)                
D   @tpsdm                       2  0 overlay(@pst_iso: *next)         
D   @tpsdd                       2  0 overlay(@pst_iso: *next)         
D  @qty                               like(tqty)                       
D  @amnt                              like(tamnt)                      

 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 * Process commands (QCAPCMD)                                         
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
D ProcCmd         Pr                  extpgm('QCAPCMD')               
D                             1024a   options(*varsize) const         
D                                9b 0 const                           
D                               20a   options(*varsize) const         
D                                9b 0 const                            
D                                8a   const                            
D                             1024a   options(*varsize) const          
D                                9b 0 const                            
D                                9b 0 const                            
D                              512a   options(*varsize) const          
                                                                       
D Cc_loscs        S              9b 0                                  
D Cc_ocbl         S              9b 0                                  
D Cc_ocbf         S              8    inz('CPOP0100')                  
D Cc_lafccs       S              9b 0 inz(0)                           
D Cc_loccsatr     S              9b 0                                  

D Cpop0100        Ds                  inz                              
D  cpop_tocp                     9b 0 inz(0)                           
D  cpop_dbcs                     1    inz('0')                         
D  cpop_pa                       1    inz('0')                         
D  cpop_css                      1    inz('0')                         
D  cpop_mk                       4                                     
D                                9    inz(x'000000000000000000')       
                                                                       
  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  * Clear data queue (QCLRDTAQ)                                         
  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 D Clrdtaq         Pr                  extpgm('QCLRDTAQ')               
 D                               10a   const                            
 D                               10a   const                            

 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 * Send data queue (QSNDDTAQ)                                         
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
D Snddtaq         Pr                  extpgm('QSNDDTAQ')              
D                               10a   const                           
D                               10a   const                           
D                                5p 0 const                           
                                                                        
   // Create data queue                                                
   #qq  = s00proc;                                                     
   #qql = 'QTEMP';                                                     
                                                                       
   Cmdstr = 'CRTDTAQ  DTAQ('                                           
          + %trim(#qql)                                                
          + '/'                                                        
          + %trim(#qq)                                                 
          + ') MAXLEN('                                                
          + %trim(%editc(%len(dta_0) +                                 
                         %len(dta_1):'3'))                             
          + ') SEQ(*KEYED) KEYLEN('                                    
          + %trim(%editc(%len(dta_0):'3'))                             
          + ') SIZE(*MAX2GB)';                                         
   Proccmd(%trim(cmdstr):                                              
           %len(%trim(cmdstr)):                                        
           cpop0100:                                                   
           cpop0100:                    
           %len(cpop0100):              
           cc_ocbf:                     
           cmdstr:                      
           %len(cmdstr):                
           cc_loccsatr:                 
           api_error);                  
                                        
   Clrdtaq(#qq:                         
           #qql);                       
                                        
  Snddtaq(#qq:                                                 
          #qql:                                                
          %len(dta_0)                                          
          + %len(dta_1):                                       
          dta_0                                                
          + dta_1:                                             
          %len(dta_0):                                         
          dta_0);                                              

  Clear #qfl;                                                         
  Clear #qs;                                                          
                                                                      
  First = *on;                                                        
  Dou #qfl <= *zero;                                                  
 /End-free                                                            
C                   Call(e)   'QRCVDTAQ'                              
C                   parm                    #qq                       
C                   parm                    #qql                      
C                   parm                    #qfl                      
C                   parm                    #qf                       
C                   parm      *zero         #qwt                      
C                   parm      'GE'          #qord                     
C                   parm                    #qkl                      
C                   parm      *blanks       #qk                       
C                   parm      44            #qsl                      
C                   parm                    #qs                       
                                                                        
 /Free                                                                  
   If #qfl <= *zero;                                                    
    Exsr subroutine;                                                      
    *inlr = *on;                                                        
    Leave;                                                              
   EndIf;                                                               
                                                                        
   Dta_0 = %subst(#qf: 1: %len(dta_0));                                 
   Dta_1 = %subst(#qf: %len(dta_0) + 1:                                 
                       %len(dta_1));                                    
                                                                        
   If first;                                                            
    Exsr subroutine;                    
   EndIf;                                  
  EndDo;

Sorry about the length of the entry, but I didn’t want to leave out the important bits.

 5,740 pts.