Kbase P69985: How to left pad a numeric character field of "X(7)" with blanks, make it align in a browse and store
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  14/12/2005 |
|
Status: Unverified
GOAL:
How to left pad a numeric character field of "X(7)" with blanks?
GOAL:
How to make it align in a browser?
GOAL:
How to store the padded string in the database?
FACT(s) (Environment):
Windows
Progress 9.x
FIX:
Follow the following steps to develop a sample solution to demonstrate how to achieve the above tasks:
1. Connect to the sports2000 database.
2. Add a character field cCustNum with "X(7)" format.
3. Populate this field by running the following code from the procedure editor:
FUNCTION padit RETURNS CHARACTER (INPUT i AS INTEGER).
DEFINE VARIABLE cBlanks AS CHARACTER FORMAT "x(7)" NO-UNDO.
DEFINE VARIABLE cValue AS CHARACTER FORMAT "x(6)" NO-UNDO.
ASSIGN
cBlanks = FILL(CHR(32),7)
cValue = STRING(i)
cValue = SUBSTRING(cBlanks,1,(7 - LENGTH(cValue))) + cValue.
RETURN cValue.
END FUNCTION.
FOR EACH customer:
ASSIGN
cCustNum = padit(custnum).
END.
4. Create a new window in the AppBuilder.
5. Drop a browse on the window against the Customer table with the fields Name, CustNum cCustNum and Country Fields.
6. Change the browse font to a fixed font.
7. Define a function 'padit' using the following code:
FUNCTION padit RETURNS CHARACTER
( INPUT c AS CHARACTER) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE cBlanks AS CHARACTER FORMAT "x(7)" NO-UNDO.
DEFINE VARIABLE cValue AS CHARACTER FORMAT "x(6)" NO-UNDO.
ASSIGN
cBlanks = FILL(CHR(32),7)
cValue = c
cValue = SUBSTRING(cBlanks,1,(7 - LENGTH(cValue))) + cValue.
RETURN cValue.
END FUNCTION.
6. Write a LEAVE trigger for the cCustNum column to pad the entry using the following code:
ON LEAVE OF Customer.cCustNum IN BROWSE BROWSE-1 /* cCustNum */
DO:
ASSIGN
SELF:SCREEN-VALUE IN FRAME {&FRAME-NAME} = padit(SELF:SCREEN-VALUE).
END.
7. Write a ROW-LEAVE trigger to assign the field to the database using the following code:
ON ROW-LEAVE OF BROWSE-1 IN FRAME DEFAULT-FRAME /* Browse 1 */
DO:
FIND CURRENT customer.
ASSIGN
cCustNum = cCustNum:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
END.
8. Save and run the window.
The whole code is attached in the note below.