jst()

Function group Execute on client Platform(s)
String YES All

Syntax

jst(string1,number1[,string2,number2]...)

Description

Returns a string containing the specified string left or right justified with sufficient spaces added to make a total length specified by number.

The jst() function also includes concatenation. If number is negative the resulting string is right justified, if the number is positive the string is left justified; number must be in the range 1 to 999.

jst('This is left justified',30)
# gives
|This is left justified |

jst('This is right justified',-30)
# gives
| This is right justified|

When you define the columns for a list, jst() lets you fix the column width and using a non-proportional font the list columns will line up properly. For example, the calculation for a list containing the fields CODE and COMPANY could be

jst(CODE,7,COMPANY,25)

The jst() function also includes concatenation, for example:

jst(p1,p2,p3,p4,p5,p6,...)
# is the same as
con(jst(p1,p2),jst(p3,p4),jst(p5,p6),...)

However it has a limit of 100 parameters, but you can exceed this limit by using Calculate CVAR1 as jst(CVAR2,CVAR3) where CVAR2 has 99 items and CVAR3 has 99 items, and so on.

Formatting Strings Using jst()

The jst() function can take a string for the second argument instead of a number, that is

jst(string1,string1[,string2,string2]...)

This form of jst() formats the first string1 argument in a way controlled by the second string2 argument. The second argument consists of a series of formatting options which you can use separately or together. Each option is represented by one or more characters. The order of the various formatting options is not important but the case is.

^n (caret) causes the data to be centered in the field n characters wide.
jst('abc','^5') ## returns ' abc '
jst(FIELD,'^25') ## as a list calculation will center the FIELD values in a column 25 characters wide
£ places a £ sign in front of the data. The data must be a number or an integer.
jst(TOTAL,'£') ## returns '£12.12' if TOTAL = 12.12
$ places a $ sign in front of the data. The data must be a number or an integer.
jst(TOTAL,'$') ## returns ' $12.12' if TOTAL = 12.12
< left justification, overriding the default set up in a report class. This is used by the Ad hoc report generator to control the justification of fields.
Pc causes the part of the field not filled by the data to be filled by character c.
jst('abc','-5P*') ## returns '**abc'
X causes the data to be truncated if its length exceeds the field length. The default is not to truncate.
jst('abcdef','4') ## returns 'abcdef
jst('abcdef','4X') ## returns 'abcd'
U causes the data to be converted to upper case.
jst('this IS it','U') ## returns 'THIS IS IT'
L causes the data to be converted to lower case.
jst('THIS is IT','L') ## returns 'this is it'
C causes the data to be capitalized.
jst('this is it','C') ## returns 'This Is It'
jst('THIS IS IT','C') ## returns 'This Is It'
jst('this IS IT','C') ## returns 'This Is It'
Nnn causes the data to be treated as a fixed decimal number with nn decimal places. If nn is not specified, a suitable number of decimal places is used.
jst(0.235,'N') ## returns '0.235'
jst(0.235,'N2') ## returns '0.24'
Fnn causes the data to be treated as a floating decimal number with format specified by nn. The nn argument can be a positive or negative number and has the same meaning as described for the #FDP variable. If nn is not specified, it defaults to the current value of #FDP.
jst(12.35,'-10F9') ## returns ' 12.35'
jst(12.35,'-10F-9') ## returns '1.23500000e+001'
jst(12.35,'-10F-3U') ## returns '1.24E+001'
D causes the data to be treated as a date. The default formatting string is #FD, but you can specify a formatting string as described later. Note - JavaScript client-executed methods do not support the D option.
jst('26/11/97','DC') ## returns '26 Nov 97' if #FD = 'D m Y'
DT causes the data to be treated as a long date and time. The default formatting string is #FDT but you can specify a formatting string using the : (colon) argument as described below. Note - JavaScript client-executed methods do not support the DT option.
jst(#D,'DT') ## returns '26 Nov 97 15:30' if #FDT is 'D m Y H:N'
T causes the data to be treated as a time using the formatting string #FT. You can include a format string using the : (colon) argument as described below. Note - JavaScript client-executed methods do not support the T option.
jst('0620','T') ## returns '06:20' if #FT = 'H:N'
A displays a null value as 'NULL'.
jst(Field1,'A') ## returns 'NULL' when Field1 is null
B causes the data to be treated as Boolean.
jst(1,'LB') ## returns 'yes'
E applies to numbers only and turns on the 'Zero shown empty' attribute.
jst(0,'N2') ## returns '0.00'
jst(0,'N2E') ## returns ''
, (comma) applies to numbers only and turns on the 'Shown like 1,234' attribute.
jst(1234,'N2') ## returns '1234.00'
jst(1234,'N2,') ## returns '1,234.00'
( (open bracket) applies to numbers only and turns on the 'Shown like (1234)' attribute.
jst(-1234,'N2') ## returns '-1234.00'
jst(-1234,'N2(') ## returns '(1234.00)'
jst(1234,'N2(') ## returns '1234.00 '
) (close bracket) applies to numbers only and turns on the 'Shown like 1234-' attribute.
jst(-1234,'N2)') ## returns '1234.00-'
jst(1234,'N2)') ## returns '1234.00 '
+ (plus sign) applies to numbers only and causes positive numbers to be shown with a "+" sign.
jst(1234,'N2+') ## returns '+1234.00'
jst(1234,'N2)+') ## returns '1234.00+'
: (colon) characters following a colon are interpreted as a formatting string. This must be the last option since all characters following it become part of the formatting string. The meaning of the formatting string depends on the type of the data.

The formatting string has a similar format to #FDT if the data is a date/time value, using the following characters:

Y Year (99) H Hour (0..23)
y Year (1999) h Hour (1..12)
C Century (19) N Minutes
M Month (06) S Seconds
m Month (JUN) s Hundredths
n Month (June) A AM/PM
D Day (12) V Short day of week (Fri)
d Day (12th) E Day of year (1–366)
W Day of week (5) G Week of year (1–52)
w Day of week (Friday) F Week of month (1–6)

For example:

jst(#D,'D:w, d n CY')
# returns 'Saturday, 29th November 1997'
cap(jst(#D,'D:V d n Y'))
# returns 'Sat 29th Nov 97'

The formatting string has a similar format to #FT if the data is a time value. #FT is used as the formatting string if a formatting string is not specified for a time.

jst(#T,'T:H-N') ## returns '14-07'

If the data is neither a date nor a time value, and if the formatting string contains an X, the data value is inserted at the position of the X to produce the data value.

jst(0,'BC:The answer is X!')
# returns 'The answer is No!'

The formatting string is concatenated to the left of the data value if the formatting string does not contain an X. The data value is left unchanged if a formatting string is not specified.

jst(12,'-7N2:$') ## returns ' $12.00'
jst(12,'-7N2:£') ## returns ' £12.00'
jst(12,'-8N2:DM') ## returns ' DM12.00'