Sunday, September 9, 2012

SUBSTR



The SUBSTR built-in function is of particular importance since it is a basic PL/1 string operator. It is a three argument function which allows a reference to be made to a portion of a string variable, i.e., SUBSTR (a, b,c) is a reference to the bth through b + c -1th character (or bit) in the string a.

SUBSTR returns a substring, specified by b and c, of a.

SUBSTR(a,b,c)
         
EX: a="MAINFRAMES"; b=5; c=5; SUBSTR(a,b,c)value will be "FRAME";

a
String expression. It specifies the string from which the substring is extracted. If a is not a string, it is converted to character.
b
Expression that is converted to FIXED BINARY(31,0). b specifies the starting position of the substring in a.
c
Expression that is converted to FIXED BINARY(31,0). c specifies the length of the substring in a. If c is zero, a null string is returned. If c is omitted, the substring returned is position b in a to the end of a.
The STRINGRANGE condition is raised if c is negative or if the values of b and c are such that the substring does not lie entirely within the current length of a. It is not raised when b = LENGTH(a)+1 and c = 0.