Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Alternate I/O Sources : Changing the output destination : A printing solution
 
A printing solution
The OpenEdge ADE toolset provides a portable solution for printing text files. The solution is a procedure called _osprint.p and it is located in the adecomm procedure library in the OpenEdge product directory (DLC). You can also access the source code for this procedure in the src/adecomm.pl file located in the OpenEdge product directory.
The _osprint.p procedure sends a specified text file to the default printer as paged output. Input parameters for the procedure allow you to specify values that configure a print job. In Windows, you can also direct the _osprint.p procedure to display the Print dialog box and print the text in a specified font. Use the following syntax to call the _osprint.p procedure from an ABL procedure:

Syntax

RUN adecomm/_osprint.p
  ( INPUT parentWindow , INPUT printFile ,
    INPUT fontNumber , INPUT PrintFlags . INPUT pageSize ,
    INPUT pageCount , OUTPUT result ).
The parameters of the _osprint.p procedure are as follows:
INPUT parentWindow
A window handle identifying the parent window for Print dialog box and any print status messages in Windows. The procedure ignores a value specified for this parameter in character interfaces. If you specify the Unknown value (?) or an invalid handle in Windows, the procedure uses the CURRENT–WINDOW handle.
INPUT printFile
A string value representing the name of a text file to print. You can specify an absolute or relative path for the file. The _osprint.p procedure uses the PROPATH to locate the file.
INPUT fontNumber
An integer value representing an entry in the font table maintained by the FONT–TABLE handle. The _osprint.p procedure uses the specified font to print the text file in Windows. The procedure ignores a value specified for this parameter in character interfaces. If you specify the Unknown value (?) or an integer value that does not exist in the font table for Windows, the procedure uses the default system font to print the text file.
INPUT PrintFlags
An integer value that determines which printing options are used for a print job in Windows (only). You can use the values in the following table. If you need to use more than one option, add the values of the options together. In all cases, the _osprint.p procedure sets the value of the PRINTER–CONTROL–HANDLE attribute of the SESSION handle to zero (0).
Table 40. Printing options for Windows
Printing option
Value
Selection
Context
0
Default print context
1
Print dialog box. This allows the user to establish a print context
Landscape orientation
2
Landscape orientation
Paper Size
4
Letter
8
Legal
12
A4
Paper Tray
32
Upper tray
64
Middle tray
96
Lower tray
128
Manual
160
Auto
UTF-8
512
Required when sending UTF-8 encoded data to the printer
INPUT pageSize
An integer value representing the number of lines per page. If you specify zero (0) for this parameter, the printer determines the page size. Windows ignores this parameter and calculates the page size based on the Paper Size setting in the Print Setup dialog box and the font specified with the fontNumber parameter.
Note: The maximum number of character per line is 255.
INPUT pageCount
An integer value that determines if _osprint.p prints the entire text file or a range of pages from the text file in Windows. The procedure ignores a value specified for this parameter in character interfaces. If the value of this parameter is not zero (0) in Windows, ABL uses the page range specified for the current print context.
OUTPUT result
A logical value that reports the success or failure of the print job.
To call the _osprint.p procedure from an ABL procedure, you must define a variable for the result output parameter. The _osprint.p procedure is an example.
_osprint.p
/*1*/ DEFINE VARIABLE result AS LOGICAL NO-UNDO.

/*2*/ OUTPUT TO tmp.dat.
      FOR EACH Customer NO-LOCK:
        DISPLAY Customer.CustNum Customer.Name Customer.Phone WITH STREAM-IO.
      END.
      OUTPUT CLOSE.

/*3*/ RUN adecomm/_osprint.p (INPUT ?, INPUT "tmp.dat", INPUT ?, INPUT 1,
                              INPUT 0, INPUT 0, OUTPUT result).
/*4*/ OS-DELETE "tmp.p".
The following list describes the important elements of the _osprint.p procedure:
1. Create a variable for the OUTPUT parameter of the _osprint.p procedure.
2. Generate the temporary text file to be printed. Remember to close the output stream after generating the text file.
3. Run the _osprint.p procedure to print the generated text file.
4. Delete the temporary text file.
For more information on the language elements referenced in this section, see OpenEdge Development: ABL Reference.