APP Connect Functions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Functions in ACE

ESQL string manipulation functions:

 CONTAINS is a string manipulation function that manipulates all string data


types (BIT, BLOB, and CHARACTER), and returns a Boolean value

Example : CONTAINS('Hello World!', 'ello'); --> returns TRUE

Example : CONTAINS('Hello World!', 'daisy'); --> returns TRUE

 ENDSWITH is a string manipulation function that manipulates all string


data types (BIT, BLOB, and CHARACTER), and returns a Boolean value

1. Example : ENDSWITH('Hello World!', 'World!'); --> returns TRUE


2. Example : ENDSWITH('Hello World!', 'World'); --> returns FALSE

 LEFT is a string manipulation function that returns a string consisting of the


source string truncated to the LEFT given by the length expression.

Example : LEFT('HelloWorld!', 5); --> returns Hello

LENGTH function is used for string manipulation on all string data types
(BIT, BLOB, and CHARACTER) and returns an integer value.
Example : LENGTH('Hello World!'); --> returns 12

 LOWER and LCASE functions are equivalent, and manipulate


CHARACTER string data; they both return a new character string, which is
identical to source_string, except that all uppercase letters are replaced
with the corresponding lowercase letters.
 LOWER('22 Railway Cuttings'); --> returns 22 railway cuttings
 LCASE('ABCD'); --> returns abcd
 LCASE('22 Railway Cuttings'); --> returns 22 railway cuttings

 LTRIM, TRIM, RTRIM are equivalent, that is removes trailing and leading
singletons from a string depending on the function
 TRIM('b' FROM 'aaabBb'); --> returns aaabB
 TRIM(TRAILING 'b' FROM 'aaabBb'); --> returns aaabB
 TRIM('b' FROM 'bbbaaabbb'); --> returns aaa
 OVERLAY is a string manipulation function that manipulates all string data
types (BIT, BLOB, and CHARACTER) and replaces part of a string with a
substring.
OVERLAY ('ABCDEFGHIJ' PLACING '1234' FROM 4 FOR 3); --> returns ABC1234GHIJ

OVERLAY (‘NANDAKUMAR’ PLACING ‘KISHU’ FROM 5 FOR 2) —


returns ‘NANDKISHUUMAR’

 POSITION is a string manipulation function that manipulates all data types


(BIT, BLOB, and CHARACTER), and returns the position of one string
within another.

POSITION returns an integer giving the position of one string


(SearchExpression) in a second string (SourceExpression). A position of
one corresponds to the first character of the source string.
 POSITION('Village' IN 'Hursley Village'); --> returns 9
 POSITION('Town' IN 'Hursley Village'); --> returns 0
 POSITION ('B' IN 'ABCABCABCABCABC'); --> returns 2
 POSITION ('D' IN 'ABCABCABCABCABC'); --> returns 0

 POSITION ('A' IN 'ABCABCABCABCABC' FROM 4); --> returns 4


 POSITION ('C' IN 'ABCABCABCABCABC' FROM 2); --> returns 3

 POSITION ('B' IN 'ABCABCABCABCABC' REPEAT 2); --> returns 5


 POSITION ('C' IN 'ABCABCABCABCABC' REPEAT 4); --> returns 12

 POSITION ('A' IN 'ABCABCABCABCABC' FROM 4 REPEAT 2); --> returns 7


 POSITION ('AB' IN 'ABCABCABCABCABC' FROM 2 REPEAT 3); --> returns 10

 POSITION ('A' IN 'ABCABCABCABCABC' REPEAT -2); --> returns 10


 POSITION ('BC' IN 'ABCABCABCABCABC' FROM 12 REPEAT -3); --> returns 5

 REPLACE returns a string consisting of the source string, with each


occurrence of the search string replaced by the replace string
 REPLACE('AAAAABCDEFGHAAAABCDEFGH', 'AA', 'XYZ'); --> RESULT =
XYZXYZABCDEFGHXYZXYZBCDEFGH
 REPLICATE is used to replace the expression based on number of times
given
 REPLICATE('*', LENGTH('nanda')); --> *****
 REPLICATE('nanda',3); --> nandanandananda

 RIGHT is a string manipulation function that truncates a string.


 RIGHT('www.ibm.com',5); --> m.com
 SPACE is a string manipulation function that consists of a defined number
of blank spaces.
 SPACE(LENGTH('ravi')); --> returns empty ' '

 STARTSWITH is a string manipulation function returns a Boolean value


 STARTSWITH('Hello World!', 'Hello'); --> returns TRUE
 STARTSWITH('Hello World!', 'World'); --> returns FALSE

 SUBSTRING is a string manipulation function that extracts characters from


a string to create another string.
 SUBSTRING('Hello World!' FROM 7 FOR 4); --> returns 'Worl'
 SUBSTRING('Hello World!' BEFORE 'World'); --> returns 'Hello '
 SUBSTRING('Hello World!' BEFORE 'World' FOR 3); --> returns 'lo '
 SUBSTRING('Hello World!' BEFORE 'e'); --> returns 'H'
 SUBSTRING('Hello World!' AFTER 'World'); --> returns '!'
 SUBSTRING('Hello World!' AFTER 'W' FOR 2); --> returns 'or'
 SUBSTRING('Hello World!' AFTER 'P'); --> returns empty ''

 TRANSLATE is a string manipulation function that replaces specified


characters in a string.
 TRANSLATE('ABCABC','B','*'); --> returns A*CA*C
 TRANSLATE('NANDAKISHORE', 'DAKI', 'BILL'); --> returns 'NINBILLSHORE'

 UPPER and UCASE are equivalent string manipulation functions that


convert lowercase characters in a string to uppercase.
 UPPER('ABCD'); --> returns 'ABCD'
 UCASE('abc123'); --> returns 'ABC123'

 URLDECODE function copies the source string and replaces any 3-


character sequences that start with a % (percent) character followed by 2
hexadecimal digits with the UTF-8 character represented by those
hexadecimal digits.
 DECLARE original CHARACTER 'Address=Hampshire,United Kingdom';
 DECLARE encoded CHARACTER URLENCODE(original);

Result: Address%3DHampshire%2CUnited%20Kingdom

 DECLARE decoded CHARACTER URLDECODE(encoded);

Result: Address=Hampshire,United Kingdom

 URLENCODE function uses RCF3986, the source string is copied into the
UTF-8 code page and each byte is replaced by a % (percent) symbol
followed by the 2 hexadecimal digits that represent the replaced
character's value. The following characters are not replaced:

 [- (hyphen), _ (underscore), . (period), ~ (tilde), alphanumeric characters]


An example that uses RCF3986:

 DECLARE original CHARACTER 'Name=John Smith/Address=Hampshire~United


Kingdom/Telephone=+441962808000/';
 DECLARE encoded CHARACTER URLENCODE(original);

Result: Name%3DJohn%20Smith%2FAddress%3DHampshire~United%20Kingdom
%2FTelephone%3D%2B441962808000%2F'
An example that uses RCF1738:
 DECLARE original CHARACTER 'Name=John Smith/Address=Hampshire~United
Kingdom/Telephone=+441962808000/';
 DECLARE encoded CHARACTER URLENCODE(original MODE RFC1738);

Result: Name%3DJohn+Smith%2FAddress%3DHampshire%7EUnited+Kingdom
%2FTelephone%3D%2B441962818000%2F'

ESQL datetime functions:

EXTRACT FUNCTION : The EXTRACT function extracts fields (or


calculates values) from datetime values and intervals.
 EXTRACT(YEAR FROM CURRENT_DATE); --> returns CHARACTER:2023/2023
 --SET op2 = EXTRACT(HOUR FROM LOCAL_TIMEZONE); --> returns
Exception:Cannot extract %3 field from value %4
 EXTRACT (DAYS FROM DATE '2000-02-29'); --> returns 730179(but actual
days upto 96-04-2023)
 EXTRACT (DAYOFYEAR FROM CURRENT_DATE); --> returns CHARACTER:96
 CURRENT_TIMESTAMP; --> returns CHARACTER:TIMESTAMP '2023-04-06
11:44:43.715707'

CURRENT_DATE FUNCTION : The CURRENT_DATE datetime function


returns the current date.
 CURRENT_DATE; --> returns CHARACTER:DATE '2023-04-06'/CHARACTER:DATE
'2023-04-06'

CURRENT_TIME FUNCTION :The CURRENT_TIME datetime function


returns the current local time.
 CURRENT_TIME; --> returns CHARACTER:TIME '11:44:43.715707'

CURRENT_TIMESTAMP FUNCTION :The CURRENT_TIMESTAMP


datetime function returns the current date and local time in ISO8601 format.
 CURRENT_TIMESTAMP; --> returns CHARACTER:TIMESTAMP '2023-04-06
11:44:43.715707'

CURRENT_GMTDATE FUNCTION :The CURRENT_GMTDATE datetime


function returns the current date in the GMT time zone.
 CURRENT_GMTDATE;--> returns CHARACTER:DATE '2023-04-06'
CURRENT_GMTTIME FUNCTION :The CURRENT_GMTTIME datetime
function returns the current time in the GMT time zone.
 CURRENT_GMTTIME; --> returns CHARACTER:GMTTIME '06:14:43.715707'

CURRENT_GMTTIMESTAMP FUNCTION : The


CURRENT_GMTTIMESTAMP datetime function returns the current date
and time in the GMT time zone.
 CURRENT_GMTTIMESTAMP; --> returns CHARACTER:GMTTIMESTAMP '2023-04-06
06:14:43.715707'

LOCAL_TIMEZONE FUNCTION :The LOCAL_TIMEZONE datetime


function returns the displacement of the local time zone from GMT.
 LOCAL_TIMEZONE; --> returns CHARACTER:INTERVAL '330' MINUTE

ESQL field functions:

ASBITSTREAM function
The ASBITSTREAM field function generates a bit stream for the subtree of
a given field according to the rules of the parser that owns the field.
ENCODING -> CCSID -> SET -> TYPE -> FORMAT -> OPTIONS

DECLARE options INTEGER BITOR(FolderBitStream, ValidateContent,


ValidateValue);
SET result = ASBITSTREAM(cursor OPTIONS options CCSID 1208);
SET Result =
ASBITSTREAM(Environment.Variables.MQRFH2.Data,,1208,,,,options);

BITSTREAM function (deprecated)


The BITSTREAM field function returns a value that represents the bit
stream that is described by the given field and its children. Its use is
deprecated; use the newer ASBITSTREAM function instead.
BITSTREAM(Root.MQMD);
BITSTREAM(Root.MQMD.UserIdentifier);

FIELDNAME function
SET X=FIELDNAME(InputBody.*[<]); -->BLOB/CHARACTER:Data
SET Y=FIELDNAME(InputBody.F1.*[<]);-->empty
SET Z=FIELDNAME(InputBody.*[<].*[<]);
-->empty/CHARACTER:Purchases/CHARACTER:Invoice

DECLARE ns NAMESPACE 'urn:nid:xxxxxx';


SET AA=FIELDNAME(InputBody.ns:F1.*[<]); -->empty
SET op13 = X; --> returns CHARACTER:Data
SET op14 = Y; --> returns empty
SET op15 = Z; --> returns CHARACTER:Invoice
SET op16 = AA; --> returns empty
FIELDTYPE function
IF FIELDTYPE(InputRoot.XMLNS.Message1.Name)
IS NULL THEN
--SET BB = "name is null"; -- Getting Deployment error: The correlation
name 'name is null' is not valid.
ELSE
--SET BB = "'name is existed'";-- Getting Deployment error: The correlation
name ''name is existed'' is not valid.
END IF;
--SET op17 = BB; --> returns commented

FIELDVALUE function
XML Input:
<Data>
<Qty Unit="Gallons">1234</Qty>
</Data>
SET CC = OutputRoot.XMLNSC.Data.Quantity =
FIELDVALUE(InputRoot.XMLNSC.Data.Qty);--with Fieldvalue
SET DD = OutputRoot.XMLNSC.Data.Quantity = InputRoot.XMLNSC.Data.Qty;--with
out Fieldvalue
SET op18 = CC; --> returns <Data><Quantity>1234</Quantity></Data>
SET op19 = DD; --> returns <Data><Quantity Unit="Gallons">1234</Quantity></Data>

SAMEFIELD function: The SAMEFIELD field function tells you whether


two field references point to the same target.
SET Result = SAMEFIELD(ref1,OutputRoot.XMLNSC.Data.Purchases[2]);-->
FALSE/FALSE

SET op20 = Result; --> returns CHARACTER:FALSE


FOR function:The FOR field function evaluates an expression and assigns
a resulting value of TRUE, FALSE, or UNKNOWN.
FOR ALL Body.Invoice.Purchases."Item"[] AS I (I.Quantity <= 50);
If you specify the ALL keyword, the function iterates over all instances of
the field Item inside Body.Invoice.Purchases and evaluates the
predicate I.Quantity <= 50. If the predicate evaluates to:

 TRUE (if the field is empty, or for all instances of Item) return TRUE.
 FALSE (for any instance of Item) return FALSE.
 Anything else, return UNKNOWN.

FOR ANY Body.Invoice.Purchases."Item"[] AS I (I.Title = 'The XML


Companion');
The ANY and SOME keywords are equivalent. If you use either, the
function iterates over all instances of the field Item
inside Body.Invoice.Purchases and evaluates the predicate I.Quantity <=
50. If the predicate evaluates to:
 FALSE (if the field is empty, or for all instances of Item) return
FALSE.
 TRUE (for any instance of Item) return TRUE.
 Anything else, return UNKNOWN.

LASTMOVE function:
The LASTMOVE field function tells you whether the last MOVE function
succeeded.

LIST Functions :
CARDINALITY function:
The CARDINALITY function returns the number of elements in a list
Syntax:
CARDINALITY (ListExpression)
SET OutputRoot.XMLNSC.Data.Purchases[] = InputRoot.XMLNSC.Data.Purchases[];

DECLARE CountF1F12 INT


CARDINALITY(SELECT F.* FROM OutputRoot.XMLNS.Data.Source.STUDENTDETAILS[]
AS F where F.FLAG = 'N');

SET op21 = CountF1F12; --> returns 5

THE function:
The THE function returns the first element of a list.If ListExpression contains
one or more elements; THE returns the first element of the list. In all other
cases, it returns an empty list.
Syntax:
THE (ListExpression)
SET OutputRoot.XMLNSC.Data.Purchases[] = InputRoot.XMLNSC.Data.Purchases[];

DECLARE CountF1 INT THE(SELECT F.* FROM


OutputRoot.XMLNS.Data.Source.STUDENTDETAILS[] AS F where F.FLAG = 'N');

SET op24 = CountF1; --> returns Exception(Illegal value for parameter)

SINGULAR function : returns a Boolean value that indicates whether a list


contains exactly one element.

Syntax: DECLARE Field1Unique BOOLEAN


SINGULAR(OutputRoot.XMLNS.Data.Source.F1[]);
SET OutputRoot.XMLNSC.Data.Purchases[] = InputRoot.XMLNSC.Data.Purchases[];

DECLARE Field1F12Unique BOOLEAN

SINGULAR(SELECT F.* FROM


OutputRoot.XMLNS.Data.Source.STUDENTDETAILS[] AS F where F.FLAG = 'N');
SET op23 = Field1F12Unique; --> returns 2

EXISTS function : returns a Boolean value to indicate whether a list


contains at least one element (that is, whether the list exists).
Syntax:DECLARE Field1Exists BOOLEAN
EXISTS(OutputRoot.XMLNS.Data.Source.F1[]);
SET OutputRoot.XMLNSC.Data.Purchases[] = InputRoot.XMLNSC.Data.Purchases[];

DECLARE Field1F12Exists BOOLEAN


EXISTS(SELECT F.* FROM
OutputRoot.XMLNS.Data.Source.STUDENTDETAILS[] AS F where F.FLAG = 'N');

SET op22 = Field1F12Exists; --> returns 6

Complex ESQL functions:

CASE function:
CASE is a complex function that has two forms; the simple-when form and
the searched-when form. In either form CASE returns a result, the value of
which controls the path of subsequent processing.
DECLARE CurrentMonth CHAR;
DECLARE MonthText CHAR;
-- SET CurrentMonth = SUBSTRING(InputBody.Invoice.InvoiceDate FROM
6 FOR 2);-->retuns empty
SET CurrentMonth =
SUBSTRING(InputRoot.XMLNSC.Invoice.InvoiceDate FROM 6 FOR 2);-->retuns
empty
SET MonthText = -->Second half of year
CASE CurrentMonth
WHEN '01' THEN 'January'
WHEN '02' THEN 'February'
WHEN '03' THEN 'March'
WHEN '04' THEN 'April'
WHEN '05' THEN 'May'
WHEN '06' THEN 'June'
ELSE 'Second half of year'
END;

DECLARE CurrentMonth1 CHAR;


DECLARE CurrentYear1 CHAR;
DECLARE MonthText1 CHAR;

SET CurrentMonth1 = SUBSTRING(InputRoot.XMLNSC.Invoice.InvoiceDate FROM 6


FOR 2);-->empty
SET CurrentYear1 = SUBSTRING(InputRoot.XMLNSC.Invoice.InvoiceDate FROM 1
FOR 4);-->empty

SET MonthText1 = --> Not first three months of any year or a month in the
Year 2000 or 2001
CASE
WHEN CurrentMonth1 = '01' THEN 'January'
WHEN CurrentMonth1 = '02' THEN 'February'
WHEN CurrentMonth1 = '03' THEN 'March'
WHEN CurrentYear1 = '2000' THEN 'A month in the Year 2000'
WHEN CurrentYear1 = '2001' THEN 'A month in the Year 2001'
ELSE 'Not first three months of any year or a month in the Year 2000
or 2001'
END;

CAST function:
--Formatted CAST from DECIMAL to CHARACTER
DECLARE source DECIMAL 31415.92653589;
DECLARE target CHARACTER;
DECLARE pattern CHARACTER '#,##0.00';
SET target = CAST(source AS CHARACTER FORMAT pattern); -->31,415.93
-- target is now '31,415.93'

-- Formatted CAST from DATE to CHARACTER

DECLARE now CHARACTER;


SET now = CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT 'yyyyMMdd-HHmmss'); --
>20230405-185637/CHARACTER:20230405-191441/ontime1151am:20230406-114443
-- target is now '20041007-111656' (in this instance at least)

-- Formatted CAST from CHARACTER to DATE


DECLARE source3 CHARACTER '01-02-03';
DECLARE target3 DATE;
DECLARE pattern3 CHARACTER 'dd-MM-yy';
SET target3 = CAST(source3 AS DATE FORMAT pattern3);--
>DATE:java.util.GregorianCalendar[time=1044037800000,areFieldsSet=true,areA
llFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/
Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,last
Rule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=2003,MONTH=
1,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?
,DAY_OF_WEEK_IN_MONTH=?,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILL
ISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]2003-02-01/2003-02-01/2003-02-01
-- target now contains Year=2003, Month=02, Day=01

-- Formatted CAST from CHARACTER to TIMESTAMP


DECLARE source4 CHARACTER '12 Jan 03, 3:45pm';
DECLARE target4 TIMESTAMP;
DECLARE pattern4 CHARACTER 'dd MMM yy, h:mma';
SET target4 = CAST(source4 AS TIMESTAMP FORMAT pattern4);--
>TIMESTAMP:java.util.GregorianCalendar[time=1042366537926,areFieldsSet=true
,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asi
a/
Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,last
Rule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=2003,MONTH=
0,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=
?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=3,HOUR_OF_DAY=15,MINUTE=45,SECOND=37,
MILLISECOND=926,ZONE_OFFSET=?,DST_OFFSET=?]2003-01-12 15:45:37.926/2003-01-
12 15:45:41.865/ontime1154am:2003-01-12 15:45:43.715
-- target now contains Year=2003, Month=01, Day=03, Hour=15,
Minute=45,
--Seconds=58
-- (seconds taken from CURRENT_TIME since not present in input)

-- Formatted CAST from DECIMAL to CHARACTER, with negative pattern


DECLARE source5 DECIMAL -54231.122;
DECLARE target5 CHARACTER;
DECLARE pattern5 CHARACTER '#,##0.000;(#,##0.000)';
SET target5 = CAST(source5 AS CHARACTER FORMAT pattern5);-->#,##0.00;
(#,##0.00):CHARACTER:(54,231.12)/(54,231.12)/for-54231.122:(54,231.122)
-- target is now '£(54,231.12)'

-- Formatted CAST from CHARACTER to TIME


DECLARE source6 CHARACTER '11:10:30'; --> Exception for 16:18:30:Hour value
out of range (1-12)
DECLARE target6 TIME;
DECLARE pattern6 CHARACTER 'hh:mm:ss';
SET target6 = CAST(source6 AS TIME FORMAT pattern6);--
>TIME:java.util.GregorianCalendar[time=-
62167457490000,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=s
un.util.calendar.ZoneInfo[id="Asia/
Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,last
Rule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=0,YEAR=2,MONTH=11,
WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=31,DAY_OF_YEAR=?,DAY_OF_WEEK=?,
DAY_OF_WEEK_IN_MONTH=?,AM_PM=0,HOUR=11,HOUR_OF_DAY=11,MINUTE=18,SECOND=30,M
ILLISECOND=0,ZONE_OFFSET=?,DST_OFFSET=?]11:18:30.000/11:40:30.000
-- target now contains Hour=16, Minute=18, Seconds=30
SET op30 = target; --> returns CHARACTER:31,415.93
SET op31 = now; --> returns CHARACTER:20230406-114443
SET op32 = target3; --> returns CHARACTER:DATE '2003-02-01'
SET op33 = target4; --> returns CHARACTER:TIMESTAMP '2003-01-12
15:45:43.715707'
SET op34 = target5; --> returns CHARACTER:(54,231.122)
SET op35 = target6; --> returns TIME '11:10:30'

 Formatting and parsing numbers as strings


For conversions between string data types and numeric data types,
you can supply, on the FORMAT parameter of the CAST function, an
optional formatting expression.

Pattern Input number Output string


+###,##0.00;-
123456789.123“+123456789,12”
###,###,##0.00:groupsep='':decsep=,
##0.00 1000000 “1000000.00”
##0.00 3.14159265 “3.14”

 Formatting and parsing dateTimes as strings


This section gives information on how you can specify the dateTime
format using a string of pattern letters.

Logical model
ESQL data type Output form
data type
TIMESTAMP or
xsd:dateTime yyyy-MM-dd'T'HH:mm:ss.SSSZZZ
GMTTIMESTAMP
xsd:date DATE yyyy-MM-dd
xsd:gYear INTERVAL yyyy
xsd:gYearMont
INTERVAL yyyy-MM
h
xsd:gMonth INTERVAL --MM
Logical model
ESQL data type Output form
data type
xsd:gmonthDay INTERVAL --MM-dd
xsd:gDay INTERVAL ---dd
xsd:time TIME / GMTTIME 'T'HH:mm:ss.SSSZZZ

-- CASTs from the numeric types to DATE


SET op61 = CAST(7, 6, 5 AS DATE); --> returns CHARACTER:DATE '0007-06-05'
SET op36 = CAST(7.4e0, 6.5e0, 5.6e0 AS DATE); --> returns CHARACTER:DATE
'0007-07-06'
SET op37 = CAST(7.6, 6.51, 5.4 AS DATE); --> returns CHARACTER:DATE '0008-
07-05'

-- CASTs from the numeric types to TIME

SET op38 = CAST(9, 8, 7 AS TIME); --> returns CHARACTER:TIME '09:08:07'


SET op39 = CAST(9.4e0, 8.6e0, 7.1234567e0 AS TIME); --> returns
CHARACTER:TIME '09:09:07.123457'
SET op40 = CAST(9.6, 8.4, 7.7654321 AS TIME); --> returns CHARACTER:TIME
'10:08:07.765432'

-- CASTs to TIMESTAMP

SET op41 = CAST(DATE '0001-02-03', TIME '04:05:06' AS TIMESTAMP); -->


returns CHARACTER:TIMESTAMP '0001-02-03 04:05:06'
SET op42 = CAST(2, 3, 4, 5, 6, 7.8 AS TIMESTAMP); --> returns
CHARACTER:TIMESTAMP '0002-03-04 05:06:07.800'

-- CASTs to GMTTIMESTAMP

SET op43 = CAST(DATE '0002-03-04', GMTTIME '05:06:07' AS GMTTIMESTAMP); -->


returns CHARACTER:GMTTIMESTAMP '0002-03-04 05:06:07'
SET op44 = CAST(3, 4, 5, 6, 7, 8 AS GMTTIMESTAMP); --> returns
CHARACTER:GMTTIMESTAMP '0003-04-05 06:07:08'
SET op45 = CAST(3.1e0, 4.2e0, 5.3e0, 6.4e0, 7.5e0, 8.6789012e0 AS
GMTTIMESTAMP); --> returns CHARACTER:GMTTIMESTAMP '0003-04-05
06:08:08.678901'
SET op46 = CAST(3.2, 4.3, 5.4, 6.5, 7.6, 8.7890135 AS GMTTIMESTAMP); -->
returns CHARACTER:GMTTIMESTAMP '0003-04-05 06:08:08.789014'

--CASTs to INTERVAL from INTEGER

SET op47 = CAST(1234 AS INTERVAL YEAR); --> returns CHARACTER:INTERVAL


'1234' YEAR
SET op48 = CAST(32, 10 AS INTERVAL YEAR TO MONTH ); --> returns
CHARACTER:INTERVAL '32-10' YEAR TO MONTH
SET op49 = CAST(33, 11 AS INTERVAL DAY TO HOUR ); --> returns
CHARACTER:INTERVAL '33 11' DAY TO HOUR
SET op50 = CAST(34, 12 AS INTERVAL HOUR TO MINUTE); --> returns
CHARACTER:INTERVAL '34:12' HOUR TO MINUTE
SET op51 = CAST(35, 13 AS INTERVAL MINUTE TO SECOND); --> returns
CHARACTER:INTERVAL '35:13' MINUTE TO SECOND
SET op52 = CAST(36, 14, 10 AS INTERVAL DAY TO MINUTE); --> returns
CHARACTER:INTERVAL '36 14:10' DAY TO MINUTE
SET op53 = CAST(37, 15, 11 AS INTERVAL HOUR TO SECOND); --> returns
CHARACTER:INTERVAL '37:15:11' HOUR TO SECOND
-- SET op54 = CAST(38, 16, 12, 10 AS INTERVAL DAY TO SECOND); -->
returns op4:CHARACTER:

-- CASTs to INTERVAL from FLOAT

SET op55 = CAST(2345.67e0 AS INTERVAL YEAR ); --> returns


CHARACTER:INTERVAL '2346' YEAR
SET op56 = CAST(3456.78e1 AS INTERVAL MONTH ); --> returns
CHARACTER:INTERVAL '34568' MONTH
SET op57 = CAST(4567.89e2 AS INTERVAL DAY ); --> returns
CHARACTER:INTERVAL '456789' DAY
SET op58 = CAST(5678.90e3 AS INTERVAL HOUR ); --> returns
CHARACTER:INTERVAL '5678900' HOUR
SET op59 = CAST(6789.01e4 AS INTERVAL MINUTE);--> returns
CHARACTER:INTERVAL '67890100' MINUTE
SET op60 = CAST(7890.12e5 AS INTERVAL SECOND); --> returns
CHARACTER:INTERVAL '789012000' SECOND
SET op62 = CAST(7890.1234e0 AS INTERVAL SECOND); --> returns
CHARACTER:INTERVAL '7890.123400' SECOND

-- CASTs to INTERVAL from DECIMAL

SET op63 = CAST(2345.67 AS INTERVAL YEAR ); --> returns


CHARACTER:INTERVAL '2346' YEAR
SET op64 = CAST(34567.8 AS INTERVAL MONTH ); --> returns
CHARACTER:INTERVAL '34568' MONTH
SET op65 = CAST(456789 AS INTERVAL DAY ); --> returns
CHARACTER:INTERVAL '456789' DAY
SET op66 = CAST(5678900 AS INTERVAL HOUR ); --> returns
CHARACTER:INTERVAL '5678900' HOUR
SET op67 = CAST(67890100 AS INTERVAL MINUTE); --> returns
CHARACTER:INTERVAL '67890100' MINUTE
SET op68 = CAST(789012000 AS INTERVAL SECOND); --> returns
CHARACTER:INTERVAL '789012000' SECOND
SET op69 = CAST(7890.1234 AS INTERVAL SECOND);--> returns
CHARACTER:INTERVAL '7890.123400' SECOND

-- CASTs to FLOAT from INTERVAL

SET op70 = CAST(INTERVAL '1234' YEAR AS FLOAT); --> returns


CHARACTER:1.234E+3
SET op71 = CAST(INTERVAL '2345' MONTH AS FLOAT); --> returns
CHARACTER:2.345E+3
SET op72 = CAST(INTERVAL '3456' DAY AS FLOAT); --> returns
CHARACTER:3.456E+3
SET op73 = CAST(INTERVAL '4567' HOUR AS FLOAT); --> returns
CHARACTER:4.567E+3
SET op74 = CAST(INTERVAL '5678' MINUTE AS FLOAT); --> returns
CHARACTER:5.678E+3
SET op75 = CAST(INTERVAL '6789.01' SECOND AS FLOAT); --> returns
CHARACTER:6.78901E+3

-- CASTs DECIMAL from INTERVAL

SET op76 = CAST(INTERVAL '1234' YEAR AS DECIMAL); --> returns


CHARACTER:1234
SET op77 = CAST(INTERVAL '2345' MONTH AS DECIMAL); --> returns
CHARACTER:2345
SET op78 = CAST(INTERVAL '3456' DAY AS DECIMAL); --> returns
CHARACTER:3456
SET op79 = CAST(INTERVAL '4567' HOUR AS DECIMAL); --> returns
CHARACTER:4567
SET op80 = CAST(INTERVAL '5678' MINUTE AS DECIMAL); --> returns
CHARACTER:5678
SET op81 = CAST(INTERVAL '6789.01' SECOND AS DECIMAL); --> returns
CHARACTER:6789.01

-- A ternary cast that fails and results in the substitution of a default


value

SET op82 = CAST(7, 6, 32 AS DATE DEFAULT DATE '1947-10-24'); --> returns


CHARACTER:DATE '1947-10-24'

-- A sexternary cast that fails and results in the substitution of a


default value

SET op83 = CAST(2, 3, 4, 24, 6, 7.8 AS TIMESTAMP DEFAULT TIMESTAMP '1947-


10-24 07:08:09'); --> returns 2E+0

-- A ternary cast that fails and throws an exception


BEGIN
DECLARE EXIT HANDLER FOR SQLSTATE LIKE '%' BEGIN
SET OutputRoot.XMLNS.Data.Date.FromIntegersInvalidCast = 'Exception
thrown';
END;

DECLARE Dummy1 CHARACTER CAST(7, 6, 32 AS DATE);


SET op84 = Dummy1; --> returns Ex
END;

-- A sexternary cast that fails and throws an exception


BEGIN
DECLARE EXIT HANDLER FOR SQLSTATE LIKE '%' BEGIN
SET OutputRoot.XMLNS.Data.Timestamp.FromIntegersInvalidCast = 'Exception
thrown';
END;

DECLARE Dummy2 CHARACTER CAST(2, 3, 4, 24, 6, 7.8 AS TIMESTAMP);


SET op85 = Dummy2; --> 27.75
END;
-- Cast BLOB to INTEGER

-- Input BLOB must be 16 digits


DECLARE source1 BLOB X'0000000000000006'; -->BLOB:
[B@79f1fa21(0000000000000006)
DECLARE target1 INT;
SET target1 = CAST(source1 AS INT); --> returns INTEGER:6
-- target is now base 10 integer 6

SET source1 = X'00000000000012C4'; -->BLOB:[B@7697825c(00000000000012c4)


SET target1 = CAST(source1 AS INT); -->INTEGER:4804
-- target is now base 10 integer 4804
SET op86 = target1; --> CHARACTER:4804

-- Cast INTEGER to BLOB

DECLARE source2 INT 6; -->INTEGER:6


DECLARE target2 BLOB;
SET target2 = CAST(source2 AS BLOB); -->BLOB:[B@ed287b45(0000000000000006)
-- target is now x'0000000000000006'

SET source2 = 4804; -->INTEGER:4804


SET target2 = CAST(source2 AS BLOB); -->BLOB:[B@45cfbc2b/ BLOB:
[B@b69f155f(00000000000012c4)
-- target is now x'00000000000012C4'
SET op87 = target2; --> returns CHARACTER:X'00000000000012c4'

SELECT function: The SELECT function combines, filters, and transforms


complex message and database data.
1. For the COUNT parameter only, you can specify the value of
the following Expression as a single star (*).
 Simple selections
 INSERT selections
 ITEM selections
 Column function selections

ROW constructor function: ROW constructor is a complex function used


to explicitly generate rows of values that can be assigned to fields in an
output message.
(input request field names changing)
Example1:
SET OutputRoot.XMLNS.Data = ROW('granary' AS bread,
'riesling' AS wine,
'stilton' AS cheese);

Output:
<Data>
<bread>granary</bread>
<wine>riesling</wine>
<cheese>stilton</cheese>
</Data>
Example2:
Input:
<Proof>
<beer>5</beer>
<wine>12</wine>
<gin>40</gin>
</Proof>
Code:
SET OutputRoot.XMLNS.Data = ROW(InputBody.Proof.beer,
InputBody.Proof.wine AS vin,
(InputBody.Proof.gin * 2)
AS special);
Output:
<Data>
<beer>5</beer>
<vin>12</vin>
<special>80</special>
</Data>

LIST constructor function: The LIST constructor complex function is


used to explicitly generate lists of values that can be assigned to fields in
an output message.
Example1:
Input:
<Car>
<size>big</size>
<color>red</color>
</Car>

SET OutputRoot.XMLNS.Data.Result[] = LIST{InputBody.Car.color,


'green',
'blue'};
Output:
<Data>
<Result>red</Result>
<Result>green</Result>
<Result>blue</Result>
</Data>

Example1:
Input:
<Data>
<Field>Keats</Field>
<Field>Shelley</Field>
<Field>Wordsworth</Field>
<Field>Tennyson</Field>
<Field>Byron</Field>
</Data>

-- Copy the entire input message to the output message,


-- including the XML message field array as above
SET OutputRoot = InputRoot;
SET OutputRoot.XMLNS.Data.Field[] = LIST{'Henri','McGough','Patten'};

Output:
<Data>
<Field>Henri</Field>
<Field>McGough</Field>
<Field>Patten</Field>
</Data>

ROW and LIST combined: ROW and LIST combined form a complex
function.
SET OutputRoot.XMLNS.Data.Country[] =
LIST{ROW('UK' AS name,'pound' AS currency),
ROW('US' AS name, 'dollar' AS currency),
'default'};
Output:
<Data>
<Country>
<name>UK</name>
<currency>pound</currency>
</Country>
<Country>
<name>US</name>
<currency>dollar</currency>
</Country>
<Country>default</Country>
</Data>

ROW and LIST comparisons: You can compare ROWs and LISTs
against other ROWs and LISTs(In the comparison between ROWs, both
the name and the value of each element are compared; in the comparison
between LISTs only the value of each element is compared.)
Example1:
Input:
<Data>
<Name>Raf</Name>
<Age>25</Age>
</Data>

IF ROW(InputBody.Data.*[1],InputBody.Data.*[2]) =
ROW('Raf' AS Name,'25' AS Age) THEN ...
IF LIST{InputBody.Data.Name, InputBody.Data.Age} = LIST{'Raf','25'} THEN
...

both the IF expressions in both the above statements evaluate to TRUE


Example2:
Input:
<Places>
<first>Ken</first>
<second>Bob</second>
<third>Kate</third>
</Places>

IF InputBody.Places =
ROW('Ken' AS first, 'Bob' AS second, 'Kate' AS third) THEN ...

the above IF expression evaluates to TRUE

Example3:
Input:
<Cities>
<City>Athens</City>
<City>Sparta</City>
<City>Thebes</City>
</Cities>

IF InputBody.Cities.City[] = LIST{'Athens','Sparta','Thebes'} THEN ...

IF expression evaluates to TRUE


Example4:
Input:
<Cities>
<Mediaeval>1350
<City>London</City>
<City>Paris</City>
</Mediaeval>
<Modern>1990
<City>London</City>
<City>Paris</City>
</Modern>
</Cities>

IF InputBody.Cities.Mediaeval.City[] =
InputBody.Cities.Modern.City[] THEN ...

IF InputBody.Cities.Mediaeval.*[] = InputBody.Cities.Modern.*[] THEN ...

IF InputBody.Cities.Mediaeval.(XML.Element)[] =
InputBody.Cities.Modern.(XML.Element)[] THEN ...

the IF expression of the first and third of the statements above evaluates to
TRUE

Miscellaneous Functions :
COALESCE Function :
As we know,it is used to provide default values.It returns the first not null
value.
SET OutputRoot.XMLNSC.COALESCE =
COALESCE(InputRoot.XMLNSC.input1,0);

SET OutputRoot.XMLNSC.COALESCE1 =
COALESCE(InputRoot.XMLNSC.input12,0);
<input1>12</input1>
SET OutputRoot.XMLNSC.employee.(XMLNSC.Attribute)id =’123′;
UUIDASCHAR,UUIDASBLOB——SET OutputRoot.XMLNSC.emp =
UUIDASCHAR;

EVAL function:
The EVAL function takes a character value and interprets that value as an
ESQL expression that returns a value.
Syntax:
SET OutputRoot.XMLNS.Data.Result = EVAL(A+B);

SLEEP function : delays the execution of a message flow instance for a


defined period of time, and returns a Boolean value to indicate whether the
sleep completed without interruption
Syntax: DECLARE returnValue BOOLEAN;
SET returnValue = SLEEP(1000); /* attempt to sleep for one second */
NULLIF function: is a miscellaneous function that returns a NULL value if
the arguments are equal.
Syntax: CASE WHEN e1=e2 THEN NULL ELSE e1 END

BASE64DECODE : is a function that manipulates CHARACTER strings


that are base64-encoded, and returns a BLOB string that contains the
base64-decoded version of the source string.
Syntax: CASE WHEN e1=e2 THEN NULL ELSE e1 END

PASSTHRU Function: evaluates an expression and executes the resulting


character string as a database statement, returning resultset

Ex:- SET OutputRoot.XML.Data.SelectResult.Row[] =


PASSTHRU(‘SELECT R.* FROM
Schema1.Table1 AS R WHERE R.Name = ? OR R.Name = ? ORDER BY
Name’
TO Database.DSN1 VALUES (‘Name1’, ‘Name4’));

PASSTHRU Statement: evaluates an expression and runs the resulting


character string as a database statement

Ex:- PASSTHRU ‘CREATE TABLE Shop.Customers ( CustomerNumber


INTEGER,
FirstName VARCHAR(256,……)

You might also like