Showing posts with label BUILTIN Functions. Show all posts
Showing posts with label BUILTIN Functions. Show all posts

Thursday, September 13, 2012

DATE/TIME BUILT IN FUCNCTIONS


DATEReturns the current date in the pattern YYMMDD
DATETIMEReturns the current date and time in the user-specified pattern or in the default pattern YYYYMMDDHHMISS999
DAYSReturns the number of days corresponding to a date/time pattern string, or the number of days for today's date
DAYSTODATEConverts a number of days to a date/time pattern string
DAYSTOSECSConverts a number of days to a number of seconds
REPATTERNTakes a value holding a date in one pattern and returns that value converted to a date in a second pattern
SECSReturns the number of seconds corresponding to a date/time pattern string, or the number of seconds for today's date
SECSTODATEConverts a number of seconds to a date/time pattern string
SECSTODAYSConverts a number of seconds to a number of days
TIMEReturns the current time in the pattern HHMISS999
VALIDDATEIndicates if a string holds a valid date
WEEKDAYReturns the day of the week corresponding to the current day or specified DAYS value
Y4DATETakes a date value with the pattern 'YYMMDD' and returns the date value with the two-digit year widened to a four-digit year
Y4JULIANTakes a date value with the pattern 'YYDDD' and returns the date value with the two-digit year widened to a four-digit year
Y4YEARTakes a date value with the pattern 'YY' and returns the date value with the two-digit year widened to a four-digit year

TRANSLATE


TRANSLATE : SUBSTITUTES ONE CHARACTER/BIT WITH ANOTHER

SYNTAX:  TRANSLATE(X,Y,Z)

X = SOURCE STRING
Y = REPLACEMENT STRING
Z = POSITION STRING

EX: TRANSLATE(X, Y, Z);

X= '1GOLDEN'
Y='ABCSILVER'
Z='WXYGOLDEN'

NOW FOR EACH CHARACTER OF X, A SEARCH OF Z IS MADE AND IF MATCH IS FOUND THE CORRESPONDING POSITIONAL CHARACTER IN Y IS RETURNED.

SO AFTER EXECUTING TRANSLATE(X,Y,Z), THE X BECOMES '1SILVER'

REPEAT


 
IT TAKES A GIVEN STRING VALUE AND FORMS A NEW STRING CONSISTING OF STRING VALUE CONCATENATED WITH ITSELF A SPECIFIED NUMBER OF TIMES.

SYNTAX:      REPEAT ( M, N )

M = STRING THAT HAS TO BE REPEATED
N = DECIMAL INTEGER CONSTANT/VARIABLE  THAT MUST  BE GREATER THAN '0'

EX:  REPEAT('HYDERABAD ', 2) RESULTS IN  'HYDERABAD HYDERABAD'

VERIFY


VERIFY returns a FIXED value indicating the position in x of the leftmost character that is not in y. It also allows you to specify the location within x at which to begin processing.

VERIFY(x,y,n)


x
Expression.x should have CHARACTER type, and if not, it is converted thereto.
y
Expression.y should have CHARACTER type, and if not, it is converted thereto.
n
Expression n specifies the location within x where processing begins.n should have FIXED type, and if not, it is converted thereto.
If all the characters in x do appear in y, a value of zero is returned. If x is the null string, a value of zero is returned. If x is not the null string andy is the null string, the value of n is returned. The default value for n is one.
n must be greater than 0 and no greater than 1 + LENGTH(x).
If n = LENGTH(x) + 1, the result is zero.

INDEX

INDEX returns the starting position of a substring within a string.
INDEX(STRING,SUBSTRING,BACK) 

EX:
1. INDEX('FORTRAN', 'R') has the value 3  
2. INDEX('FORTRAN', 'R',BACK=TRUE) has the value 5  
BACK is an optional parameter/argument.

Case (i): If BACK is absent or present with the value .FALSE., the result is the minimum positive value of I such that STRING (I : I + LEN (SUBSTRING) - 1) = SUBSTRING or zero if there is no such value. Zero is returned if LEN (STRING) < LEN (SUBSTRING). One is returned if LEN (SUBSTRING) = 0.

Case (ii): If BACK is present with the value .TRUE., the result is the maximum value of I less than or equal to LEN (STRING) - LEN (SUBSTRING) + 1, such that STRING (I : I + LEN (SUBSTRING) - 1) =  SUBSTRING or zero if there is no such value. Zero is returned if LEN (STRING) < LEN (SUBSTRING) and LEN (STRING) + 1 is returned if LEN (SUBSTRING) = 0.

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.