Producing XML Output with CA Easytrieve - Part 1

Document ID : KB000055734
Last Modified Date : 14/02/2018
Show Technical Document Details

By adding the XML parameter to an existing REPORT statement within release 11, you can quickly generate an XML output file. For example, the following code takes the standard personnel file that is distributed with the product and generates XML for the first record in that file. This CA Easytrieve job was written and executed with the Windows version. By removing the SYSNAME parameter (a file identifier statement) and wrapping JCL around it, it can run on the mainframe just as easily.


This program results in an XML file (with the name of TEST.XML) that looks like this:

<RPT_REPORT><RPT>                             <REGION>1</REGION>                <BRANCH>01</BRANCH>               <LAST_NAME>WIMN    </LAST_NAME>   <FIRST_NAME>GLORIA  </FIRST_NAME> <DEPT>903</DEPT>                  <GROSS_PAY>   373.60 </GROSS_PAY> </RPT>                            </RPT_REPORT>

As the purpose of this article is not to teach XML, the use of style sheets, or HTML, we'll just point out a couple of items within the generated file. First, the beginning tag (<RPT_REPORT>) and its closing tag (</RPT_REPORT>) are automatically generated based upon the name of the report, in this case RPT. Secondly, each line of what would appear in a normal Advantage CA-Easytrieve report is enclosed within the <RPT> and </RPT> tags and each field on the LINE statement appears as an attribute within those tags. This becomes important when building a style sheet to display the data within your Web Page.

Before making the generated XML anymore complex, we should probably cover the rest of the pieces that are needed to take the XML data into the Web environment. The next piece to explore is a style sheet to display the XML data. This is accomplished by using the Extensible Stylesheet Language, XSL. Using very limited XSL functionality, the following code displays those people who are in REGION='1'. Note that this example was designed and tested on Microsoft's Internet Explorer 6.0. As all Browsers are not identical,using this within Netscape, Mozilla or Opera may produce different results.

<?xml version="1.0"?><xsl:stylesheet     xmlns:xsl=""    version="1.0">    <xsl:output method="xml" encoding="WINDOWS-1252"/>    <xsl:template match="/">        <table ALIGN="center" WIDTH="80%">        <tr>            <th></th>            <th bgcolor="bisque"><font size="2">Region</font></th>            <th bgcolor="bisque"><font size="2">Branch</font></th>            <th bgcolor="bisque"><font size="2">Last Name</font></th>            <th bgcolor="bisque"><font size="2">First Name</font></th>            <th bgcolor="bisque"><font size="2">DEPT</font></th>            <th bgcolor="bisque"><font size="2">Salary</font></th>        </tr>        <TR>            <xsl:for-each select="RPT_REPORT/RPT">                <xsl:sort select="REGION" data-type="text" order="ascending"/>                <xsl:sort select="BRANCH" data-type="text" order="ascending"/>                <TR>                <xsl:choose>                    <xsl:when test='./REGION="1"'>                         <TH></TH>                         <td bgcolor="beige" ALIGN="center"><font size="2">                          <xsl:value-of select="REGION"/></font></td>                         <td bgcolor="beige" ALIGN="center"><font size="2">                          <xsl:value-of select="BRANCH"/></font></td>                         <td bgcolor="beige" ALIGN="center"><font size="2">                          <xsl:value-of select="LAST_NAME"/></font></td>                         <td bgcolor="beige" ALIGN="center"><font size="2">                          <xsl:value-of select="FIRST_NAME"/></font></td>                         <td bgcolor="beige" ALIGN="center"><font size="2">                          <xsl:value-of select="DEPT"/></font></td>                         <td bgcolor="beige" ALIGN="center"><font size="2">                          <xsl:value-of select="GROSS_PAY"/></font></td>                    </xsl:when>            </xsl:choose>            </TR>        </xsl:for-each>        </TR>        </table>    </xsl:template></xsl:stylesheet>

If you have looked at HTML source before, a large portion of this stylesheet may look familiar to you as it is simply a combination of HTML and XSL statements. In this case, we are simply creating a table to display the data from the XML file. (The beauty of this approach is that the style sheet is not tied to the data itself, only the columns presented and in this case, only selecting REGION='1'.) All you need to do is run your Advantage CA-Easytrieve job to generate the XML file and make it accessible to your Web application.

The final piece that needs to be considered is how the XML and XSL files come together. There are a number of different approaches to that but we'll cover two simple ones. The easier of the two is to modify your JOB statement in your Advantage CA-Easytrieve program with a START Procedure which includes a pointer to the XSL file similar to the following:

JOB INPUT PERSNL START SPROC        PRINT RPTSPROC. PROC    DISPLAY XMLRPT '<?xml-stylesheet type="text/xsl"' +      'href="EZTPersnl.xsl"?>'END-PROC

Remember, the START parameter on the JOB statement causes that procedure to be performed once and performs it before any other processing within the activity. This produces an XML file which points to the XSL file so that direct browsing (Internet Explorer 5.0 and above) automatically displays the file with the correct visual behavior. So now, by simply double-clicking the file within Windows, the browser displays the report. The new XML file looks like this:

<?xml-stylesheet type="text/xsl" href="EZTPersnl.xsl"?><RPT_REPORT>                                                        <RPT>                                                               <REGION>1</REGION> ...the rest of the XML follows
Depending upon your Web implementation, it may suit your needs better to transform the XML file from within an HTML page. (NOTE: If you implement this method, do not add the procedure into your Easytrieve program as described above.) There are numerous methods of how to do this on the Web but the following is a simple example:
<html><head><title>Advantage CA-Easytrieve PERSNL Report</title></head><script LANGUAGE="JScript"><!--var xml = null;var xsl = null;function DoOnLoad() { xml = new ActiveXObject("MSXML2.DOMDocument.3.0"); xsl = new ActiveXObject("MSXML2.DOMDocument.3.0"); xml.async = false; xsl.async = false; xml.load("test.xml"); xsl.load("EZTpersnl.xsl");"text/html", "replace"); document.write(xml.transformNode(xsl));}--></script><BODY >     <SCRIPT LANGUAGE="JavaScript">DoOnLoad()</script></BODY></html>

After saving the above code as EZT1.htm and saving the XSL sample as EZTpersnl.xsl, by bringing up EZT1.htm within Internet Explorer, or creating a link (HREF) to it from any existing web page, your Advantage CA-Easytrieve data is displayed and looks similar to this:


Obviously, this is a very simple example for people new to XML and XLS. Your Advantage CA-Easytrieve program to select and combine data from multiple sources can be much more complex. The sample style sheet can be expanded to do many more things with all the capabilities of using frames, cascading style sheets with links on fields to point to other data, and it can imbed graphics as well. All this is possible and is limited only by your imagination. As you know, the easy part of all this is using Advantage CA-Easytrieve to report on your data!

In the next issue we will discuss improving the performance of reading XML files. If this article has generated any interest and you want to start playing with this capability, consider becoming a Beta tester of the new release and you will be able to start now. Sign up at