ID: P117058
Title: "4GL: How to use FORMAT dynamically in 4GL"
Created: 06/28/2006Last Modified: 10/16/2008Status: Unverified
[B]Goals: [/B]
4GL/ABL: How to use FORMAT dynamically in 4GL
How to specify FORMAT in runtime
Example of FORMAT value being defined from a variable in 4GL
[B]Facts: [/B]
Progress 9.x
OpenEdge 10.x
All Supported Operating Systems
[B]Fixes: [/B]
Use the following piece of code:
/* Example 1 of dynamically changing the variable FORMAT */
[B]DEFINE VARIABLE cFormatVariable AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVariableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cValueToDisplay AS CHARACTER NO-UNDO.[/B]
[B]ASSIGN
cVariableName = "ABCDEFGHIJKLMNOP"
cFormatVariable = 'x(10)'
cValueToDisplay = STRING( cVariableName, cFormatVariable).[/B]
/* Example 2 of dynamically changing the variable FORMAT */
[B]DEFINE VARIABLE cFormatVariable AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVariableName AS CHARACTER NO-UNDO.[/B]
[B]DEFINE FRAME FrameName cVariableName.[/B]
[B]ASSIGN
cVariableName = "ABCDEFGHIJKLMNOP"
cFormatVariable = 'x(10)'
cVariableName:FORMAT = cFormatVariable.[/B]
/* Example 3 of dynamically changing the variable FORMAT */
[B]DEFINE VARIABLE cFormatVariable AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVariableName AS CHARACTER NO-UNDO.[/B]
[B]ASSIGN
cVariableName = "123456789012345678901234567890".[/B]
[B]OUTPUT TO 'FileName.txt'.
cFormatVariable = 'x(10)'.
PUT "Displaying the variable with the Using 'x(10)' FORMAT" SKIP.
PUT cVariableName FORMAT cFormatVariable SKIP.
PUT "Displaying the variable with the Using 'x(20)' FORMAT" SKIP.
cFormatVariable = 'x(20)'.
PUT cVariableName FORMAT cFormatVariable.
OUTPUT CLOSE.[/B]