Datastage STRING Functions
Datastage STRING Functions
AlNum
Description:
Syntax:
AlNum (%string%)
Example:
STRING RESULT
“ABC!@” non-alnum
“ABC123″ alnum
“ABCVF” alnum
“123@#$” non-alnum
“12345″ alnum
“!@#$$” non-alnum
Alpha
Description:
Syntax:
Alpha (%string%)
Example:
STRING RESULT
“ABC!@” non-alpha
“ABC123″ non-alpha
“ABCVF” alpha
“123@#$” non-alpha
“12345″ non-alpha
“!@#$$” non-alpha
CompactWhiteSpace
Description:
Return the string after reducing all consecutive whitespace to a single space
Syntax:
CompactWhiteSpace(%string%)
Example:
Compare
Description:
Syntax:
Compare (%string1%,%string2%,[%justification%])
Default: L
Example:
Compare(“data”,”data”,”L”) = 0
Compare(“data”,”data”,”R”) = 0
Compare(“100″,”50″,”L”) = -1
Compare(“100″,”50″,”R”) = 1
Compare(“100B”,”99A”,”L”) = -1
Compare(“100B”,”99A”,”R”) = 1
ComparNoCase
Description:
Syntax:
CompareNoCase(%string1%,%string2%)
Example:
CompareNumNoCase(“Ask”,”asked”,2) = 0
ComparNum
Description:
CompareNum(%string1%,%string2%,%length%)
Example:
CompareNum(“ask”,”asked”,2) = 0
CompareNum(“ask”,”asked”,4) = -1
CompareNumNoCase
Description:
Syntax:
CompareNumNoCase(%string1%,%string2%,%length%)
Example:
CompareNumNoCase (“ask”,”Asked”,2) = 0
CompareNumNoCase (“ask”,”Asked”,4) = -1
Convert
Description:
Syntax:
Convert(%fromlist%,%tolist%,%expression%)
Example:
Convert(“1234567890″,” “,”Data12stage567″)=Datastage
Convert(“ab”,”12″,”ab3456″)= 123456
Here a=1 and b=2 , All “a” replace by 1 and “b” replace by 2
Count
Description:
Syntax:
Count(%string%,%substring%)
Example:
Count(“Datastage”,”a”) = 3
Dcount
Description:
Syntax:
DCount(%string%,%delimiter%)
Example:
DCount(“I_am_Data_stage_Developer”,”_”) = 5
Default Dcount is 1
Dcount(“Datastage”,”_”) = 1
DownCase
Description:
DownCase(string)
Example:
String= “DATASTAGE”
DownCase(string)= “datastage”
DQuote
Description:
Syntax:
DQuote(%string%)
Example:
Field
Description:
Syntax:
Example:
Field (“ETL_Data_stage_8″,”_”, 2)
Returns : Data
Index
Description:
Syntax:
Index(%string%,%substring%,[%n%])
Example:
Index (string,”re”,1) = 8
Index (string,”re”,2) = 15
Left
Description:
Syntax:
Left(%string%,%length%)
Example:
Left[1,6] = “I Love”
Len
Description:
Length of string in characters
Syntax:
Len(%string%)
Example:
Num
Description:
Syntax:
Num(%string%)
Example:
NUM(“143.23″) = 1 true
NUM(“abc123″)= 0 false
PadString
Description:
Return the string padded with the optional pad character and optional length
Syntax:
PadString(%string%,%char%,%length%)
Example:
PadStr(“Data”,”x”,3) = “Dataxxx”
Right
Description:
Syntax:
Right(%string%,%length%)
Example:
Right[1,3] = “you”
Space
Description:
Syntax:
Space(%length%)
Example:
Space(3) = ” ”
Squote
Description:
Syntax:
SQuote(%string%)
Example:
Str
Description:
Repeat a string.
Syntax:
Str(%string%,%repeats%)
Example:
Arg: 1234567
Str(“0″,10-Len(Arg)):Arg =0001234567
Trim
Description:
Remove all leading and trailing spaces and tabs plus reduce internal
occurrences to one
Syntax:
Trim(%string%,[%stripchar%],[%option%])
D Removes leading and trailing spaces and tabs, and reduces multiple
spaces and tabs to single ones.
Example:
Trim(“..Remove..redundant..dots….”, “.”)
Returns “Remove.redundant.dots”
Returns “Removealldots”
Returns “Remove..trailing..dots”
TrimB
Description:
Syntax:
TrimB(%string%)
Example:
TrimF
Description:
Syntax:
TrimF(%string%)
Example:
Description:
Syntax:
Example:
Description:
Syntax:
UpCase(string)
Example:
String= ” datastage ”
UpCase(string)= “DATASTAGE”
FIELD function
Syntax
FIELD (string, delimiter, occurrence [ ,num.substr] )
Description
Use the FIELD function to return one or more substrings located between specified delimiters in
string.
delimiter evaluates to any character, including field mark, value mark, and subvalue marks. It
delimits the start and end of the substring. If delimiter evaluates to more than one character, only
the first character is used. Delimiters are not returned with the substring.
num.substr specifies the number of delimited substrings to return. If the value of num.substr is an
empty string or less than 1, 1 is assumed. When more than one substring is returned, delimiters
are returned along with the successive substrings.
If either delimiter or occurrence is not in the string, an empty string is returned, unless
occurrence specifies 1. If occurrence is 1 and delimiter is not found, the entire string is returned.
If delimiter is an empty string, the entire string is returned.
If string evaluates to the null value, null is returned. If string contains CHAR(128) (that is,
@NULL.STR), it is treated like any other character in a string. If delimiter, occurrence, or
num.substr evaluate to the null value, the FIELD function fails and the program terminates with
a run-time error message.
Examples
D=FIELD("###DHHH#KK","#",4)
PRINT "D= ",D
The variable D is set to DHHH because the data between the third and fourth occurrence of the
delimiter # is DHHH.
REC="ACADABA"
E=FIELD(REC,"A",2)
PRINT "E= ",E
VAR="?"
Z=FIELD("A.1234$$$$&&",VAR,3)
PRINT "Z= ",Z
Z is set to an empty string since "?" does not appear in the string.
Q=FIELD("+1+2+3ABAC","+",2,2)
PRINT "Q= ",Q
Q is set to "1+2" since two successive fields were specified to be returned after the second
occurrence of "+".
D= DHHH
E= C
Z=
Q= 1+2