Char

This keyword declares a character string with a size limited to a value that cannot exceed 255 characters.

Syntax

Local Char NAME(LENGTH)Local Char NAME(LENGTH)(DIMENSIONS)Variable Char NAME(LENGTH)(DIMENSIONS)Value Char NAME(LENGTH)(DIMENSIONS)Const Char NAME(LENGTH)(DIMENSIONS)

Several variable declarations can be done on the same line, separated by a comma.

Local declarations create the variables in the current local variable class that is not seen by nested or calling sub-programs. The Call / Subprog and func / Funprog insulate the local variables, as well as the calls of method by fmet.

Const, Variable, and Value declarations declare the arguments sent by a Call, func, or fmet. With these syntaxes, the dimensions and the index ranges can be omitted when the parenthesis are present (the dimension and index ranges are defined by the calling program).

Example

# Direct declarationsLocal Char MYTEXT(250), KEYWORDS(30)(1..100) : # 250 max character string, and an array of 30 char keywordsLocal Char KEY_ARRAY(20)(1..10) : # An array of 10 character keys of 20 characters maximum.# A sub-program sending a text and returning a resultFunprog SEND_TEXT(TEXT)Variable Char TEXT()(,) : # A 2 dimensions matrix of character strings is sent as references...End SEND_STATUS# A sub-program storing textsSubprog STORE_TEXTS(TEXT)Value Char TEXT()(1..3) : # An array of 3 elements is sent (a copy is done when passing the arguments)...End

Comments

The dimension is the limit of the length allowed for the variable. Any attempt to assign a longer string or append characters over the limit defined by the length) will truncate the variable to the dimension.

The characters stored are double-byte characters. A Schar declaration exists for single-byte characters, but its use is strongly discouraged.

There is still a Global declaration variable that exists for variables that have to be seen in the scope of a process execution, but its use is strongly discouraged.

Implicit data type conversion

The Char data type will implicitly convert [Date](../4gl/date.md) and [Clbfile](../4gl/clbfile.md) to a Char
Local Char MY_CHAR(30) # Declare CharLocal Date MY_DATEMY_DATE=[31/12/2099]MY_CHAR = MY_DATE # MY_CHAR = "20991231"...Local Clbfile MY_CLOBMY_CLOB=string$(3,"AB")# MY_CLOB = "ABABAB"MY_CHAR=CLOB # MY_CHAR = "ABABAB"

See also

Global, Local, Variable, Value, Const, Tinyint, Shortint, Date, Integer, Float, Double, Decimal, Clbfile, Blbfile, Uuident, Datetime, Instance.