
This will receive the results from the SQL statement I will use to create the XML output. In this example we have three different types: I can hear you all say: "What are all the LOBs I can use?” Rather than describe them all in this post I will write about them in a future post. At compile time the SQL precompiler replaces these declarations with their RPG equivalents. Lines 2 – 4: RPG does not have equivalent variables to SQL's Large Objects, LOBs, therefore, the SQLTYPE keyword was added to the variable definition. Line 1: For those of you who have read this blog before should now be familiar with the **FREE, as all of my examples are in totally free RPG. Let me start with defining the variables:Ġ2 dcl-s XmlData sqltype(xml_clob:3000) ccsid(37) Ġ4 dcl-s Data sqltype(clob:1000000) ccsid(*utf8) Ġ6 dcl-s Path varchar(100) inz('/MyFolder/xmlfile.xml') Ġ7 dcl-s ThisCustomer char(10) inz('9877A') I will give the entire program at the bottom of this post. There is a lot of cool interesting stuff in this program, so I am going to break it up into parts to make it easier for me to explain the code and I hope for you to understand. Now I have explained that I can start with the program. Lines 4 and 5, 8 and 9: The children contain the "data”. Each parent has starting tags, lines 3 and 7, and matching ending tags, 6 and 10. Lines 3 – 6 and 7 – 10: There are two parent elements within this file.

Usually there is just one root element per file. Line 2: root is the root element, and it has its matching end on line 11.

It gives the version of the XML standard that is being used, and the character set. Line 1: Every well formed XML document starts with one of these elements. I will post a link to her Github at the bottom of this post along with the other reference links.īefore I continue I want to describe the parts of a XML document so you understand when I call an element something what it is. Some of the code in this example is based upon a series of example procedures and programs she posted on Github. She is someone whose work I study, and articles I always read.

After a good deal of research I have an example program of 28 lines, which takes data from a DDS file or DDL table, converts the data to XML, and outputs the data to a file in the IFS. I wanted to keep my program simple, K.I.S.S. This left me thinking how do I create a XML file just using native IBM i functionality? In an earlier post I described how to retrieve information from a XML file.
