Modeling COBOL data by using DFDL
View Details

IBM Knowledge Center

Learn how to model COBOL data by using Data Format Description Language (DFDL).
Back To Gallery

Import projects and create schema

Click Import and a shared library is imported into your workspace.

Library COBOL-Purchases contains a COBOL copybook called PurchaseData.cpy in 'Other resources'. It defines a COBOL data structure that records the purchases made by a customer. Open the copybook and look at the COBOL structure which is called PurchaseData. The main points of interest are:

  1. OCCURS DEPENDING ON. The purchases are recorded by an array of Item structures. There can be between 1 and 50 occurrences of Item, with the actual number provided by the ItemCount field at the start of the data.
  2. REDEFINES. Structure ItemGrocery is followed by structure ItemNonGrocery which overlays it. This means that either ItemGrocery or ItemNonGrocery will be present, but not both. The preceding ItemType field indicates which is actually present.

You will now create a DFDL schema to model the COBOL PurchaseData structure, using the New Message Model wizard.

Tip: Ensure that steps 1 to 7 below are all visible in the Tutorial Steps View before proceeding.

  1. With PurchaseData.cpy selected, click New... in the Application Development view, then select Message Model.... The New Message Model wizard opens.
  2. Select COBOL then click Next.
  3. Select the option Create a DFDL schema file by importing a COBOL copybook or program then click Next.
  4. PurchaseData.cpy should be highlighted. Click Next.
  5. The wizard loads and compiles the copybook, and presents all the 01 level structures it finds. Click the >> button then click Next.
  6. Here you can choose settings for DFDL properties such as default values, null values and padding characters. Leave the options to default and click Next.
  7. Here you can choose platform dependent settings such as encoding and zoned decimal sign representation. Leave the options to default and click Next.

Two DFDL schemas are created in the library. The PurchaseData.xsd schema models the overall COBOL data structure. The CobolDataDefinitionFormat.xsd schema defines suitable default values for DFDL properties. The imported copybook is copied into the importFile folder and a report is created in the log folder.

Exploring the schemas

The COBOL-Purchases library is shown in the Application Development view of your workspace.

The PurchaseData.xsd DFDL schema opens in the DFDL editor. If it does not open, double-click the DFDL schema to open it in the editor.

The PurchaseData message is highlighted and models the COBOL PurchaseData structure from the copybook. The main editor view shows the logical components of the message such as elements and sequences. You can explore the PurchaseData structure by expanding the elements.

The physical rendering of each logical component is described by the DFDL properties in the Representation Properties tab. DFDL properties can be specified locally on the component, or can be inherited from pre-defined sets of DFDL properties. Inherited properties have an icon shown next to them, and hovering over the icon reveals where the property is defined. In this schema, inherited properties are obtained from schema CobolDataDefinitionFormat.xsd.

The COBOL REDEFINES within Item has been imported as xs:choice. The COBOL OCCURS DEPENDING ON has resulted in the DFDL property Occurs Count Kind for Item being set to 'expression', and the DFDL property Occurs Count is a DFDL expression that refers to ItemCount.

You will be test parsing an example binary data file using the PurchaseData message. The test parsing takes place entirely within the DFDL editor, so there is no message flow in this tutorial and no Deploy step. Before test parsing, switch to the DFDL Test perspective by clicking Window > Open Perspective and then clicking DFDL Test. (Alternatively, you can use the toolbar icon ).

Tip: If this Tutorial Steps View tab disappears when you switch perspectives, use the Window > Show View menu option to add it back.

Follow these steps to complete the tutorial

The PurchaseData.xsd DFDL schema is open in the DFDL editor. The PurchaseData message should be highlighted in green.

  1. Test parse an example COBOL file:
    1. Click the Test Parse Model button in the DFDL editor toolbar. The Test Parse Model window opens.
    2. In the Message section, select PurchaseData.
    3. In the Parser Input section, select Content from a data file then click Browse.
    4. Select the PurchaseData1.bin file from COBOL-Purchases then click OK.
    5. Set the Encoding to ASCII.
    6. Click OK. If asked to confirm switching to the DFDL Test perspective, click Yes.
  2. The results of the test parse are displayed. You should see the message Parsing completed successfully. You can dismiss this message.
  3. You can view the parsed data file in the DFDL Test - Parse view. The results of the parse can be viewed in the DFDL Test - Logical Instance view, as a tree or as XML. If you expand Invoice and then each Item, you can see that the parser has correctly resolved the xs:choice to either ItemGrocery or ItemNonGrocery.
  4. When the parser encounters a xs:choice, its default strategy is to parse the data by trying the first branch of the choice. If that fails, the parser backtracks and tries the second branch. And so on, until a branch parses successfully. In our example, the parser tries ItemGrocery first, and if that fails it backtracks and tries ItemNonGrocery.
  5. Open the DFDL Test - Trace view and scroll back through the trace entries. You will see an error message CTDP3053E saying that a zoned number conversion error occurred. At this point the parser was attempting to parse the choice by trying ItemGrocery, but the error occurred. The trace entries after that show the parser backtracking and attempting to parse the choice by trying ItemNonGrocery, which succeeded.
  6. Sometimes the default strategy of the parser is not sufficient to resolve a xs:choice resulting from a COBOL REDEFINES. If that is the case, DFDL provides two other features to help you - discriminators and direct dispatch. These DFDL features are covered in detail by other IBM Integration Bus tutorials.
  7. Test serialize the logical instance that resulted from the parse:
    1. Click the Test Serialize Model button in the DFDL editor toolbar. The Test Serialize Model window opens.
    2. In the Serializer Input section, select Content from a DFDL Test - Logical Instance.
    3. Set the Encoding to ASCII.
    4. Click OK.
  8. The results of the test serialize are displayed. You should see the message Serialization completed successfully. You can dismiss this message.
  9. You can view the serialized data file in the DFDL Test - Serialize view. You can view a log of the serializer actions in the DFDL Test - Trace view.
  10. As an alternative to the toolbar buttons, you can also test from the DFDL Test - Parse and DFDL Test - Serialize views, using the Browse button to select a data source and the green play icon to run the DFDL parser or serializer.

The shared library can be deployed to an integration node for use by message flows.