Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Creating Reports : Using the PUT statement : Using PUT for printer control
 
Using PUT for printer control
When you send output to a printer, you may want to modify the way the printer generates that output. Many printers have a set of control sequences you can use to specify different print characteristics. You might, for example, want to change the number of printed characters per inch.
When you write a procedure that sends output to a printer, you can include printer control sequences within that procedure. Many control sequences involve special characters that can be represented by their octal (base 8) equivalent. To distinguish these octal codes, you precede the three octal digits by an escape character. the AVM then converts the octal number to a single character.
On UNIX, the escape character is a tilde (~) or a backslash (\).
The PUT statement with the CONTROL option allows you to specify a control sequence to send to the printer. This is a partial syntax for this version of the PUT statement:

Syntax

PUT [ STREAM stream-name| STREAM-HANDLE handle]
CONTROL "ctrl-sequence" "ctrl-sequence" ...
The control sequences you send to the printer have no effect on the current line, page counters, and positions maintained within ABL. Assume you want to print a report on your Brand X printer, using compressed-print mode.
The i-10-13.p procedure implements this task.
i-10-13.p
      /********** DEFINE WIDGETS **********/
/*1*/ DEFINE VARIABLE Start-Compress AS CHARACTER INITIAL "~033[3w".
/*2*/ DEFINE VARIABLE Stop-Compress  AS CHARACTER INITIAL "~032[3w".

DEFINE BUTTON b-normal   LABEL "Print Normal Report".
DEFINE BUTTON b-compress LABEL "Print Compressed Report".
DEFINE BUTTON b-exit     LABEL "Exit".

/********** DEFINE FRAMES **********/
DEFINE FRAME Frame1
        SKIP(1)
        b-normal b-compress SKIP(1)
        b-exit
        WITH NO-BOX CENTERED THREE-D.

/********** DEFINE TRIGGERS **********/
/*3*/ ON CHOOSE OF b-normal DO:
        OUTPUT TO PRINTER.
        FOR EACH Customer NO-LOCK
          WHERE Customer.Balance >= 1400 WITH STREAM-IO:
          DISPLAY Customer.Name Customer.Phone Customer.Balance
            Customer.SalesRep.
        END.
        OUTPUT CLOSE.
      END.

/*4*/ ON CHOOSE OF b-compress DO:
        OUTPUT TO PRINTER.
        PUT CONTROL Start-Compress.
        FOR EACH Customer NO-LOCK
          WHERE Customer.Balance >= 1400 WITH STREAM-IO:
          DISPLAY Customer.Name Customer.Phone Customer.Balance
            Customer.SalesRep.
        END.
        PUT CONTROL Stop-Compress.
        OUTPUT CLOSE.
END.

/********** MAIN LOGIC **********/
ENABLE ALL WITH FRAME Frame1.
WAIT-FOR CHOOSE OF b-exit.
These notes help to explain the code:
1. The start-compress variable contains the four-character sequence that puts the printer into compressed-print mode. These four characters are octal 033 (decimal 27) followed by left bracket ([), 3, and w.
2. The variable stop-compress takes the printer out of compressed print mode.
3. When the user clicks b-normal, the AVM runs the report in normal mode.
4. When the user clicks b-compressed, the AVM runs the report in compressed mode.
Note: This procedure works only if you have a printer connected to your system. Also, be aware that not all printers support compressed printing.
Control sequences are hardware-dependent, thus applications containing hard-coded printer control sequences are not easily portable to other environments. See OpenEdge Deployment: Managing ABL Applications for more information about using the PUT CONTROL statement with control sequences.