COBOL Copybook to XSD

COBOL Copybook to XSD

QTAssistant provides the ability to convert a COBOL copybook (containing data description etnries) into an XML Schema. The tool uses the XML metadata generated from the source copybook, to generate an equivalent XSD.

The conversion uses the following conventions:

  • A REDEFINES is converted into an xsd:choice
  • OCCURS is captured as an element occurrence (maxOccurs)
  • An 88 record level is converted into an xsd:enumeration facet.
  • The equivalent display length is converted into an appropriate length facet (depending on the underlying type, numeric vs. string)
      **************************************************************
      * QTAssistant COBOL Samples                                  *
      *                                                            *
      * Sample request 0001 - Simple IFX 1.7/1.8-like transaction. *
      * Payment Cancellation PMTCAN                                *
      **************************************************************
      *  Revision history                                          *
      *------------------------------------------------------------*
      *QTAR  DATE       NOTES                                AUTHOR*
      *----- ---------- ------------------------------------ ------*
      *2408  05/10/29   First version.                       PG    *
      **************************************************************      
       01  PMTCANRQ-RECORD.
           02 PMTCANRQ-RQUID                           PIC X(36).  
           02 PMTCANRQ-MSGRQHDR.  
              03 PMTCANRQ-NETWRK-INFO.
                 05 PMTCANRQ-NETWRK-OWNER              PIC X(3).
                    88 PMTCANRQ-NETWRK-ATM             VALUE 'ATM'.
                    88 PMTCANRQ-NETWRK-POS             VALUE 'POS'.
                    88 PMTCANRQ-NETWRK-ACH             VALUE 'ACH'.
           02 PMTCANRQ-CUSTID.
              05 PMTCANRQ-SPNAME                       PIC X(10).
              05 PMTCANRQ-CUST-PERMID                  PIC X(20).
           02 PMTCANRQ-PMTID                           PIC X(36).      

The generated XML file is shown below.

<copybook filename="SAMPLE-RQ.cpy.xsd.xml">
  <item level="01" name="PMTCANRQ-RECORD" position="1" display-length="105" storage-length="105">
    <item level="02" name="PMTCANRQ-RQUID" picture="X(36)" display-length="36" storage-length="36" position="1" />
    <item level="02" name="PMTCANRQ-MSGRQHDR" position="37" display-length="3" storage-length="3">
      <item level="03" name="PMTCANRQ-NETWRK-INFO" position="37" display-length="3" storage-length="3">
        <item level="05" name="PMTCANRQ-NETWRK-OWNER" picture="X(3)" display-length="3" storage-length="3" position="37">
          <condition name="PMTCANRQ-NETWRK-ATM">
            <condition value="ATM" />
          </condition>
          <condition name="PMTCANRQ-NETWRK-POS">
            <condition value="POS" />
          </condition>
          <condition name="PMTCANRQ-NETWRK-ACH">
            <condition value="ACH" />
          </condition>
        </item>
      </item>
    </item>
    <item level="02" name="PMTCANRQ-CUSTID" position="40" display-length="30" storage-length="30">
      <item level="05" name="PMTCANRQ-SPNAME" picture="X(10)" display-length="10" storage-length="10" position="40" />
      <item level="05" name="PMTCANRQ-CUST-PERMID" picture="X(20)" display-length="20" storage-length="20" position="50" />
    </item>
    <item level="02" name="PMTCANRQ-PMTID" picture="X(36)" display-length="36" storage-length="36" position="70" />
  </item>
</copybook>

The corresponding XSD:

<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/Enterprise Toolbox (COBOL) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="PMTCANRQ-RECORD">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="PMTCANRQ-RQUID">
          <xsd:simpleType>
            <xsd:restriction base="xsd:string">
              <xsd:maxLength value="36" />
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
        <xsd:element name="PMTCANRQ-MSGRQHDR">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="PMTCANRQ-NETWRK-INFO">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="PMTCANRQ-NETWRK-OWNER">
                      <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                          <xsd:enumeration value="ATM">
                            <xsd:annotation>
                              <xsd:documentation>PMTCANRQ-NETWRK-ATM</xsd:documentation>
                            </xsd:annotation>
                          </xsd:enumeration>
                          <xsd:enumeration value="POS">
                            <xsd:annotation>
                              <xsd:documentation>PMTCANRQ-NETWRK-POS</xsd:documentation>
                            </xsd:annotation>
                          </xsd:enumeration>
                          <xsd:enumeration value="ACH">
                            <xsd:annotation>
                              <xsd:documentation>PMTCANRQ-NETWRK-ACH</xsd:documentation>
                            </xsd:annotation>
                          </xsd:enumeration>
                        </xsd:restriction>
                      </xsd:simpleType>
                    </xsd:element>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="PMTCANRQ-CUSTID">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="PMTCANRQ-SPNAME">
                <xsd:simpleType>
                  <xsd:restriction base="xsd:string">
                    <xsd:maxLength value="10" />
                  </xsd:restriction>
                </xsd:simpleType>
              </xsd:element>
              <xsd:element name="PMTCANRQ-CUST-PERMID">
                <xsd:simpleType>
                  <xsd:restriction base="xsd:string">
                    <xsd:maxLength value="20" />
                  </xsd:restriction>
                </xsd:simpleType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="PMTCANRQ-PMTID">
          <xsd:simpleType>
            <xsd:restriction base="xsd:string">
              <xsd:maxLength value="36" />
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

The XSD model:

Generated XSD
Generated XSD
(Click to Enlarge)

QTAssistant provides the ability to generate a relational model from an XSD. The "compactness" of the model depends on the tool used. The .NET built in conversion to a dataset generates a layout based on how many complex types are present in the XSD.

The ADO.NET dataset associated with the XSD
The ADO.NET dataset associated with the XSD
(Click to Enlarge)

The XML Builder mapper creates a model based on the cardinality of the relationship between a parent and its children nodes, as well as whether choices are used or not.

Cardinality-driven dataset for the XSD
Cardinality-driven dataset for the XSD
(Click to Enlarge)