In this section:
A character expression returns an alphanumeric or text value.
A character expression can consist of the following components, highlighted below:
COMPUTE STATE = 'NY' ;
COMPUTE AddressPartTwo = STATE ;
COMPUTE INITIAL/A1= MASK(FIRSTNAME,'9$$$$$$$$$$');
COMPUTE TITLE/A19= 'DR. ' || LAST_NAME;
You can write an expression to concatenate several alphanumeric and/or text values into a single character string. The concatenation operator takes one of two forms, as shown in the following table:
Preserves trailing spaces.
Suppresses trailing spaces.
Any non-character expression that is embedded in a character expression is automatically converted to a character string.
A constant must be enclosed in single or double quotation marks. Whichever delimiter you choose, you must use the same one to begin and end the string. The ability to use either single or double quotation marks provides the added flexibility of being able to use one kind of quotation mark to enclose the string, and the other kind as data within the string itself.
The backslash (\) is the escape character. You can use it to:
When the backslash is used as an escape character, it is not included in the length of the string.
Because you can define a character string using single or double quotation marks, you can use one kind of quotation mark to define the string and the other kind within the string, as in the following expressions:
COMPUTE LastName = "O'HARA"; COMPUTE Msg/A40 = 'This is a "Message"';
You can include a backslash (the escape character) within a string as part of the value by preceding it with a second backslash. For example, the following source code
COMPUTE Line/A40 = 'The characters \\\' are interpreted as \''; . . . TYPE "Escape info: <Line"
Escape info: The characters \' are interpreted as '
When the backslash is used as an escape character, it is not included in the length of the string. For example, a string of five characters and one escape character fits into a five-character variable:
COMPUTE Word/A5 = 'Can\'t'
A path may, depending on the operating system, contain backslashes (\). Because the backslash is the escape character for character expressions, if you specify a path that contains backslashes in an expression, you must precede each of the backslashes with a second backslash. For example:
MyLogo/A50 = "C:\\ibi_img\\AcmeLogo.gif";
The following example shows how to use the SUBSTR function to extract the first initial from a first name, and then use both strong and weak concatenation to produce the last name, followed by a comma, followed by the first initial, followed by a period:
First_Init/A1 = SUBSTR (First_Name, 1, 1); Name/A19 = Last_Name || (', ' | First_Init | '.');
Suppose that First_Name has the value Chris and Last_Name has the value Edwards. The above request evaluates the expressions as follows:
Note that while Last_Name has the format A15, strong concatenation suppresses the trailing spaces.
You can enable a character variable to have a varying length by declaring it either as text (TX) or as alphanumeric with a length of zero (A0). TX and A0 are equivalent.
Specifying a varying length provides several advantages:
The default value of a variable-length character variable is a string of length zero.
Of course, if you assign a string with trailing spaces to either a fixed-length or variable-length character variable, the variable preserves those trailing spaces.
Note that the characteristics of variable-length data source fields differ from those of temporary variables. When declaring a data source field, TX is supported for relational data sources, and has a maximum length of 4094 characters. A0 is not supported for data source fields. For information about data source text fields in WebFOCUS Maintain applications, see the Describing Data With WebFOCUS Language manual.
Variable-length character variables, unlike those of fixed length, never pad strings with spaces.
For example, if you assign a string of 11 characters to a 15-character fixed-length alphanumeric variable, the variable pads the value with four spaces to make up the difference.
For example, the following source code
COMPUTE Name/A15 = 'Fred Harvey' ; TYPE "<<Name End of string" ;
Fred Harvey End of string
If you assign the same string of 11 characters to a variable-length variable, the variable stores the original value without padding it. For example, the following source code, in which Name is changed to be of variable length (specified by A0)
COMPUTE Name/A0 = 'Fred Harvey' ; TYPE "<<Name End of string" ;
Fred HarveyEnd of string
If you assign a string with trailing spaces to a variable (of either fixed or varying length), the variable preserves those spaces. For example, the following source code
COMPUTE Name/A0 = 'Fred Harvey ' ; TYPE "<<Name End of string" ;
Fred Harvey End of string