I have to propose a solution to convert a legacy flat-file (fixed-width) to XML. I have the following questions:
- Can I do that in COBOL on z/OS?
- If so, then what are the software requirements on z/OS?
- And what would I need to code in COBOL?
- Enterprise COBOL for z/OS Version 3 Release 3 (PID 5655-G53).
- 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
Set EOF To True
Not At End
XML Generate xmldoc(sp: ) From rec-1
Count in xc
Add xc To sp
Move '</File-name>' To xml-doc(sp:12)