Kbase P168671: 4GL/ABL: How to Print Preview a report when running a Window application?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  24/06/2010 |
|
Status: Unverified
GOAL:
4GL/ABL: How to Print Preview a report when running a Window application?
GOAL:
How to redirect the output of a report to a dynamically created DIALOG-BOX widget from a Smart Window or a regular Window Application?
GOAL:
How to display a report on a screen larger than the CURRENT-WINDOW widget when running a Smart Window or a regular Window Application?
GOAL:
How to work around inability to use OUTPUT TO TERMINAL when running a Smart Window or a regular Window application?
FIX:
The following solution uses a dynamic DIALOG-BOX widget containing a dynamic LARGE EDITOR widget to display the result set (report) generated by a FOR EACH query. Although the example uses a regular WINDOW widget, the solution is equally applicable to SmartWindow widgets:
1. Start an OpenEdge or a Progress proenv session:
Start > Programs > OpenEdge > Proenv
2. Create a copy of the sports2000 in your working directory
prodb sports2000 sports2000
3. Start an AppBuilder session connected to the sports2000 database:
prowin32 sports2000 -1 -p _ab
4. Create a new Window.
5. Drop a BUTTON widget on the window. Name it PrintPreview and label it Print Preview.
6. Use the following code to define a CHOOSE event trigger for the PrintPreview BUTTON widget:
DO:
DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
ASSIGN
cFileName = STRING(USERID) + "_" + STRING(TODAY,"99999999") + "_" + STRING(TIME,"999999").
OUTPUT TO VALUE(cFileName).
RUN GenerateReport.
OUTPUT CLOSE.
RUN PrintPreview (INPUT cFileName).
END.
7. Use the following code to define the GenerateReport internal procedure:
FOR EACH Customer NO-LOCK:
DISPLAY
CustNum
NAME
City
State
Country
Balance
CreditLimit
WITH STREAM-IO WIDTH 320.
END.
END PROCEDURE.
8. Use the following code to define the PrintPreview internal procedure:
DEFINE INPUT PARAMETER cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hFrame AS HANDLE NO-UNDO.
DEFINE VARIABLE hEditor AS HANDLE NO-UNDO.
/* Create a DIALOG-BOX frame */
CREATE DIALOG-BOX hFrame
ASSIGN
X = 0
Y = 0
WIDTH-PIXELS = SESSION:WIDTH-PIXELS * 0.85
HEIGHT-PIXELS = SESSION:HEIGHT-PIXELS * 0.85
THREE-D = TRUE
TITLE = "Print Preview"
VISIBLE = TRUE
SCROLLABLE = TRUE
TRIGGERS:
. ON WINDOW-CLOSE PERSISTENT RUN ClosePrintPreviewDialog IN THIS-PROCEDURE (hFrame, hEditor, cFileName).
END TRIGGERS.
/* Create an EDITOR widget */
CREATE EDITOR hEditor
ASSIGN
X = 24
Y = 10
LARGE = TRUE
AUTO-RESIZE = TRUE
WORD-WRAP = FALSE
SCROLLBAR-HORIZONTAL = TRUE
SCROLLBAR-VERTICAL = TRUE
WIDTH-PIXELS = hFrame:WIDTH-PIXELS * 0.95
HEIGHT-PIXELS = hFrame:HEIGHT-PIXELS * 0.95
FRAME = hFrame
READ-ONLY = TRUE
VISIBLE = TRUE
SENSITIVE = TRUE
BGCOLOR = 15
FONT = 0.
hEditor:READ-FILE(cFileName).
END PROCEDURE.
9. Use the following code to define the ClosePrintPreviewDialog internal procedure:
DEFINE INPUT PARAMETER hFrame AS HANDLE.
DEFINE INPUT PARAMETER hEditor AS HANDLE.
DEFINE INPUT PARAMETER cFileName AS CHARACTER.
IF VALID-HANDLE(hEditor) THEN
DELETE WIDGET hEditor. /* editor */
IF VALID-HANDLE(hFrame) THEN
DELETE WIDGET hFrame. /* frame */
IF SEARCH (cFileName) <> "" THEN
OS-DELETE VALUE(cFileName).
END PROCEDURE.
10. Save and Run the Window..