Built-In Functions

The expression can also contain REXX built-in functions: SUBSTR, LEFT, RIGHT, and OVERLAY. Here are some examples:
SET VAR1 = VAR1 !! VAR2 !! 'XX'  
(!! is the concatenation character)
SET VAR2 = SUBSTR(&OYMD1,5,2) + 1
SET VAR3 = RIGHT(VAR1,2,'0')
SET VAR4 = LEFT(VAR4,3)
SET VAR5 = OVERLAY('X',VAR4,5)

Syntax of SUBSTR built-in function

SUBSTR(string,n,length,pad)

The SUBSTR built-in function returns the substring of string that begins at the nth character and is of length length, padded if necessary with the character pad. n must be a positive whole number. If n is greater than LENGTH(string), only padding characters are returned. If you omit length, the rest of the string is returned. The default padding character is a blank. Here are some examples:
SET VAR1 = SUBSTR('abc',2)          ->    VAR1 = 'bc'
SET VAR1 = SUBSTR('abc',2,4)        ->    VAR1 = 'bc  '
SET VAR1 = SUBSTR('abc',2,6,'.')    ->    VAR1 = 'bc....'

Syntax of RIGHT built-in function

RIGHT(string,length,pad)

The RIGHT built-in function returns a string of length length, containing the rightmost length characters of string. The string returned is padded with pad characters, or truncated, on the left, as necessary. The default padding character is a blank. length must be a positive whole number or zero.

Here are some examples:
SET VAR1 = RIGHT('abc  d',8)     ->    VAR1 = '  abc  d'
SET VAR1 = RIGHT('abc def',5)    ->    VAR1 = 'c def'
SET VAR1 = RIGHT('12',5,'0')     ->    VAR1 = '00012'

Syntax of LEFT built-in function

LEFT(string,length,pad)

The LEFT built-in function returns a string of length length, containing the leftmost length characters of string. The string returned is padded with pad characters, or truncated, on the right as necessary. The default padding character is a blank. length must be a positive whole number or zero. The LEFT function is exactly equivalent to SUBSTR(string,1,length,pad)

Here are some examples:
SET VAR1 = LEFT('abc d',8)        ->    VAR1 = 'abc d   '
SET VAR1 = LEFT('abc d',8,'.')    ->    VAR1 = 'abc d...'
SET VAR1 = LEFT('abc  def',7)     ->    VAR1 = 'abc  de'

Syntax of OVERLAY built-in function

OVERLAY(new,target,n,length,pad)

The OVERLAY built-in function returns the string target, which, starting at the nth character, is overlaid with the string new, padded or truncated to length length. (The overlay might extend beyond the end of the original target string.) If you specify length, it must be a positive whole number or zero. The default value for length is the length of new. If n is greater than the length of the target string, padding is added to the left of the new string. The default padding character is a blank, and the default value for n is 1. If you specify n, it must be a positive whole number.

Here are some examples. Assume that VAR1 value is 'ABCDEFGH'.
SET VAR1 = OVERLAY(' ',VAR1,3)         -> VAR1 = 'AB DEFGH'
SET VAR1 = OVERLAY('.',VAR1,3,2)       -> VAR1 = 'AB. EFGH'
SET VAR1 = OVERLAY('qq',VAR1)          -> VAR1 = 'qqCDEFGH'
SET VAR1 = OVERLAY('qq',VAR1,4)        -> VAR1 = 'ABCqqFGH'
SET VAR1 = OVERLAY('123',VAR1,5,6,'+') -> VAR1 = 'ABCD123+++'
The SET instruction returns one of the following return codes:
CC = 0
Instruction correctly processed
CC = 8
Invalid instruction. See the error message.