Kbase P64416: How to build right align 4GL reports using fixed fonts
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Unverified
GOAL:
How to build right align 4GL reports using fixed fonts
GOAL:
How to create "Arabic" right aligned reports using fixed fonts
FIX:
Example:
/*------------------------------------------------------------------------------
Example - how to right align a text when using fixed fonts.
It suppose that the text is written from right to left (for Arabic languages).
Output the report to a file and open it in NOTEPAD.
NOTE: Is important to use fixed font when you open it in NOTEPAD or when sending the file to the printer
-------------------------------------------------------------------------------------*/
&SCOPED-DEFINE LineSize 115 /* Standard line length in characters*/
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE iSpaceSize AS INTEGER NO-UNDO.
DEFINE VARIABLE gcLine AS CHARACTER NO-UNDO. /*current line we will display */
FUNCTION TruncateField RETURNS CHARACTER
(ipcText AS CHARACTER, ipiMaxTextSize AS INT) FORWARD.
OUTPUT TO 'aaa.txt'.
FOR EACH customer:
/* first we fill the current line with spaces*/
gcLine = fill(' ', {&LineSize}).
/*We change the current line - we replace the spaces with a database field at given coordinates
The coordinates are from right to left. If the text to display is longer that the given length
then will be truncated at the left side */
RUN FormField(customer.custnum, 1, 5) NO-ERROR. /* The parameters are in characters*/
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE 'ERROR: ' RETURN-VALUE
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
RUN FormField(customer.NAME, 7, 30) NO-ERROR. /* The parameters are in characters*/
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE 'ERROR: ' RETURN-VALUE
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
RUN FormField(customer.address, 40, 10) NO-ERROR. /* The parameters are in characters*/
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE 'ERROR: ' RETURN-VALUE
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
RUN FormField(customer.city, 77, 25) NO-ERROR. /* The parameters are in characters*/
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE 'ERROR: ' RETURN-VALUE
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
/*Now we display the current line to the output device - in our case aaa.txt file*/
RUN PrintLine.
END.
OUTPUT CLOSE.
/* Open aaa.txt file in NOTEPAD */
FILE-INFO:FILE-NAME = 'aaa.txt'.
OS-COMMAND NO-WAIT value( "notepad " + FILE-INFO:FULL-PATHNAME ).
PROCEDURE FormField:
/*-------------------------------------------------------------------------------------
Insert the field at the right coordinates in the current line and
with the given length
-------------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER ipcText AS CHARACTER NO-UNDO. /* Text to print*/
DEFINE INPUT PARAMETER ipiStart AS INTEGER NO-UNDO. /* The starting coordinate - from right to left */
DEFINE INPUT PARAMETER ipiLength AS INTEGER NO-UNDO. /*Text length. We will truncate the text at the left side if needed */
DEFINE VARIABLE iTextSize AS INTEGER NO-UNDO.
DEFINE VARIABLE iExistingLeftTextSize AS INTEGER NO-UNDO.
/*Double check the coordinates are above 0 */
/*IF ipiStart = 0 THEN ipiStart = 1.*/
/* Checking the parameters */
IF ipiStart + ipiLength > {&LineSize} THEN
RETURN ERROR 'The field position + length exceed the line size'.
/*text length in characters: iTextSize*/
iTextSize = LENGTH(ipcText).
/*In case iTextSize > ipiLength then we will truncate the text on it's left side*/
IF iTextSize > ipiLength THEN
ipcText = TruncateField(ipcText, ipiLength).
/*We insert the text in the existing line */
iExistingLeftTextSize = {&LineSize} - ipiStart - LENGTH(ipcText) - 1.
gcLine = SUBSTRING(gcLine, 1, iExistingLeftTextSize) +
ipcText +
SUBSTRING(gcLine, {&LineSize} - ipiStart).
END PROCEDURE.
PROCEDURE PrintLine:
/*-----------------------.--------------------------------------------------------------
output the new formatted text
-------------------------------------------------------------------------------------*/
MESSAGE gcLine.
END PROCEDURE.
FUNCTION TruncateField RETURNS CHARACTER (ipcText AS CHARACTER, ipiMaxTextSize AS INT):
/*-------------------------------------------------------------------------------------
truncate eventual characters on the left side in case the field length
exceeds ipiMaxTextSize
-------------------------------------------------------------------------------------*/
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE iInitialLength AS INTEGER NO-UNDO. /*Initial text length in characters .*/
iInitialLength = LENGTH (ipcText).
DO i = 1 TO iInitialLength:
IF LENGTH(ipcText) .