I've wondered this for a long time. Should compilers, and even other environments (CICS et al) really have the responsibility for the support of transformations between programming language structures and XML/JSON/etc.? It seems to be that between COBOL, PL/I, CICS, DB2, etc. the parsing/generating between XML/JSON and programing language structures seems to have happened at least a few too many times.
DB2 I'm going to leave out because it probably really (perhaps) needs explicit XML (and JSON?) support. But do we really need all of these other ways? In my opinion, and no offense to COBOL development, but its only with the recent support of the SUPPRESS clause of XML GENERATE that Enterprise COBOL is even generally usable for transformation to XML. And it still has what I consider a fairly large limitation, which is that you must know the maximum number of occurrences that you can ever have for an element, and make the table "OCCURS clause" match that. Yes, I realize that there is OCCURS UNBOUNDED, but that requires:
- Dynamic memory allocation (made simpler in V6 with ALLOCATE statement, but...)
- Still knowing before you allocate memory for your structure how many occurrences will be in it!
This being said, I think that perhaps COBOL itself (compiler and run-time) are not the place for this support at all. Let them concentrate on improving the compiler and supporting the actual COBOL standard! I envision an API, perhaps built by the group that built z/OS Connect Enterprise Edition, that can be used by any of the more "static" programming languages (COBOL, probably PL/I, and perhaps C) to perform transformation between the language data structures and XML/JSON/(others?). In fact I imagine that configuration of a JSON transformation and configuration of an XML transformation would be pretty much the same (except where one format has a feature that simply cannot be represented in the other format), so that when calling the API to transform to one of the formats you would simply choose XML or JSON as the destination format.
I have many more, specific, thoughts on this, but I'm wondering if I am just "off the beam", or if this is a valid thing to request from IBM. It seems to me that it could eliminate the need for XML PARSE and XML GENERATE from COBOL and the XMLCHAR and the PLISAXx functions from PL/I. For CICS, the TRANSFORM command (which just recently added DATATOJSON and JSONTODATA options) could either be eliminated, or at the very least could be modified internally to utilize my envisioned API. Also the transformations required by SOAP and REST support in CICS. Others I don't know as much about (IMS TM, for example), but I can't see why they wouldn't use this as well.
I'm not really suggesting XML PARSE and XML GENERATE be removed, as it is used to heavily, but that COBOL no longer need to make enhancements to them. If this responsibility is in "once place" then hopefully we wouldn't have all of the "re-inventing of the wheel" that seems to have occurred up to this point. Additionally, hopefully the group supporting this API would be more focused on supporting all of the features that are truly needed for these transformations. It seems to me that COBOL support, and I am truly not trying to offend, only adds support for features as requests come in for them; rather than having taken a holistic approach and supported "everything" (or everything reasonable) at the get-go. Specifically I refer to how originally there was no support originally (in XML GENERATE) for attributes, assigning names other than the "COBOL names", applying individual types on a "per field" basis, suppressing "empty" fields, etc. All of these are now supported, but it seems to me to have been a long time coming and should have been implemented on "day one" of XML support (10+ years ago?). Or rather, they should not have been implemented at all, but rather as part of this API I am thinking about. (And I won't even get in to the horror of XML PARSE, which is so low-level that I've never actually used it in a production program.)
Note that I am not referring to the low-level support that is provided by z/OS XML System Services and the z/OS JSON Parser. Certainly this new API, which I see as being at a higher level, would use those services under the covers.
Its interesting to note that the COBOL standards committee, who released the COBOL 2002 and COBOL 2014 standards, had long and heated discussions regarding if COBOL should support XML at a language level. There was a proposed language support, and interestingly it was not the XML PARSE and XML GENERATE statements supported by Enterprise COBOL, but rather something based on an "XML file" where you would "describe" your transformations in an "XD entry" in the FILE SECTION. This feature is not present in either release of the standard, so I must assume the proponents lost. And perhaps that's all for the best.
I guess I should briefly (??) describe how I envision this API would work. Basically, you'd have a "configuration artifact" that might be very simple to how a "BMS map" is developed. You would describe the "programming language structure" and how it maps to the desired "external formats" (XML, JSON, other?). You'd use this to generate the actual programming language structure(s) (COBOL copybook, etc) as well as an "internal control block" that is understood by the API. The program itself would simply invoke the API with the "name" of the structure, the direction (to/from), the external format (XML/JSON), and the address of the source and destination. And probably a "results" field to hold error conditions, etc.
It should also allow not just a single call to the API, but also a "streaming" type of transformation, where you could feed in "chunks" of source data and also retrieve in to perhaps more than one programming language structure. This would allow for transformation of very large documents where you don't know ahead of time how large they are (think of VisaNet's "VML" files, if you are familiar with them. They could have millions of instances of some elements.)
Am I crazy? Should I request this? Should be come free with z/OS, or should we have to pay extra? What are your thoughts?
Frank
fswarbrick