Purpose

Substringing is the process of retrieving a portion of an alphanumeric string.  It is performed on alphanumeric fields.  For wide fields In-line Substringing must be used.

The In-line Substring operation is replacing this command.  In the future, support for this command will be discontinued; existing applications using SUBSTR should be modified as soon as possible.  Refer to the explanation of In-line Substring for further information.

Syntax

SUBSTR (operand1,operand2,operand3)

Syntax Elements

operand1 is the string to be searched.

On the right-hand side of an assignment it is any valid alphanumeric character string constant, variable, or expression.

On the left-hand side of an assignment it is any alphanumeric character string variable.

operand2 is any valid numeric constant, variable, or expression which represents the starting position in operand1.  It is given in terms of bytes for alphanumeric strings and characters for wide strings.

operand3 is any valid numeric constant, variable, or expression which represents the ending position in operand1.  It is given in terms of bytes for alphanumeric strings and characters for wide strings.

Operation

 

Remarks

 

Example 1
 

$B = SUBSTR ($A,6,10)    if $A = 'Laboratory', causes $B to be 'atory'

$B = SUBSTR ('ABCXYZ89123',4,9)    causes $B to be 'XYZ891'

Example 2

This logic routine is used to parse the field NAME into first and last name.

#X = INDEX (NAME, ' ')
IF #X = 0 THEN
                LAST = NAME
                EXIT
ENDIF
FIRST = SUBSTR (NAME, 1, #X)
#X = #X + 1
#A = LEN (NAME)
LAST = SUBSTR (NAME, #X, #A)

Prior to processing the logic, the fields below contain the following values:

NAME    the last name only, or the first name followed by the last name

LAST      null

FIRST     null

#X         zero

#A         zero

After processing the logic, the fields contain the following values:

NAME     remains unchanged

LAST      the last name from field NAME

FIRST     the first name from field NAME if one exists, otherwise it remains null

#X         the starting position of the last name in field NAME if a first name was provided in field NAME, otherwise it remains zero

#A         the length of the data in field NAME if a first name was provided in field NAME, otherwise it remains zero

Comment on this topic

Topic ID: 520211