Page 1 of 1

XML GENERATE conversion to DB2 naming convention

PostPosted: Wed Aug 09, 2017 6:28 pm
by TomSteiner
The situation that I have is that I need to generate XML that has DB2 column names as tags from a COBOL copylib. The names in the copylib match the DB2 column names except the hyphen in the COBOL variable and underscore in the DB2 column name.

XML GENERATE will create the XML based on the COBOL names with the hyphen ..... any ideas on how to easily convert the hyphen to underscores in the process?

01 STRUCT.
02 STAT-CD PIC X.
02 IN-AREA PIC X(2).

want

<STRUCT><STAT_CD>A</STAT_CD><IN_AREA>AA</IN_AREA></STRUCT>

Thanks in advance for your ideas!

Re: XML GENERATE conversion to DB2 naming convention

PostPosted: Wed Aug 09, 2017 6:58 pm
by Robert Sample
Why not
01 STRUCT.
 02 STAT_CD PIC X.
 02 IN_AREA PIC X(2).

This compiles with no errors on my 5.1 COBOL. Since the XML GENERATE statement explicitly tells you the XML is generated from the COBOL data names, I don't think you can do anything else and get what you want.

Re: XML GENERATE conversion to DB2 naming convention

PostPosted: Wed Aug 09, 2017 7:13 pm
by TomSteiner
Thanks Robert - was hoping there was some type of "replace all" process to run to execute after the call to XML GENERATE to take the output and replace the hyphens with underscores.

Re: XML GENERATE conversion to DB2 naming convention

PostPosted: Wed Aug 09, 2017 10:06 pm
by Robert Sample
There's nothing in COBOL to do that, and writing your own could run into issues if you have negative numbers in your data, or dashes in quoted fields in the XML data. Changing the COBOL data definitions is most likely the easiest way.