Consultor Eletrônico



Kbase 6364: Using PUT to Send CONTROL Codes to a printer 4GL or RESULTS
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

GOAL:

How to use the PUT statement in a Progress Procedure.

GOAL:

It is useful to override Progress framing in order to have more control over your output. You can use the CONTROL option to send escape sequences to output devices such as printers. PUT statements can also be used in RESULTS Printer Administration.

The example in this solution demonstrates the use of variables to store escape sequences. It is possible to do this with a variable but not with a database field. The PUT statement enables you to output data to a destination other than the terminal. Use PUT rather than DISPLAY when you write to a file to override default Progress framing. You can also use PUT with the UNFORMATTED option to write to your output destination in a RAW state.

FIX:

You can use the CONTROL option with PUT to send escape sequences to peripheral devices. The following program shows how you can manage the attributes of a printer.

NOTE: The special character tilde (~) allows a control sequence to be passed through the 4GL to the output stream without any interpretation by Progress. It is required for the ESCape character (octal 033) in the following example:

/* PROGRAM NAME: put_hp.p
* DESCRIPTION : This program shows how you can use printer
* escape codes to change attributes on a
* printed report. This program uses codes for
* an HP Laserjet II as an example.
*/
DEF VAR reset AS CHAR FORMAT "X(02)" INITIAL "~033E".
DEF VAR compress AS CHAR FORMAT "X(09)" INITIAL "~033(s16.66H".
DEF VAR normal AS CHAR FORMAT "X(09)" INITIAL "~033(s10H".
DEF VAR landscape AS CHAR FORMAT "X(05)" INITIAL "~033&l1O".
DEF VAR portrait AS CHAR FORMAT "X(05)" INITIAL "~033&l0O".

DEF VAR prtmode AS LOGICAL FORMAT "C/N" INITIAL "N".
DEF VAR orient AS LOGICAL FORMAT "P/L" INITIAL "P".
DEF VAR dfile AS CHARACTER FORMAT "X(20)".

DEFINE STREAM diskfile.

/* Prompt user for output details */
MESSAGE "Select mode for report (Normal or Compressed) "
UPDATE prtmode.
MESSAGE "Select orientation (Portrait or Landscape) "
UPDATE orient.

dfile = USERID(DBNAME) + "rpt.tmp".

OUTPUT STREAM diskfile TO VALUE(dfile).

/* Ask printer to go into requested state for report */
IF prtmode = TRUE THEN
PUT STREAM diskfile CONTROL compress. /* send COMPRESS code */
ELSE
PUT STREAM diskfile CONTROL normal. /* send NORMAL code */

IF orient = TRUE THEN
PUT STREAM diskfile CONTROL portrait. /* send PORTRAIT code */
ELSE
PUT STREAM diskfile CONTROL landscape. /* send LANDSCAPE code */

/* report code */
FOR EACH customer:
DISPLAY STREAM diskfile cust-num name.
END.

/* return printer to default state */
PUT STREAM diskfile CONTROL reset.
OUTPUT STREAM diskfile CLOSE.
UNIX silent lp -dlwmis value(dfile). /* spool report */
RETURN. /* return to calling program */

/* end of procedure */

Similarly, RESULTS can also be configured to interpret control characters. The various escape sequences will work for an HP laser printer. In addition, Results can be used in the initialization line for the Printer Control Sequence under Results Administration Printer Setup: NOTE: These do not work in the Normal Print,
- Landscape: ~033&l1O is entered as follows:
initialization: esc '&' 'l' '1' 'O'

(the characters are "lowercase L", "number one",
"capital O")

- Compressed: ~033(s16.66H is entered as follows:
initialization: esc '(' 's' '1' '6' '.' '6'
'6' 'H'

(the characters are "left parenthesis", followed
by "lowercase s", "number one", "three number
six's", "period", and "capital H")