AS400 Data Queue Concept

What is an AS400 Data Queue:-
An AS400 data queue is just what it says; it is a sort of queue ;-), a physical one. Data waiting to be picked for processing is lined up in this queue. Once a data record is picked up (by reading the data queue), that record is removed automatically from the queue.

Data Queue and Physical File
A data queue can be assumed to be sort of a physical file, in the sense that, it can store data for long time and unlike an AS400 Data area, multiple records can be stacked/queued in it. However, it differs with the PF, that the data queue is not permanent storage. As discussed earlier, the data record is removed from queue as soon as it’s read.

Data Queue as mediator
So far you must have been aware that a data queue is a temporary but physical storage. In practical scenarios, we write a data queue at one place of the application and it’s read by another entirely different section of application. In this sense, data queue allows us to handle asynchronous completion of jobs.

Data queue can be used to fragment a job into two portions easily and save processing time and efficiency. This is how it can be done.

Example to illustrate practical usage of an AS400 data queue
Let us say that we’ve one job A which have two logical sections within itself, B and C and section C requires input from section B. Now, Section B is rather easy part and it takes 5 seconds on average to feed section C. Section C is time consuming and it takes 30 seconds to complete.
Now let us say we need to run 100 iterations of job A. In the present scenario, when Section B calls Section C with input parameters, it will take a total of (5+30) * 100 = 3500 seconds to complete the job.

Data Queue Comes in Picture:-
Now let us divide the logical sections into two separate sections B and C. For this we create a data queue and write each set of input parameter to it instead of making a direct call to section C. We make the section C such that, it scans the data queue for any fresh entry. As soon as it finds one, it processes it. If section C is in process, the input is just stacked in the data queue, waiting for section C to make its next scan.
With introduction of this small change, total processing time is reduced to 5 + 30*100 = 3005 seconds.

Picture is filled with data queue in a bigger role:-
Is there any way we can further reduce the processing time? Yes! There is. If we just introduce one more instance of section C to scan the same data queue, the total processing time will be around 5+30*100/2 = 1505 seconds. One more instance and processing time goes down to 1005 seconds etc.
You see how efficient a data queue can make an application!!

Note: -

  1. You might be thinking that why we can’t use PFs to isolate two sections of job A in the example. Well, yes we can. Only that data queue easier to process and I guess I/O operations are better.

  • You might be wondering that why don’t we use data queue within the same program? Like writing to it and reading from it? Again, yes, technically, this is possible. Should such requirement come, we off course do that.
  • In the example above, I assume that Section B is independent and it does not depend on completion of Section C for its input.

    Thanks for patiently going through this article. In the coming sections, we’ll learn how to create and delete an AS400 data queue.

    Did you like it? Do you want something more? Any suggestions or comments for improvement? Do put your comment at the bottom, or send me a mail directly @ admin@tutorialindia.com. I'd love your input.