Substitution in String Values
When creating a string constant, it is often useful to substitute the result of some expression. This is done by using two percent signs percent signs (%%
) followed
by that expression between parentheses.
If you only need to substitute the current value of a field, variable, or function, it is possible to use two percent signs followed immediately by the name of the field, variable, or function. However, as a good practice, it is advisable to always use the two percent signs, followed by parentheses enclosing the field, variable or function.
For example:
message "FIELDA contains %%(FIELDA); variable myVar is %%(myVar)"
If FIELDA contains AAAA and myVar contains 1111, the following message appears:
FIELDA contains AAAA; variable $1 is 1111
Substitution is possible in any constant string parameter, except in the perform and blockdata statements. Substitution is often used in statements that display text (message. askmess, and so on), in assignment statements, and in global messages and help texts.
Rules for String Substitution
The following rules apply:
- Use two percent signs (
%%
) followed by an expression inside parentheses to replace the expression with its result. - Use two percent signs (
%%
) immediately followed by the name of a field, variable, or function to replace it with the current value of that field, variable, or function. - Use parentheses around the name of a field, variable, or function name in a string,
to prevent ambiguity in interpreting it:
message "%%($$GLOBVAR)XYZ"
Note: In older versions of Uniface, ambiguity was avoided by following the name with three percent signs (
%%%
).message "%%$$GLOBVAR%%%XYZ"
- Use two percent signs followed by a double quotation mark (
%%"
) to include a double quotation mark in the resulting string. - Use two percent signs followed by a caret (
%%^
) to include a carriage return in the resulting string. - Use two percent signs followed by a left or right angle bracket (
%%<
or%%>
) to include the angle bracket in the resulting string. Use this to prevent the ProcScript Precompiler from interpreting the angle brackets for precompiler constants. - A single percent sign simply appears as a single percent sign.
- To insert several consecutive percent signs, use string substitution, like in this example:
Use %%("%")%%("%") to get two percent signs in your message.
Example | Result |
---|---|
; the current entity is ENT1 |
|
; initialize values $$GVAR1 = 999 FIELDA.ENT1 = "AAAA" |
Values are initialized. |
"Values %%(FIELDA) %%($1) %%($entname)" "FIELDA contains %%FIELDA%%%." "FIELDA contains %%"%%(FIELDA)%%"" |
Values AAAA 1111 ENT1 FIELDA contains AAAA. FIELDA contains "AAAA" |
"%%(FIELDA.001)" "%%(FIELDA)%%%.001" "%%($1)001" "%%($$GVAR1)xyz" |
Compile error: 1000 - Field ‘FIELDA.001’ not found. AAAA.001 1111001 999xyz |
"%%($USER)" "%%("%")%%("%") $USER" "% % $USER" |
KAYE %%$USER % % $USER |
"Roses are red%%^Violets are blue" |
Roses are red |
$2 = "%% FIELDA" "%%($2)" |
%%FIELDA |
"%%<OK%%> is <OK>" | <OK> is 0 |
"%%(vFieldA->$parent->$parent)%%%" | ENT1 |
"%%(1+2)" | 3 |