XML GENERATE conversion to DB2 naming convention



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

XML GENERATE conversion to DB2 naming convention

Postby TomSteiner » Wed Aug 09, 2017 6:28 pm

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!
TomSteiner
 
Posts: 2
Joined: Wed Aug 09, 2017 6:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: XML GENERATE conversion to DB2 naming convention

Postby Robert Sample » Wed Aug 09, 2017 6:58 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: XML GENERATE conversion to DB2 naming convention

Postby TomSteiner » Wed Aug 09, 2017 7:13 pm

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.
TomSteiner
 
Posts: 2
Joined: Wed Aug 09, 2017 6:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: XML GENERATE conversion to DB2 naming convention

Postby Robert Sample » Wed Aug 09, 2017 10:06 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post