First time here?
Back again?


 
 

How to format a string made of various types of variables (integer, real,...)?

CATEGORY: PROGRAMMING
TYPE: MACRO
IMS VERSION: ALL
PLATFORM: ALL

Use the macro language function SPRINT.
This function takes a variable number of arguments.
The format is:
result = SPRINT("format", arg1, arg2,)
SPRINT formats the arguments in arg1, arg2, etc., according to the string format.
As an example:
result = SPRINT(" %-10s %4.3f %5s",VARNAME,X.VALUE,X.UNITO) creates a string of the form:
X VALUE 1234.123 MM
and stores it in result,
where "X VALUE" is the value of VARNAME
1234.123 is the value stored in X.VALUE and
"MM" is the value stored in X.UNITO
Please note that:
%-10s means formatting a string with 10 characters from the left.
%4.3f means a float with 4 digits prior to the decimal point and 3 after.
%5s means formatting a string with 5 characters from the right.

Back to Frequently Asked Questions