COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.

 View Only
  • 1.  XML to COBOL copybooks

    Posted Thu October 19, 2017 03:52 AM

    Hi there,

    I'm trying to build a program to convert XML to COBOL copybooks. Don't want to have to use a separate converter. As I searched the web, I found many having the same problems I do. 

    Based on the example 'parsing an XML document one segment at a time' in the 'Enterprise COBOL for z/OS, V6.1 Programming Guide'  (page 574), I've build a little program that interprets this XML-file fmtest3.xml

    My program (fmtest3.txt) at this moment can detect in which copybook to write based on the attribute given. I've made sections vul-fm001 and vul-fm002 to fill the appropriate copybooks. But now this is the problem. How can I write a move statement that uses the tagname as fieldname. Idealy I would have something like MOVE XML-text to 'field-name' in FM00x. 

    I could, of course use an IF-statement and use hard-coded field-names, but I want to make this more flexiable by using a variable for the field-name (and maybe also for the copybook-name) so I could code one MOVE-statement. 

     

    Hope there's someone who can help.

     

    Thanx in advance

     

    Fons

     

     

    Fonzie2405


  • 2.  Re: XML to COBOL copybooks

    Posted Sun October 29, 2017 03:24 PM

    Your goal seems to be to have exactly one program that executes the XML PARSE statement and is able to parse arbitrary XML data streams.  This feels uncomfortably close to the Inner-Platform Effect (https://thedailywtf.com/articles/The_Inner-Platform_Effect).

    COBOL does not have a reflection API like Java.  Nor does C or FORTRAN, or PL/I.  So you cannot do what you seem to want in the fashion you seem to want to do it.

    I think a better approach to solving a problem with COBOL is to design your application with the capabilities of COBOL in mind.

    Perhaps write a code generator, something that reads input consisting of your tag names and generates the desired COBOL program.  Or a copybook.  Or make use of the BASIS statement.

    cschneid_the_elder