When you define a variable as a CHARACTER type, its default initial value is an empty character string (""). You can initialize the variable to set the initial value. In ABL, you can modify the value of a CHARACTER variable, provided the result does not exceed 32K characters.
VAR CHAR cURLString.
		  
VAR CHAR cWarehouseName = "Bldg A".

ABL provides many operators and functions for working with strings. All of these can be used with CHARACTER data, and most of these can also be used with LONGCHAR data.

String functions and operators Description
+ Concatenation operator Joins two character strings or expressions.
ASC function Converts a character expression representing a single character into the corresponding ASCII (or internal code page) value, returned as an INTEGER.
BEGINS operator Returns true if a string begins with a pattern.
CAPS function Returns the uppercase version of a string.
CHR function Converts an integer value to its corresponding character value.
COMPARE function Compares two strings using a specified comparison operator or function.
FILL function Generates a string made up of a character string that is repeated a specified number of times.
INDEX function Searches the string for a substring, and if it is found, then returns the location of the substring.
LC function Returns the lowercase version of a string.
LEFT-TRIM function Removes characters from the beginning of a string, including leading blanks.
LENGTH function Returns the length of the string.
MATCHES operator Performs a wildcard match for a string within another string. By default MATCHES is not case sensitive.
OVERLAY statement Inserts content from a specified expression into a field or variable replacing existing characters, bytes, or columns.
R-INDEX function Returns an INTEGER value that indicates the position of the target string within the source string. In contrast to the INDEX function, R-INDEX performs the search from right to left.
REPLACE function Returns a string with specified substring replacements. The data type of the returned value matches the data type of the expression passed to the function.
RIGHT-TRIM function Removes characters from the end of a string, including trailing blanks.
STRING function Converts a value of another data type into a character value.
SUBSTITUTE function Returns a character string that is made up of a base string plus the substitution of arguments in the string.
SUBSTRING function Returns a substring of a string based on the locations specified in the string.
TRIM function Removes characters from the beginning or end of a string, including leading or trailing blanks.

For additional information, see ABL string manipulation functions.

The next sections discuss how to use the concatenation operator (+) and the SUBSTITUTE, REPLACE, and STRING functions. These are commonly used for string manipulation. For more information about the other functions listed, click on the links. .

Concatenation operator (+)

You can combine character strings by concatenating them. Concatenation means putting two or more strings together in sequence. For example, the string "PRO" concatenated with the string "GRESS" becomes "PROGRESS".

You use the string + Concatenation operator to combine two or more strings:
string1 + string2 + string3

If you want spaces or punctuation to appear between string values, then you must explicitly include them. For example, to display a person's full name, you might write the following code:

VAR CHAR fullName.
VAR CHAR firstName = "Alexander".
VAR CHAR middleInitial = "T".
VAR CHAR lastName = "Great".

fullName = firstName + " " + middleInitial + ". " + lastName.

MESSAGE "My name is: " fullName.

Running the code produces the following output:

My name is:  Alexander T. Great

SUBSTITUTE function

The SUBSTITUTE function returns a character string that is made up of a base string plus the substitution of parameter values in the string. This function allows you to use a single string in place of concatenated strings.

new-string = SUBSTITUTE( base-string [ , 
arg ] ... ) 
new-string
The string returned by the SUBSTITUTE function.
base-string
A character string optionally containing substitution parameters of the form &n, where n is an integer between 1 and 9, inclusive.
arg
A constant, field name, variable, or expression that results in a character string value. These values replace substitution parameters in base-string.

The following example code uses substitution rather than concatenation, but produces the same output as the previous example. In this example, firstName replaces &1; middleInitial replaces &2; and lastName replaces &3.

VAR CHAR newString.
VAR CHAR firstName = "Alexander".
VAR CHAR middleInitial = "T".
VAR CHAR lastName = "Great".

newString = SUBSTITUTE("My name is: &1 &2. &3", firstName, middleInitial, lastName).

MESSAGE newString.

REPLACE function

You can use the REPLACE function to replace characters in a variable with an expression.

The syntax for the REPLACE function is:

new-string = REPLACE(source-string, from-string, to-string)

new-string
The string returned by the REPLACE function.
source-string
Specifies the base string to make replacements in. The source-string parameter can be any expression that evaluates to a string. The REPLACE function does not change the value of source-string itself, unless new-string and source-string refer to the same variable.
from-string
Specifies the substring to replace. The from-string parameter can be any expression that evaluates to a string. Each occurrence of from-string within source-string is replaced.
to-string
Specifies the replacement substring. The to-string parameter can be any expression that evaluates to a string. Each occurrence of from-string in source-string is replaced by to-string.

Example: Replace a text string

The following example code creates a list of departments separated by commas. The REPLACE function changes the separator from a comma to a bar surrounded by spaces, for better readability.
VAR CHAR cDeptList.

FOR EACH Department:
  cDeptList = cDeptList + "," + DeptName.
end.
MESSAGE cDeptList VIEW-AS ALERT-BOX.

cDeptList = REPLACE(cDeptList, ",", " | ").
MESSAGE cDeptList VIEW-AS ALERT-BOX.
The example code produces the following output:
,Consulting,Administration,Marketing,Sales,Training,Development,Finance,Shipping
 | Consulting | Administration | Marketing | Sales | Training | Development | 
Finance | Shipping