Q
Problem solve Get help with specific problems with your technologies, process and projects.

Can I convert a legacy file to XML with COBOL?

I have to propose a solution to convert a legacy flat-file (fixed-width) to XML. I have the following questions:
  1. Can I do that in COBOL on z/OS?
  2. If so, then what are the software requirements on z/OS?
  3. And what would I need to code in COBOL?
  1. Yes!
  2. Enterprise COBOL for z/OS Version 3 Release 3 (PID 5655-G53).
  3. The first thing you have to decide is if you want the entire file encoded as one XML document or each record to be one XML document. To get the entire file converted into one XML document, you could read each record into the COBOL program record description, then use the new XML GENERATE FROM statement to create an XML message from each record. The first step (optional) in creating the XML document is to output the XML declaration; next create the begin element for the entire file, and then you can do all the XML GENERATEs for each of the records. Something like this:
    Move '<?xml version="1.0"?>' To xml-doc(1:21)
    Move '<File-name>' To xml-doc(22:11)
    Compute sp = 34 
    Perform Until EOF
    Read rec-1 
    At End 
    Set EOF To True
    Not At End
    XML Generate xmldoc(sp: ) From rec-1
    Count in xc
    Add xc To sp 
    End-Read
    End-Perform 
    Move '</File-name>' To xml-doc(sp:12)
    

Dig Deeper on IBM system z and mainframe systems

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

SearchServerVirtualization

SearchCloudComputing

Close