Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


A string function that returns a string of spaces.


{fn SPACE(count)}


Argument Description
count An integer expression specifying the number of blank spaces to return.


SPACE returns a string of blank spaces count spaces long. If count is a numeric string, a decimal number, or a mixed numeric string, Caché resolves it to its integer portion. If count is a negative number or a nonnumeric string, Caché resolves it to 0.

To remove blank spaces from a string, use LTRIM (leading blanks) or RTRIM (trailing blanks).


The SPACE function should not be confused with the SPACE collation type. SPACE collation appends a single space to a value, forcing it to be evaluated as a string. To establish SPACE collation, CREATE TABLE provides a %SPACE collation keyword, and ObjectScript provides the Collation() method of the %SYSTEM.Util class.


The following embedded SQL example returns a string of spaces the length of the name field:

   &sql(SELECT SPACE(LENGTH(name))
   INTO :a
   FROM Sample.Person)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Leave this much space:",a,"for names" }
Copy code to clipboard

See Also