For a Device select/print procedure body printing is initialised will be initialised on entry to the owning procedure. The print device will be closed again on exit from the procedure. This allows the procedure body itself and all the subsidiary procedures to print.
To initialise printing in a procedure body:
If this is the only part of the procedure tree that will do any printing you can use the Output Devices dialog on the Program Editing Functions menu to select the required devices. This dialog will also be useful if only the Print Device needs to be changed in the procedure trees that print, because is specified directly in the procedure body.
If you are printing to radically different output devices in different procedure trees (e.g. file in one place, printer in another), or you want to control the output device programmatically, you cannot rely on the Output Devices dialog. For example you may need to print information to various different files. There is no equivalent of the Output Devices dialog at a procedure level. One possibility is to consider using a sub program, so that you can still select the devices in the program header. In this case you need to follow the advice at the start of this section in Printing to Multiple Output Devices. The other method, which you can use if you do not want the overhead of calling another program at this point in your program, or need more flexibility, is to use the QAB standard variables output_device and filename to specify the destination for your printing. You have to set these up before you get to the procedure that initialises printing, because the initialisation takes place before your procedure body executes, so setting them there is ineffective. See Print Control Variables for further information and examples.
In both cases, you can now include Device/Select Print procedures in your procedure tree. Such procedures can either continue to use the current print device (if they specify "default_printer") , or they can select a new print device. See Procedure Overview for details.
The Program Editor will not allow you to set up a new Device select/print procedure underneath another one. Although you can cheat the Program Editor, by moving procedures around, the Program Compiler specifically checks for this, and will disable device selection in any subsidiary procedures of a procedure that does initialise a device.