Generating a Copybook and Schema

You can generate a copybook with XML syntax extensions and an XML schema from an existing copybook or COBOL program. You can use the generated copybook to XML-enable your COBOL program. You can use the generated schema to create an XML document that conforms to the schema and contains data, and use that document as input to your COBOL. Use the following command-line format for cbl2xml to generate the copybook and the schema:

cbl2xml filename 
        [-c cobolFile]
        [-x schemaFile]
        [-d directiveFile]
        [-nocountin]        

To enable your COBOL program to access XML information that conforms to the schema generated, cbl2xml generates a new record in a separate copybook. This new record contains the XML syntax extensions necessary for XML operation. The following example assumes that you have not specified the -c or -x parameters:

Generated copybook with XML syntax extensions

cbl2xml takes the following copybook record contained in the file record.cpy:

01 A-FILE-RECORD.
   05 A-FILE-ITEM PIC XX.

and generates the following XML-enhanced copybook, filename record-cbl2xml.cpy:

01 a-file-record identified by "a-file-record" 
   count in a-file-record-count.
   02 a-file-item pic X(2) identified by "a-file-item" 
      count in a-file-item-count.

For detailed information on XML syntax extensions, see the topic XML Syntax Extensions.

To XML-enable your program, you need to either rename record-cbl2xml.cpy to record.cpy, or replace the original record in record.cpy with the record in record-cbl2xml.cpy.

The process of XML-enabling an entire COBOL program is the same as that of XML-enabling a copybook. In this case, cbl2xml generates a schema and program that contain equivalent information for each record found in the program.

The schema produced by running cbl2xml on record.cpy, record.xsd, is as follows:

Generated XML schema from a COBOL file definition

<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
   elementFormDefault="qualified">
   <element name="a-file-record">
      <complexType>
         <sequence>
            <element name="a-file-item">
               <simpleType>
                  <restriction base="string">
                     <length value="2"/>
                  </restriction>
               </simpleType>
            </element>
         </sequence>
      </complexType>
   </element>
</schema>
 
               	 

The following table explains the purpose of each schema tag in the context of the record it represents:

Schema Tag Description
<element name="a-file-record">
This defines the group-level data name A-FILE-RECORD. It serves as the parent element to all elements that define data items contained in the group.
<complexType>
This indicates that the group record has one or more subordinate data items.
<sequence>
This indicates the beginning of the sequence of tags that defines the subordinate record.
<element name="a-file-item">
This defines the data name of the subordinate data item A-FILE-ITEM. We know it is subordinate because this element tag is a child to a parent element tag.
<simpleType>
This indicates that the data item has no subordinate data items.
<restriction base="string">
This defines any restrictions on the data. In this case, the data must be a string, as indicated by the PIC XX clause in the COBOL data record.
<length value="2"/>
This defines the length of the record, which in this case is 2, as defined by the PIC XX in the COBOL data record.