SFMT() operator passes a string with variable parameters in it:
SFMT("string %1 [string %2 string %3... etc]", parameter1 [,parameter2, parameter3...])
Here the value returned by parameter1 will be passed to the %1 placeholder, the value returned by the parameter2 will be passed to the %2 placeholder, etc.
The position of the parameters within the string is defined by placeholders that are preceded by a percent (%) symbol.
If the percent symbol must be displayed to the SFMT() string, it must be doubled – %%.
With SFMT(), you can use one and the same placeholder several times. In this case the same value will be passed to several positions.
You can pass any valid expressions to the SFMT() operator.
Date and numeric expressions are converted into string according to the current DBDATE and DBMONEY settings.
There are pre-defined placeholders that can be used during error handling within WHENEVER ERROR CALL and WHENEVER ERROR GOTO statements:
Predefined placeholders |
description |
%(ERRORFILE) |
gets the name of the module in which the last runtime error occurred |
%(ERRORLINE) |
gets the number of the line in the module where the last runtime error occurred |
%(ERRNO) |
gets the operation system number of the last error |
%(STRERROR) |
gets the operation system text of the last error |
Here is a simple example of how SFMT() can be used:
MAIN
DEFINE ct VARCHAR(20)
LET ct = "London"
DISPLAY sfmt("Today is %1. The current time in %2 is %3", DATE, ct, TIME)
CALL fgl_getkey()
END MAIN
On Wednesday, the 2nd of December, 2020 the returned string would be
Today is Wed Dec 2 2020. The current time in London is 18:15:24
One more example program:
MAIN
DEFINE
v_varchar VARCHAR(80)
LET v_varchar = "%1 string has been %2"
DISPLAY SFMT(v_varchar,NULL,"changed.") --> will be displayed: string has been changed.
DISPLAY SFMT(v_varchar,"This","changed.") --> will be displayed: This string has been changed.
LET v_varchar = "This %1 %2 changed."
DISPLAY SFMT(v_varchar,"string","has been") --> will be displayed: This string has been changed.
LET v_varchar = "This string has been %1changed%2."
DISPLAY SFMT(v_varchar,"""","""") --> will be displayed: This string has been "changed".
LET v_varchar = "This string has been %%%1changed%2%%."
DISPLAY SFMT(v_varchar,"","") --> will be displayed: This string has been %changed%.
CALL fgl_getkey()