Skip to content

Instantly share code, notes, and snippets.

@RainerRoss
Last active March 20, 2022 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RainerRoss/0c614c81eb5bde9ed849fae5b7352408 to your computer and use it in GitHub Desktop.
Save RainerRoss/0c614c81eb5bde9ed849fae5b7352408 to your computer and use it in GitHub Desktop.
SELECT my_cube.rate_time, my_cube.currency, my_cube.rate
FROM
XMLTABLE(
-------------- Declare Namespaces ----------------------
XMLNAMESPACES(
DEFAULT 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref',
'http://www.gesmes.org/xml/2002-08-01' AS "gesmes"
),
-------------- Row Expression --------------------------
'gesmes:Envelope/Cube/Cube/Cube'
PASSING
------------ Initial Context ------------------------
XMLPARSE(DOCUMENT
SYSTOOLS.HTTPGETCLOB(
----------------- URL ------------------------
'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml',
---------------- Header ---------------------
''
)
)
-------------- Result Set Columns -------------
COLUMNS
currency CHAR(3) PATH '@currency',
rate DECIMAL(10,4) PATH '@rate',
rate_time DATE PATH '../@time'
) my_cube
WHERE currency in ('USD','DKK','GBP')
ORDER BY rate_time DESC;
ctl-opt dftactgrp(*no) option(*nodebugio:*nounref);
//------------------------------------------------------------------//
// //
// Get ECB-Currency Rates //
// //
//----------------- //
// R.Ross 06.2017 * //
//------------------------------------------------------------------//
// Files //
//------------------------------------------------------------------//
dcl-f curratp disk keyed usage(*update:*output);
//------------------------------------------------------------------//
// Array SQL-Result //
//------------------------------------------------------------------//
dcl-ds DsResult qualified;
cur like(crcur); // Currency
date like(crdate); // Currency-Date
rate like(crrate); // Currency-Rate
end-ds;
//------------------------------------------------------------------//
// Process //
//------------------------------------------------------------------//
main();
*inlr = *on;
//------------------------------------------------------------------//
// Main //
//------------------------------------------------------------------//
dcl-proc Main;
dcl-s LocUrl varchar(256); // URL
exec sql set option datfmt=*iso, timfmt=*iso, commit=*none,
closqlcsr=*endactgrp;
LocUrl =
'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml';
exec sql declare cursor01 cursor for // Declare Cursor
SELECT my_cube.currency, my_cube.rate_time, my_cube.rate
FROM
XMLTABLE(
XMLNAMESPACES(
DEFAULT 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref',
'http://www.gesmes.org/xml/2002-08-01' AS "gesmes"
),
'gesmes:Envelope/Cube/Cube/Cube'
PASSING
XMLPARSE(DOCUMENT
SYSTOOLS.HTTPGETCLOB(:LocUrl,'')
)
COLUMNS
currency CHAR(3) PATH '@currency',
rate DECIMAL(10, 4) PATH '@rate',
rate_time DATE PATH '../@time'
) my_cube
ORDER BY rate_time DESC;
exec sql open cursor01; // Open Cursor
dou sqlcode < *zero or sqlcode = 100;
exec sql fetch cursor01 into :dsresult;
if sqlcode >= *zero and sqlcode <> 100;
wrtCurrat(DsResult); // Write CURRATP
endif;
enddo;
exec sql close cursor01; // Close Cursor
end-proc;
//------------------------------------------------------------------//
// Write Curency-Rates in CURRATP //
//------------------------------------------------------------------//
dcl-proc wrtCurrat;
dcl-pi *n;
##Result likeds(DsResult) const;
end-pi;
crcur = ##Result.Cur;
crdate = ##Result.Date;
chain (crcur:crdate) curratf;
crrate = ##Result.Rate;
if %found(curratp);
update curratf;
else;
write curratf;
endif;
end-proc;
//------------------------------------------------------------------//
// https://snippet.webix.com/8hlqi8w5
var text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
function parseXML(){
var parser, xmlDoc;
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"application/xml");
var title = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
var author = xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue;
var year = xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue;
webix.message("title: " + title);
webix.message("author: " + author);
webix.message("year: " + year);
$$("title").setValue(title);
$$("author").setValue(author);
}
webix.ui({
view:"form", elements:[
{ view:"text", label:"Name", id:"name", name:"name"},
{ view:"text", label:"Ort", id:"ort", name:"ort"},
{ view:"text", label:"Titel", id:"title", name:"title"},
{ view:"text", label:"Author", id:"author", name:"author"},
{ margin:20, cols:[
{},
{ view:"button", value:"Cancel", width:200},
{ view:"button", type:"form", value:"Book Now", width:200, align:"right", click:function(){
var values = this.getFormView().getValues();
$$("name").setValue("Elmar");
$$("ort").setValue("München");
parseXML();
webix.message(JSON.stringify(values));
}}
]}
]
});
http://phpfiddle.org/main/code/fsmj-czxz
-- Webservice JSON GET-Request
values SYSTOOLS.HTTPGETCLOB('http://www.myhofi.com/myapp/websrv01.pgm?id=1','');
-- Webservice JSON POST-Request
values SYSTOOLS.HTTPPOSTCLOB(
'http://www.myhofi.com/myapp/websrv01.pgm',
'<httpHeader>
<header name="Content-Type" value="application/x-www-form-urlencoded"/>
</httpHeader>',
'id=1'
);
-- Wetter Landsberg für 3 Tage
values SYSTOOLS.HTTPGETCLOB (
'https://user:password@twcservice.eu-gb.mybluemix.net/api/weather/v1/geocode/48.050783/10.870351/forecast/daily/3day.json?language=de-DE&units=m',
'<httpHeader>
<header name="Content-Type" value="application/json; charset=utf-8"/>
</httpHeader>'
);
Select x.*
from JSON_TABLE(
SYSTOOLS.HTTPGETCLOB('https://user:password@twcservice.eu-gb.mybluemix.net/api/weather/v1/geocode/48.050783/10.870351/forecast/daily/3day.json?language=de-DE&units=m',''),
'$'
Columns(
nested '$.forecasts[*]' columns(
"Datum&Zeit" varchar(30) path 'lax $.fcst_valid_local',
"Min_Temp" integer path 'lax $.min_temp',
"Max_Temp" integer path 'lax $.max_temp',
"Text" varchar(256) path 'lax $.narrative'
)
)
) x;
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var parser, xmlDoc;
var text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"application/xml");
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
var title = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
var author = xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue;
var year = xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue;
console.log("title: " + title);
console.log("author: " + author);
console.log("year: " + year);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment