As we noted at the start of the chapter, the second issue that frequently arises in printing concerns ownership of the printer. Requests for printing often originate from a user at a display terminal. The task that processes the request and generates the printed output is associated with the user’s terminal and therefore cannot send output directly to the printer.
If your task does not own the printer it wants to use, it must create another task, which does, to do the work. These are the ways to do this:
The first technique for creating the print task is to issue a START command in the task that wants to print. The command names the printer as the terminal required by the STARTed task in the TERMID option and passes the data to be printed, or instructions on where to find it, in the FROM option. START causes CICS® to create a task whose principal facility is the designated terminal when that terminal is available.
The program executed by the STARTed task, which you must supply, retrieves the data to be printed (using a RETRIEVE command), and then writes it to its terminal (the printer) with SEND, SEND MAP, or SEND TEXT . For example:
·
·
·
(build output in OUTAREA, formatted as expected by the STARTed task)
EXEC CICS START TRANSID(PRNT) FROM(OUTAREA) TERMID(PRT1)
LENGTH(OUTLNG) END-EXEC.
·
·
·
·
·
·
EXEC CICS RETRIEVE INTO(INAREA) LENGTH(INLNG) END-EXEC.
·
·
·
(do any further data retrieval and any formatting required)
EXEC CICS SEND TEXT FROM(INAREA) LENGTH(INLNG) ERASE PRINT END-EXEC.
·
·
·
(repeat from the RETRIEVE statement until a NODATA condition arises)
The task associated with the printer loops until it exhausts all the data sent to it, in case another task sends data to the same printer before the current printing is done. Doing this saves CICS the overhead of creating new tasks for outputs that arrive while earlier ones are still being printed; it does not change what finally gets printed, as CICS creates new tasks for the printer as long as there are unprocessed START requests.
The second method for creating the print task involves transient data. A CICS intrapartition transient data queue can be defined to have a property called a "trigger". When the number of items on a queue with a trigger reaches the trigger value, CICS creates a transaction to process the queue. The queue definition tells CICS what transaction this task executes and what terminal, if any, it requires as its principal facility.
You can use this mechanism to get print data from the task that generates it to a task that owns the printer. A transient data queue is defined for each printer where you direct output in this way. A task that wants to print puts its output on the queue associated with the required printer (using WRITEQ TD commands). When enough items are on the queue and the printer is available, CICS creates a task to process the queue. (For this purpose, the trigger level of "enough" is usually defined as just one item.) The triggered task retrieves the output from the queue (with READQ TD commands) and writes it to its principal facility (the printer), with SEND, SEND MAP, or SEND TEXT commands.
As in the case of a STARTed printer task, you have to provide the program executed by the task that gets triggered. The sample programs distributed with CICS contain a complete example of such a program, called the "order queue print sample program". The CICS 4.1 Sample Applications Guide describes this program in detail, but the essentials are as follows:
·
·
·
(do any formatting or other processing required)
EXEC CICS WRITEQ TD QUEUE(‘PRT1’) FROM(OUTAREA)
LENGTH(OUTLNG) END-EXEC.
·
·
·
·
·
·
EXEC CICS ASSIGN QNAME(QID) END-EXEC.
EXEC CICS READQ TD QUEUE(QID) INTO(INAREA) LENGTH(INLNG)
RESP(RESPONSE) END-EXEC.
IF RESPONSE = DFHRESP(QZERO) GO TO END-TASK.
·
·
·
(do any error checking, further data retrieval and formatting required)
EXEC CICS SEND FROM(INAREA) LENGTH(INLNG) END-EXEC.
·
·
·
(repeat from READQ command)
The print task determines the name of its queue using an ASSIGN command rather than a hard-coded value so that the same code works for any queue (printer).
Like its START counterpart, this task loops through its read and send sequence until it detects the QZERO condition, indicating that the queue is empty. While this is just an efficiency issue with the STARTed task, it is critical for transient data; otherwise unprocessed queue items can accumulate under certain conditions. (See Automatic transaction initiation (ATI) for details on the creation of tasks to process transient data queues with triggers.)
If you use this technique, you need to be sure that output to be printed as a single unit appears either as a single item or as consecutive items on the queue. There is no fixed relationship between queue items and printed outputs; packaging arrangements are strictly between the programs writing the queue and the one reading it. However, if a task writes multiple items that need to be printed together, it must ensure that no other task writes to the queue before it finishes. Otherwise the printed outputs from several tasks may be interleaved.
If the TD queue is defined as recoverable, CICS prevents interleaving. Once a task writes to a recoverable queue, CICS delays any other task that wants to write until the first one commits or removes what it has written (by SYNCPOINT or end of task). If the queue is not recoverable, you need to perform this function yourself. One way is to ENQUEUE before writing the first queue item and DEQUEUE after the last. (See Transient data control for a discussion of transient data queues.)
A task also can get output to a printer other than its principal facility with BMS routing. This technique applies only to BMS logical messages (the ACCUM or PAGING options) and thus is most appropriate when you are already building a logical message.
When you complete a routed message, CICS creates a task for each terminal named in a route list. This task has the terminal as its principal facility, and uses CSPG, the CICS-supplied transaction for displaying pages, to deliver the output to the printer. So routing is similar in effect to using START commands, but CICS provides the program that does the printing. (See Message routing for more information about routing.)
[[ Contents Previous Page | Next Page Index ]]