APP Connect Functions
APP Connect Functions
APP Connect Functions
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
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
Result: Address%3DHampshire%2CUnited%20Kingdom
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:
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'
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
FIELDNAME function
SET X=FIELDNAME(InputBody.*[<]); -->BLOB/CHARACTER:Data
SET Y=FIELDNAME(InputBody.F1.*[<]);-->empty
SET Z=FIELDNAME(InputBody.*[<].*[<]);
-->empty/CHARACTER:Purchases/CHARACTER:Invoice
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>
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.
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[];
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[];
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;
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'
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 to TIMESTAMP
-- CASTs to GMTTIMESTAMP
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>
Example1:
Input:
<Data>
<Field>Keats</Field>
<Field>Shelley</Field>
<Field>Wordsworth</Field>
<Field>Tennyson</Field>
<Field>Byron</Field>
</Data>
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
...
IF InputBody.Places =
ROW('Ken' AS first, 'Bob' AS second, 'Kate' AS third) THEN ...
Example3:
Input:
<Cities>
<City>Athens</City>
<City>Sparta</City>
<City>Thebes</City>
</Cities>
IF InputBody.Cities.Mediaeval.City[] =
InputBody.Cities.Modern.City[] 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);