I am working on a project where I will read an xml file from disk that a cobol mainframe system has created. I want a specific naming struture in this xml file like this:
<Orders>
<Order>
<Data>
...
</Data>
</Order>
<Order>
<Data>
...
</Data>
</Order>
<Order>
<Data>
...
</Data>
</Order>
</Orders>
The issue I have learned with this naming structure from my cobol developer is that "Order" and "Data" are reserved names in cobol so he says they cannot be used. Is this really the case or could someone point us in a direction where our xml output can be anything we want when cobol is creating the xml file?
IBM Enterprise COBOL has an XML GENERATE statement which is used to generate XML from COBOL data structures. The generated tag names are, by default, the names of the data items in the structure. The name of a data item cannot be a reserved COBOL word.
Since version 5 of IBM Enterprise COBOL there is a mechanism to generate tag names for data items that are not the name of the data item. It is the NAME phrase of the XML GENERATE statement.
A structure that looks like this...
01 WS-ORDERS.
05 WS-ORDER OCCURS 2.
10 WS-DATA PIC X(4096).
...processed via XML GENERATE would normally result in...
<WS-ORDERS><WS-ORDER><WS-DATA>...</WS-DATA></WS-ORDER><WS-ORDER><WS-DATA>...</WS-DATA></WS-ORDER></WS-ORDERS>
...but using the NAME phrase...
XML GENERATE WS-BUFFER FROM WS-ORDERS
NAME WS-ORDERS 'ORDERS'
WS-ORDER 'ORDER'
WS-DATA 'DATA'
END-XML
...should give you what you want. That's just freehand, but I think you can see the idea.
It's possible your COBOL compiler hasn't been upgraded to a version that supports the NAME phrase of XML GENERATE. The last such version is 4.2, which goes out of service on 30-Apr-2022.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With