Datastage Function
Datastage Function
Alpha(%string%)
AlNum(%string%)
This set of functions is used to check the contents of a string.
Alpha(%string%)
Checks if %string% contains only alpha characters (A-Z,a-z)
Returns: 1 if true, 0 otherwise.
Examples:
Alpha("this is a test!") = 0
Alpha("this is a test") = 0
Alpha("thisisatest") = 1
AlNum(%string%>
Checks if %string% contains only alph-numeric characters (A-Z,a-z,0-9)
Returns: 1 if true, 0 otherwise.
Examples:
AlNum("1 2 3") = 0
AlNum("thisisatest123") = 1
Alpha, AlNum
Alpha(%string%)
AlNum(%string%)
This set of functions is used to check the contents of a string.
Alpha(%string%)
Checks if %string% contains only alpha characters (A-Z,a-z)
Returns: 1 if true, 0 otherwise.
Examples:
Alpha("this is a test!") = 0
Alpha("this is a test") = 0
Alpha("thisisatest") = 1
AlNum(%string%>
Checks if %string% contains only alph-numeric characters (A-Z,a-z,0-9)
Returns: 1 if true, 0 otherwise.
Examples:
AlNum("1 2 3") = 0
AlNum("thisisatest123") = 1
Compare, CompareNoCase, CompareNum,
CompareNumNoCase
Compare(%string1%, %string2% [,"%justification%"])
CompareNoCase(%string1%, %string2%)
CompareNum(%string1%, %string2%, %length%)
CompareNumNoCase(%string1%, %string2%, %length%)
This set of functions is used to compare strings.
Examples:
Compare("horse","horse","L") = 0
Compare("horse","horse","R") = 0
Compare("zebra","ardvark","L") = 1
Compare("zebra","ardvark","R") = 1
Compare("100","20","L") = -1
Compare("100","20","R") = 1
Compare("100B","99A","L") = -1
Compare("100B","99A","R") = 1
Compare("A99","B100","L") = -1
Compare("A99","B100","R") = 1
CompareNoCase("Zebra","zebra") = 0
CompareNum("ant","antler",3) = 0
CompareNum("ant","antler",4) = -1
CompareNumNoCase("Ant","antler",3) = 0
Convert
Convert(%from%,%to%,%string%)
This function is used to translate from one set of characters to
another set.
Return:
a string with with translated characters.
Examples:
Convert("-.","/:","23-01-2009 18.09.33") = "23/01/2009 18:09:33"
Hint
Use convert to remove unwanted characters
Convert("0123456789_","","FILENAME_01") = "FILENAME"
Return:
integer
Examples:
Count("this is an island","is") = 3
DCount(%string%,%delimiter%)
This function returns the number of fields in a delimited string.
Return:
integer
Examples:
Count("this is an island"," ") = 4
Len(%string%)
This function returns the number of characters in %string%
Return:
integer
Examples:
Len("this is an island") = 17
DateFromDaysSince, DateFromJulianDay,
DaysSinceFromDate, JulianDayFromDate,
MonthFromDate, MonthDayFromDate,
NextWeekdayFromDate,
PreviousWeekDayFromDate,
WeekdayFromDate, YearFromDate,
YeardayFromDate, YearWeekFromDate
DateFromDaysSince(%days%,%date1%)
DateFromJulianDay(%jdate%)
DaysSinceFromDate(%date1%,%date2%)
JulianDayFromDate(%date%)
MonthFromDate(%date%)
MonthDayFromDate(%date%)
NextWeekdayFromDate(%date%,%dayofweek%)
PreviousWeekdayFromDate(%date%,%dayofweek%)
WeekdayFromDate(%date%)
YearFromDate(%date%)
YeardayFromDate(%date%)
YearweekFromDate(%date%)
DateFromDaysSince(%days%,%date1%)
Returns a date %days% from %date1%
Example:
let days = 10
let date1 = 2001-01-01
DateFromDaysSince(days,date1) = 2001-01-11
DaysSinceFromDate(%date1%,%date2%)
Returns the number of days between two dates
Example:
let date1 = 2001-01-01
let date2 = 2001-01-07
DaysSinceFromDate(date1,date2) = -6
DateFromJulianDay(%jdate%)
Converts a Julian date to a date
Example:
let jdate = 2451911
DateFromJulianDay(jdate) = 2001-01-01
JulianDayFromDate(%date%)
Converts a date to a Julian date
Example:
let date = 2001-01-01
JulianDayFromDate(date) = 2451911
Hint:
Use Julian days whenever you need to do date arithmetic
MonthFromDate(%date%)
returns the month portion of a date
Example:
let date = 2001-01-07
MonthFromDate(date) = 1
MonthDayFromDate(%date%)
returns the day of month
Example:
let date = 2001-01-07
MonthDayFromDate(date) = 7
NextWeekdayFromDate(%date%,%dayofweek%)
returns the date on which the next %dayofweek% falls.
Example:
let date = 2001-01-01
NextWeekdayFromDate(date,"wed") = 2001-01-03
PreviousWeekdayFromDate(%date%,%dayofweek%)
returns the date on which the previous %dayofweek% falls.
Example:
let date = 2001-01-01
PreviousWeekdayFromDate(date,"friday") = 2000-12-29
WeekdayFromDate(%date%)
returns a zero-based interger indicating the day of week (0=Sunday)
An optional argument can be used to indicate a different start of
week.
Example:
let date = 2001-01-01
WeekdayFromDate(date) = 6
WeekdayFromDate(date,"Mon") = 0
let date = 2001-01-07
WeekdayFromDate(date) = 0
WeekdayFromDate(date,"Mon") = 6
YearFromDate(%date%)
returns the year portion of a date
Example:
let date = 2001-01-07
YearFromDate(date) = 2001
YeardayFromDate(%date%)
returns the day of year
Example:
let date = 2001-01-07
YeardayFromDate(date) = 7
YearweekFromDate(%date%)
returns the week of year
Example:
let date = 2001-01-07
YearweekFromDate(date) = 1
DecimalToDecimal, DecimalToString,
StringToDecimal
DecimalToDecimal(%decimal% [,"%rtype%"])
DecimalToString(%decimal% [,"suppress_zero" | "fix_zero"])
StringToDecimal(%string% [,"%rtype%"])
This set of functions is used to manipulate decimal values.
DecimalToDecimal
Return:
a decimal value
DecimalToString
Return:
a string representation of the decimal value.
StringToDecimal
Return:
a decimal value
Note that the lvalue data type defines rounding operations. In the
examples below,
the lvalue is specified for each example.
Examples:
Round down
DecimalToDecimal(0000000001234.567890,"floor") = 00000000000001234.56
(lvalue=19,2)
Round up
DecimalToDecimal(0000000001234.567890,"ceil") = 00000000000001234.57
(lvalue=19,2)
Round nearest
DecimalToDecimal(0000000001234.567890,"round_inf") =
00000000000001234.57 (lvalue=19,2)
DecimalToDecimal(0000000001234.565890,"round_inf") =
00000000000001234.57 (lvalue=19,2)
DecimalToDecimal(-0000000001234.565890,"round_inf") = -
00000000000001234.56 (lvalue=19,2)
Default is "trunc-zero"
DecimalToDecimal(0000000001234.567890) = 00000000000001234.57
(lvalue=19,2)
Notes:
1. There is a leading character in the string representation of
decimal values. The character
can be either a space or a negative sign.
2. As far as I can tell, "fix_zero" does not have any effect.
3. Using "suppress_zero" suppresses leading and trailing zeros as well
as the decimal point if the value
has no fractional component.
Hint: To create a string such as "-1234.50", use the following:
Let str = "-00000000000001234.50"
s1 = Trim(str[1,1]) = "-"
s2 = Right(str,Len(str)-1) = "00000000000001234.50"
s3 = Trim(s2,"0","L") = "1234.50"
result = s1:s3
= Trim(str[1,1]):Trim(Right(str,Len(str)-1),"0","L")
= "-1234.50"
UpCase, DownCase
UpCase(%str%)
DownCase(%str%)
This functions are used to convert from uppert to lower case or vice-
versa.
Return:
a string with case conversion
Examples:
UpCase("jack robinson") = "JACK ROBINSON"
DownCase("PETER RABBIT") = "peter rabbit"
Examples:
let string = "one for the road"
Field(string," ",2) = "for"
Field(string," ",3,2) = "the road"
%string%[%start%,%length%]
Return:
%length% characters of string starting at %start%
Examples:
let string = "one for the road"
string[1,3] = "one"
string[5,3] = "for"
Right(%string%,%length%)
Return:
%length% rightmost characters
Examples:
let string = "one for the road"
Right[1,4] = "road"
Left(%string%,%length%)
Return:
%length% leftmost characters
Examples:
let string = "one for the road"
Left[1,7] = "one for"
Index
Index(%string%,%substring%,[%n%])
This function finds the nth occurance of substring within string
Return:
a one-based integer pointing to the start of the substring within
string
Examples:
let string = "these are the results"
Index(string,"re",1) = 8
Index(string,"re",2) = 15
Examples:
s = @NULL
IsNotNull(s) = @FALSE
IsNull(s) = @TRUE
NullToValue(s,"some_string") = "some_string"
NullToEmpty(s) = ""
i = @NULL
NullToZero(i) = 0
i = @NULL
NullToValue(i,42) = 42
Return:
string
Examples:
PadStr("Title","*",3) = "Title***"
Space(%length%)
This function returns a string made up of %length% spaces
Return:
string
Examples:
Space(3) = " "
Str(%string%,%repeats%)
This function returns a string made up of %string% repeated %repeat%
times
Return:
string
Examples:
Str("happy ",3) = "happy happy happy "