%STRING

Convert a value to a string

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
string = %STRING(value[, format])

Return value

string

A string representation of value. (a)

Arguments

value

The value to convert. (n)

format

(optional) A format string, which is a sequence of characters that depicts how value will be formatted. (a)

Discussion

If format is not specified, %STRING converts value to a nonblank string according to the rules for moving data to an alpha destination. (See Assignment statements for a description of these rules.) If format is passed, %STRING considers it to be a format string and converts value according to the rules for formatting data. (See Explicit formatting rules for more information.) If value is a compile-time expression, %STRING is also evaluated as a compile-time expression.

Tip

%STRING is a useful alternative to ^A for displaying integer values, because ^A doesn’t perform a data conversion like %STRING does.

Examples

The following function reads in a price from an inventory file and displays it on the screen.

function show_price 
    a_chn       ,n
    a_item      ,a
.include "INV:invent.def"       ;Data layout (record inven) for inventory file
.define ERROR   ,-1
proc 
    read(a_chn, inven, a_item) [err=invalid] 
    writes(TTCHN, "Price: " + %string(price, "$$$,$$$.XX")) 
    freturn (%true) 
invalid, 
    writes(TTCHN, "Invalid inventory item code") 
    freturn (ERROR) 
endfunction