|
Jon, Vern,and
It's only the way you are used to do it.
The SQL syntax is really powerful.
Using CTEs allow you to the complex structure into sub-structures. Those
sub-structures can be tested and put together.
You start with the lowest level, build the XML string add join fields
test the result. Build the next level join with the lower level, test itglobal
again etc.
And at the end the complete XML document is created.
In RPG I'd use the same practice. Writing sub-procedures, testing those
sub-procedures, calling the sub-procedures from other procedures etc.
In real live I create and use SQL views may be in composition with
variables and reduce my RPG or whatever (embedded SQL) Code to aminimum:
Exec SQL Set GblVaStart = :HostStartDate;RPG/Cobol
Exec SQL Set GblVarIncoTerms = :HostIncoTerms;
... set other Global Variables
Exec SELECT XMLDoc into :IFSFile From SQLView;
BTW in my classes I have them both, those guys who prefer the pure
(in composition with CGIDEV2) solution and others who prefer the pureSQL
version.(Les
Mit freundlichen Gr??en / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars."
Brown)them
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training
and keeping them!"Vernon
-----Urspr?ngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von
HambergSQL
Gesendet: Wednesday, 20.8 2014 21:22
An: RPG programming on the IBM i (AS/400 and iSeries)
Betreff: Re: Writing XML with RPGLE V7R1M0
Jon
I had a similar response when I first tried to write some XML here - the
approach was ghastly as to syntax, and CGIDEV2 was devilishly trivial.think
I just don't have the time to dig so deeply into the SQL syntax - i
it's tremendously powerful - but this is one area I don't really want touse
a "black-box" approach - I want to see better what I'm doing.build
Maintainability and speed are key for me.
Cheers
Vern
On 8/20/2014 11:48 AM, Jon Paris wrote:
Thanks for that - I think it has convinced me that I don't want to
XML this way <grin> but I will study it further.CustNo="xx"><Name></Name><Street></Street><ZipCode></ZipCode><City></City>
SQL's ghastly syntax.
I'd probably get on better if I could get past my thorough dislike for
wrote:
On 2014-08-20, at 11:54 AM, Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx>
tables:
Jon,
I only used this simple SQL statement because I wanted to show how to
write into the IFS with embedded SQL.
But iIf you want to have a more complex SQL statement that generates
an XML document that is written with a single SQL-Statement into the
IFS here is a more complex one:
Joining Address Master, Order Header, Order Detail and Item master
With -- 1. Address information:
-- <Customer
'DO'"CustNo"),-- </Customer>
Address as (Select CustNo, XMLElement(Name "Customer",
XMLAttributes(Trim(CustNo) as
XMLConcat(XMLElement(Name "Name",
Trim(Trim(CustName1) concat ' ' concat Trim(CustName2))),
XMLForest(Trim(Street)
as "Street",
Trim(ZipCode)
as "ZipCode",
Trim(City) as
"City"))) CustXML
From Addressx),
-- 2. Order Header Information:
-- <Mandant></Mandant><OrderNo></OrderNo>
--
<DeliveryDate><DeliveryDate><OrderType></OrderType><DeliveryTerms></D
elivery
Terms>
Header as (Select Company, OrderNo, CustNo,
XMLForest(Company as "Mandant",
OrderNo as "OrderNo") OrderNoXML,
XMLConcat(XMLElement(Name "DeliveryDate",
Char(DelDate, ISO)),
XMLElement(Name "OrderType",
Case When OrderType =
'EX'Then 'Domestic'
When OrderType =
'UO'Then 'Export'
When OrderType =
'CPT'Then 'Express'
else '???' End),
XMLElement(Name "DeliveryTerms",
Case When DelTerms =
'EXW'Then 'Delivered Free'
When DelTerms =
2)Then 'Ex Works'
Else '???' End))
HdrAddXML
From OrderHdrX
Where DelDate between '2009-12-01' and
'2009-12-31'),
-- 3. Joining Order Header and Address Information (CTE No. 1 and
"DeliveryValue",ItemNo=""><ItemDescription><ItemDescription><PricePerUnitHdrAddr as (Select Company, OrderNo, XMLConcat(OrderNoXML,
CustXML,
HdrAddXML) OrderXML
from Header Join Address Using(CustNo)),
-- 4. Item Information
-- <Item
Currency=""></PricePerUnig>
-- </Item>
Item as (Select i.*,
XMLElement(Name "Item" ,
XMLAttributes(Trim(ItemNo) as "ItemNo"),
XMLConcat(XMLElement(Name
"ItemDescription", Trim(Descript)),
XMLElement(Name "PricePerUnit",
XMLAttributes('EUR' as "Currency"),
Price))) ItemXML
from ItemMastX i),
-- 5. Order Detail Information
-- <Position PosNo=""><Item Information from CTE No. 4=Item>
--
<DeliveryQuantity></DeliveryQuantity><DeliveryValue
Currency""></DeliveryValue>
-- </Position>
Position as (Select Company, OrderNo,
XMLElement(Name "Position",
XMLAttributes(OrderPos as "PosNo"),
XMLConcat(ItemXML,
XMLElement(Name
"DeliveryQuantity", DelQty),
XMLElement(Name
21</Street>
XMLAttributes('EUR' as "Currency"),
DelQty *
Price))) PosXML
From OrderDetX join Item using (Company, ItemNo)
Where DelQty > 0),
-- 6. Concatenating Order Details per Order
-- <Positions><Order Position Information - CTE No. 5>
-- </Positions>
AllPos as (Select Company, OrderNo,
XMLElement(Name "Positions",
XMLAGG(PosXML)) PosOrderNoXML
from Position
Group By Company, OrderNo),
-- 7. Joining Order Header / Address / Order Position and Item
information
-- <Order><OrderHeader and Address information - CTE No. 3>
-- <Order Positions and Item information - CTE No. 5>
-- </Order>
Order as (Select XMLElement(Name "Order",
XMLConcat(OrderXML,
PosOrderNoXML)) OrdersXML
from HdrAddr join AllPos using (Company,
OrderNo))
-- Final Select Statement
-- Concatenating Order Informationen No. 7 and generating an XML
Document
Select xmldocument(xmlElement(Name "Orders", XMLAGG(OrdersXML)))
From Order;
An here is the Result (I only copied the first Order)
<Orders>
<Order>
<Mandant>10</Mandant>
<OrderNo>BNR2009-12-15/1</OrderNo>
<Customer CustNo="10003">
<Name>Goldbach GmbH
***********Sonder-Aktion******</Name>
<Street>Hanauerstr.
Free</DeliveryTerms><ZipCode>63755</ZipCode>
<City>Alzenau</City>
</Customer>
<DeliveryDate>2009-12-01</DeliveryDate>
<OrderType>Domestic</OrderType>
<DeliveryTerms>Delivered
ItemNo="CF001"><Positions>
<Position PosNo="1">
<Item
ItemNo="CF003">1</ItemDescription><ItemDescription>Champagne flute
<PricePerUnit
Currency="EUR">,60</PricePerUnit>
</Item>
<DeliveryQuantity>20</DeliveryQuantity>
<DeliveryValue
Currency="EUR">12,00</DeliveryValue>
</Position>
<Position PosNo="2">
<Item
ItemNo="BS002">3</ItemDescription><ItemDescription>Champagne flute
<PricePerUnit
Currency="EUR">1,45</PricePerUnit>
</Item>
<DeliveryQuantity>24</DeliveryQuantity>
<DeliveryValue
Currency="EUR">34,80</DeliveryValue>
</Position>
<Position PosNo="4">
<Item
existswrote:<ItemDescription>Book shelves
2</ItemDescription>
<PricePerUnit
Currency="EUR">66,15</PricePerUnit>
</Item>
<DeliveryQuantity>40</DeliveryQuantity>
<DeliveryValue
Currency="EUR">2646,00</DeliveryValue>
</Position>
</Positions>
</Order>
Mit freundlichen Gr??en / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars."
(Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training
them and keeping them!"
-----Urspr?ngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von
Jon Paris
Gesendet: Wednesday, 20.8 2014 17:22
An: RPG programming on the IBM i (AS/400 and iSeries)
Betreff: Re: Writing XML with RPGLE V7R1M0
Your example does seem to work well Birgitta - but even the simplest
of XML documents usually requires a bit more "shape". The script as
given (modified a bit to fit a DB I had to hand) produces this:
<Customers>
<Customer>
<ID>A0011</ID>
<PersName>Acme Best Brew </PersName>
<ZipCode>0</ZipCode>
<Zip-Plus>0</Zip-Plus>
<City>Acme </City>
</Customer>
... repeat Customer element
But what I wanted was:
<Customers>
<Customer>
<ID>A0011</ID>
<PersName>Acme Best Brew </PersName>
<Address> <<<< New compound element
<ZipCode>55901</ZipCode>
<Zip-Plus></Zip-Plus>
<City>Acme </City>
</Address>
</Customer>
And I have looked throughout the IBM and other examples and have not
been able to see how this is done. In all the other approaches
described in this thread providing this "shape" is trivial. I'd love
to know how the SQL approach handles it.
Also Zip-Plus is commonly an optional element and should not be
present when empty - how do I achieve that?
On 2014-08-20, at 12:57 AM, Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx>
CloSQLCsr=*EndActGrp;
Hi Brian,
You may check the following article:
Using RPG to exploit IBM DB2 XML support
http://www.ibm.com/developerworks/ibmi/library/i-using-rpg/index.htm
l
Using embedded SQL or better Reference Files is an even easier way
for writing the result to the IFS. (The most complex part is
building the SQL statement for generating the XML document.
The following souce code is a complete program for generating an XML
document and writing this document directly to the IFS:
D MyXMLDoc S SQLTYPE(XML_CLOB_File)
D
//******************************************************************
**
***
/Free
Exec SQL Set Option Commit=*None, DatFmt=*ISO,
Clear MyXMLDoc;
MyXMLDoc_Name = '/home/Hauser/WrtSQLXML.xml';
MyXMLDoc_NL = %Len(%Trim(MyXMLDoc_Name));
MyXMLDoc_FO = SQFOVR; //Replace if
http://archive.midrange.com/rpg400-l.IFS.
Exec SQL
Select XmlDocument
(xmlgroup(EmployeeNo as "PersNo",
Trim(Trim (FirstName) concat ' ' concat
Trim(Name)) as "PersName",
Address as "Street",
ZipCode as "ZipCode",
City as "City"
Order By City Desc, Name
Option Row "Employee"
Root "Staff"))
into :MyXMLDoc
From LobStaff;
If SQLCODE < *Zeros;
Dsply 'Error occured';
else;
Dsply 'XML Document generated';
EndIf;
*InLR = *On;
/End-Free
Mit freundlichen Gr??en / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars."
(Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not
training them and keeping them!"
-----Urspr?ngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von
Brian Stapleton
Gesendet: Tuesday, 19.8 2014 21:56
An: rpg400-l@xxxxxxxxxxxx
Betreff: Writing XML with RPGLE V7R1M0
Good Afternoon
I need to learn how to write XML documents with RPGLE V7R1M0 onto our
destroy the original message and all copies.
How can I educate myself on doing this?
I would prefer to stay as native RPGLE as possible, and am not
looking to purchase a 3rd party solution.
Brian Stapleton
Information Services
Carhartt, Inc
5750 Mercury Drive
Dearborn, MI 48126
Desk - 313-749-6586
Fax - 313-271-3455
BStapleton@xxxxxxxxxxxx<mailto:BStapleton@xxxxxxxxxxxx>
[Description: Description: Carhartt_emaillogo]
Confidential: This electronic message and all contents contain
information from Carhartt, Inc. and its affiliates which may be
confidential or otherwise protected from disclosure. The information
is intended to be for the addressee only. If you are not the
addressee, any disclosure, copy, distribution or use of the contents
of this message is prohibited. If you have received this electronic
message in error, please notify us immediately at (313) 271-8460 and
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at
http://archive.midrange.com/rpg400-l.
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at
subscribe,Jon ParisJon Paris
www.partner400.com
www.SystemiDeveloper.com
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at
http://archive.midrange.com/rpg400-l.
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at
http://archive.midrange.com/rpg400-l.
www.partner400.com
www.SystemiDeveloper.com
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To
unsubscribe, or change list options,mailing list
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Brian,<Hauser@xxxxxxxxxxxxxxx>
As mentioned CGIDEV2 our our eRPG SDK could be used for this.
They are template based applications that are able not only to output
dynamic content to the web, but stream files in the IFS.
Normally used for dynamic HTML, they can be used to generate dynamic
"anything" (XML, JSON, JavaScript... anything!)
Brad
www.bvstools.com
On Thu, Aug 21, 2014 at 7:46 AM, Birgitta Hauser
wrote:within
With CGIDEV2 it is as easy as populating and writing printer files.
SQL has all kinds of publishing functions, that can be easily used
(LesRPG
And embedded SQL even has a very easy way to directly write to the IFS.
So Why to reinvent the wheel and adding additional opcodes?
Mit freundlichen Gr??en / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars."
themBrown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training
Brianand keeping them!"
-----Urspr?ngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von
differentStapleton
Gesendet: Thursday, 21.8 2014 14:32
An: RPG400-L@xxxxxxxxxxxx
Betreff: Writing XML from RPGLE
Good Morning Guru's and Masters of RPGLE
Thank you to all who replied to my earlier email about writing XML from
within RPGLE. I will go back into the digest and read up on the
theapproaches.
The XML files that I will be generating are fairly nested, and are for
notpurpose of transferring data to another system. (Non AS/400 - Yeah,
similarhappy about that myself) and I will be pulling the data from several
different files.
I was hoping that the latest release of RPGLE would have Op codes
such ato
XML-Into / XML-SAX that write XML code to the IFS, and it looks like
informationthing doesn't exist.
Thank you to all who responded for your help.
Brian Stapleton
Information Services
Carhartt, Inc
5750 Mercury Drive
Dearborn, MI 48126
Desk - 313-749-6586
Fax - 313-271-3455
BStapleton@xxxxxxxxxxxx<mailto:BStapleton@xxxxxxxxxxxx>
[Description: Description: Carhartt_emaillogo]
Confidential: This electronic message and all contents contain
forfrom Carhartt, Inc. and its affiliates which may be confidential or
otherwise protected from disclosure. The information is intended to be
youthe addressee only. If you are not the addressee, any disclosure, copy,
distribution or use of the contents of this message is prohibited. If
(RPG400-L)have received this electronic message in error, please notify us
immediately
at (313) 271-8460 and destroy the original message and all copies.
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
subscribe,mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To
(RPG400-L)unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.