Pages

Friday, December 4, 2020

Send Data to Data Queue from SQL - IBM i

Send Data to Data Queue:

Data Queues (DTAQ) has been very useful for communication between different Jobs on IBM i. 

There are multiple APIs to work with Data Queues. These have been very much helpful to Send and/or Receive the Data from Data Queues by calling these APIs. 

Working with Data Queues has been made easier with SQL Procedures. In this post, we will see how to send the data to Data Queues using SQL procedures. 

There are three different procedures to do this. 
  • SEND_DATA_QUEUE (Input data to be sent in Character Format to DTAQ).
  • SEND_DATA_QUEUE_BINARY (Input data to be sent in Binary Format to DTAQ).
  • SEND_DATA_QUEUE_UTF8 (Input data to be sent in UTF8 Format to DTAQ). 
We will mainly focus on the 'SEND_DATA_QUEUE' in this post and look at the other two procedures towards the end. 

Let's see how to send a message to a Standard Data Queue with no Key. 

SEND_DATA_QUEUE

In the above call to Procedure, We are passing three parameters. 
  • MESSAGE_DATA - Message to be sent to Data Queue
  • DATA_QUEUE - Data Queue Name
  • DATA_QUEUE_LIBRARY - Library in which Data Queue is present. *LIBL and *CURLIB can also be used depending on where Data Queue is present.
If we notice, in the above Call statement, we are using the Parameter name followed by the Parameter value. This doesn't necessarily be the same and parameters can be passed similar to regular CALL statement.

SEND_DATA_QUEUE

Both of these should work the same way. Below are the messages currently present in the Data Queue (Click Here to see how to retrieve data from Data Queue from SQL). 

DATA_QUEUE_ENTRIES

Let's look at sending data to Keyed Data Queue. This would require additional parameter to be passed for Key Data.

SEND_DATA_QUEUE

  • KEY_DATA - Key data to be passed. Length of the Key data should match with the length specified while creating Data Queue. 
Let's now look at how the data is stored differently when we send data using 'SEND_DATA_QUEUE_UTF8' and 'SEND_DATA_QUEUE_BINARY'. 

BINARY:

SEND_DATA_QUEUE_BINARY


Parameters passed are similar to 'SEND_DATA_QUEUE' except the Message data is in Binary format. 

DATA_QUEUE_ENTRIES_BINARY

Similarly, for SEND_DATA_QUEUE_UTF8 we can send the message in UTF8 format with all other parameters same as above. 

In the next post we will see how to Receive the data from Data Queue from SQL. And, a bit more details on how the Binary/UTF8 formatted data is received. 

If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form.

No comments:

Post a Comment

Popular Posts