Concatenation (||) operator joins two operands of any simple data type and returns a single string.
Concatenation operator joins these two strings with a left-to-right association.
For example, (a || b ||c) and ((a || b) ||c) are equivalent expressions.
The precedence of || is greater than that of LIKE or MATCHES but smaller than the precedence of arithmetic operators. Like arithmetic operators, || returns a null value (as a zero-length string) if either operand is NULL.
|| ignores any spaces that appear after the INTEGER and DECIMAL operands but not after operands of the character, FLOAT, and SMALLFLOAT data types.
CLIPPED can remove trailing blanks from values before concatenation in 4gl statements, but TRIM must replace CLIPPED in preparable SQL statements.
This example program shows how to used the CLIPPED operator.
MAIN
DEFINE n, s, x, y, z CHAR(10)
DEFINE result CHAR(50)
LET s = "MyStr X "
LET x = "MyString X"
LET y = "MyString Y"
LET z = "MyString Z"
DISPLAY "n = \"NULL \"" AT 5, 5
DISPLAY "s = \"",s, "\"" AT 6, 5
DISPLAY "x = \"",x, "\"" AT 7, 5
DISPLAY "y = \"",y, "\"" AT 8, 5
DISPLAY "z = \"",z, "\"" AT 9, 5
LET result = x || y || z
DISPLAY "x || y || z = " AT 12,5
DISPLAY result AT 12,30
LET result = x || y + z
DISPLAY "x || y + z = " AT 13,5
DISPLAY result AT 13,30
LET result = (x || (y + z))
DISPLAY "(x || (y + z)) = " AT 14,5
DISPLAY result AT 14,30
LET result = x || n
DISPLAY "x || NULL = " AT 15,5
DISPLAY result AT 15,30
LET result = x || s || z
DISPLAY "x || s || z = " AT 16,5
DISPLAY result AT 16,30
LET result = x || s CLIPPED || z
DISPLAY "x || s CLIPPED || z = " AT 17,5
DISPLAY result AT 17,30
CALL fgl_getkey()
END MAIN
You can use comma (,) to concatenate strings. This operator can be used in statements such as LET, PRINT, MESSAGE, ERROR, and DISPLAY.
However, if you use comma (,) for concatenation, you must remember that it treats null values differently (as compared to ||).
With comma (,), if one string operand is NULL, the result is the other string. For example, in the right expression list of the LET statement, comma has concatenation semantics and ignore any null values. But if all operands in a comma-separated list are NULL, the LET statement returns a null value but represents it as a single blank space.
With comma (,), if one string operand is NULL, the result is the other string. For example, in an expression, comma has the concatenation semantics and will ignore any null values. But if all operands in a comma-separated list are NULL, the expression will return NULL but will represent it as a blank space.
These pairs of expressions are equivalent:
x || y + z and (x || (y + z))
"wxyz " || NULL and NULL
"wxyz " CLIPPED || "AB" and "wxyzAB"