Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML-GENERATE for z/OS COBOL 3.3 and underscore help

Status
Not open for further replies.

lordsmiter

Programmer
Apr 26, 2005
2
US
Hi,

I have a troubling issue that I have researched heavily and keep coming up with dead ends. We are migrating an XML process to the mainframe using the new COBOL statements in Version 3 Release 3. Right now it is multi-platform (mainframe to windows server via websphere) and it is not yielding the performance we need.

My problem is that when generating an XML document from our COBOL copybook (XML-GENERATE), the resulting XML document tags must contain underscores "_" in the resulting names. Now since the XML document tags are generated using the data structure names that I build in COBOL, it would dictate that the data names in COBOL would need to contain underscores. This does not compile so well. There must be a way to get underscores in COBOL data names. I would need something like this in COBOL:

01 XML_Document.
05 Tag_1 PIC X(05).
05 Tag_2 PIC X(05).

After I populate this and run XML-GENERATE, it should produce this:

<XML_Document>
<Tag_1>12345</Tag_1>
<Tag_2>12345</Tag_2>
</XML_Document>

Obviously I can't get past compile with that data structure though. Is this a system limitation? Any ideas on how I may get this to happen in COBOL? I am clueless as well as the Development Center where I work.

Thanks in advance!



Jason
 
Well, we are limited to the features that COBOL supports. Also the process must be as streamlined as possible. As soon as COBOL generates the XML it is being shipped "out the door". All of this needs to happen in milliseconds. The formating of the XML is very strict, that is why underscores are there.

Is there a way to have COBOL do this transform in a single pass? I didn't even think I could feed in style sheets to COBOL.



Jason
 
Jason,

While I am not familiar with IBM's implementation, it appears from the online documentation that (1) XML element names are derived directly from the COBOL data-names which are in turn user words, and (2) user words are constrained to a character set that does not include the underscore character. From this, one might conclude there is no 'COBOL only' solution.

Now, turning your attention to process that is shipping the generated XML document 'out the door' (which most likely is not being done by any 'features that COBOL supports'), is there the possibility that this process might apply an XSLT transformation as part of its duties?

From the point of view of XML document manipulation, the IBM COBOL implementation is, frankly, very limited in its capabilities. I can only conclude from this that IBM must have presumed the existence of extra-COBOL mechanisms to do the very common things one does with XML documents (such as transforming them with XSLT).

Tom Morrison
 
Just for the record,
I answered the question in comp.lang.cobol

pointing out that SHARE (the IBM user group) has already asked for ISO 2002 COBOL underscore support and that this (or any other) IBM customer can submit a "REQUEST" via their marketting rep(s).

Bill Klein
 
This is a COBOL Language Limitation. Variable names can not contain an underscore. If you had some way to convert the "-" to "_" in XML that might work better. If you choose to use Cobol you have to expect that.

You might be able to convert a text file of field using a ASCII map or some kind of character conversion. However, normally "_" is an unacceptable part of any variable name in Cobol. You could convert the source code to change "-" to "_" but it would not compile as COBOL. Inspect can replace one character for another. Also the editor used on the mainframe may have a global replace function that can do the same thing. Cobol source is just text.

If you do not like my post feel free to point out your opinion or my errors.
 
Just a comment on that last post.

An underscore may NOT be a part of a user-defined word in the '85 ANSI/ISO Standard; it *MAY* be used as such in an '02 Standard program/compiler.

Several (not most?) vendors allow it as an extension to the '85 Standard. IBM ("original home" of XML GENERATE) does not (currently) have this extension.

Bill Klein
 
The output of the XML GENERATE command is a COBOL record in memory (working-storage). COBOL has provided a number of elegant ways of editing memory records since it started back in the 60's. In fact this was the reason that COBOL was invented.

The simplest solution is therefore:
XML GENERATE xml-output from COBOL-source-record
END-XML
INSPECT xml-output replacing all '-' by '_'

After the INSPECT command, the xml-output now contains valid XML statements with '_' instead of the '-'.

If you need to add any additional xml headers/trailers not provided by the GENERATE command, these can then be appended to the xml-output using the COBOL STRING command.



 
As I stated earlier in this thread, the only problem with the INSPECT REPLACING (or comparable) solution is that it will ALSO change any hyphens WITHIN data as well in tag names. It is possible to get around this by using a PERFORM VARYING and checking for "where you are" when doing the conversion, but it is easiest if you can "guarantee" that no data will include hyphens.

Bill Klein
 
It might be feasible to replace all "-"'s contained within data by a unique character, say a "`" somewhere before it becomes xml output. Then you could do as ft4611 suggests, with one additional step; add the statement "INSPECT xml-output replacing all '`' by '-' " after the inspect statement that converts all dashes to underscores.

In other words, convert the dashes within the data stream away from dashes before they “collide,” then convert them back to dashes after the underscore conversion.


Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top