You can use the instructions in this topic to build the COBOL sample. Alternatively, you can import the completed DFDL schemas, application, and library for the sample.
Creating the Application and Library
This sample uses an application and a library to contain the sample artifacts. First create the Library:
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Click New.
Click Start by creating a library. The New Library wizard opens.
In the project name field enter COBOLLibrary. Click Finish
A library is created, named COBOLLibrary, and is shown in the Application Development view.
Now that you have created the library, create the application:
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Click New.
Click Start by creating an application. The New Application wizard opens.
In the project name field enter COBOLApplication. Click Next
Select your previously created library, COBOLLibrary. Click Finish.
An application is created, named COBOLApplication, and is shown in the Application Development view.
Creating the DFDL schema files
This section describes how to create the DFDL schema files used in this sample, by importing COBOL copybooks. Save the following COBOL copybooks into your file system and drag and drop them onto the COBOLLibrary project in the Application Development view:
To create a DFDL schema file for each of these COBOL copybooks:
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Right-click the library, COBOLLibrary.
Click New > Message Model. The New Message Model wizard opens.
In the New Message Model wizard, select COBOL. Click Next.
Select Create a DFDL schema file by importing a COBOL copybook or program. Click Next.
Select the copybook that you want to import from your workspace. Click Next
Each of the COBOL copybooks that is provided contains only one level 01 element. Select this element in the Source structures list, and then click the > button
to move the element to the Imported structures list. Click Next.
Leave these options as default. Click Next.
Under Encoding options, select Fixed.
In the Encoding (code page) drop-down list, select UTF-8. Set Byte order to Big Endian.
Click Finish
The DFDL schema file is created (file extension .xsd), and is displayed in the Schema Definitions folder of your library, COBOLLibrary. Repeat these steps for each of the three COBOL copybooks.
Adding discriminators to the DFDL schema files
Before the DFDL schema files OrderList.xsd and PurchaseData.xsd can be used in this sample, you must add discriminators to each of the choice elements.
To add the required discriminators to OrderList.xsd:
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Expand COBOLLibrary > Schema Definitions. Right-click the DFDL schema file, OrderList.xsd and select Open. The DFDL schema file opens in the DFDL schema editor.
In the Editor view, a choice is displayed as a child of the complex type, OrderList. Expand this choice, and select PointOfSale1.
In the DFDL Properties view, click the Asserts and Discriminators tab.
Select Discriminator, and click Add discriminator.
In the Test Kind drop-down list, select expression.
In the Test Condition field, enter {/OrderList/PointOfSaleType eq '1'}.
In the Editor view, select PointOfSale2.
In the DFDL Properties view, click the Test Conditions tab.
Select Discriminator, and click Add discriminator.
In the Test Kind drop-down list, select expression.
In the Test Condition field, enter {/OrderList/PointOfSaleType eq '2'}.
To add the required discriminators to PurchaseData.xsd:
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Expand COBOLLibrary > Schema Definitions. Right-click the DFDL schema file, PurchaseData.xsd and select Open. The DFDL schema file opens in the DFDL schema editor.
In the Editor view, expand SaleList > Invoice > Items > choice, and select Item1.
In the DFDL Properties view, click the Test Conditions tab.
Select Discriminator, and click Add discriminator.
In the Test Kind drop-down list, select expression.
In the Test Condition field, enter {/PurchaseData/SaleList/Invoice/Items/ItemType eq '1'}.
In the Editor view, select Item2.
In the DFDL Properties view, click the Test Conditions tab.
Select Discriminator, and click Add discriminator.
In the Test Kind drop-down list, select expression.
In the Test Condition field, enter {/PurchaseData/SaleList/Invoice/Items/ItemType eq '2'}.
You should now have three DFDL schema files, which look like this:
To create the OrderList2PurchaseData message flow that is used in this sample.
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Right-click the application, COBOLApplication. Click New > Message Flow. The New Message Flow wizard opens.
In the Message flow name field, enter OrderList2PurchaseData.
Click Finish. The message flow is created, named OrderList2PurchaseData, and is opened in the Message Flow editor.
In the Message Flow editor, add two MQInput nodes, a transformation node of your choice (for example an ESQL Compute or a Mapping node), and an MQOutput node.
For instructions, see Creating a message flow in the IBM Integration Bus documentation.
Connect the node terminals:
Connect the Out terminal of both MQInput nodes to the In terminal of the transformation node.
Connect the Out terminal of the transformation node to the In terminal of the MQOutput node.
Configure the node properties as listed in the following table. Accept the default values for all properties unless an alternative value is listed in the table.
For instructions, see Configuring a message flow node in the IBM Integration Bus documentation.
Node
Page
Property
Value
MQInput (for binary OrderList)
Basic
Queue name
ORDERLIST.IN1
Input Message Parsing
Message domain
DFDL
Input Message Parsing
Message
{}:OrderList
MQInput (for XML OrderList)
Basic
Queue name
XMLORDERLIST.IN
Input Message Parsing
Message domain
XMLNSC
Validation
Validate
Content and Value
Parser Options
Build Tree using XML schema data types
yes
MQOutput
Basic
Queue name
PURCHASEDATA.OUT1
If using an ESQL Compute node, double-click the Compute node to open the ESQL Editor.
In the editor view, replace the existing ESQL with the following code:
CREATE COMPUTE MODULE OrderList2PurchaseData_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
SET OutputRoot.DFDL.PurchaseData.InvoiceCount = InputBody.OrderList.InvoiceCount;
SET OutputRoot.DFDL.PurchaseData.ItemCount = InputBody.OrderList.ItemCount;
DECLARE TotalQuantity INTEGER 0;
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputBody.OrderList.SaleList.Invoice[]);
WHILE I <= J DO
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].CustomerInitial[1] = InputBody.OrderList.SaleList.Invoice[I].InvoiceHeader.CustomerInitial[1];
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].CustomerInitial[2] = InputBody.OrderList.SaleList.Invoice[I].InvoiceHeader.CustomerInitial[2];
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Surname = InputBody.OrderList.SaleList.Invoice[I].InvoiceHeader.Surname;
DECLARE K INTEGER 1;
DECLARE L INTEGER;
SET L = CARDINALITY(InputBody.OrderList.SaleList.Invoice[I].Items.Item[]);
WHILE K <= L DO
DECLARE OutputItem ROW;
SET OutputItem = THE (
SELECT Inv.ItemType
, Inv.ItemCode
, Inv.Description
, Inv.Price
, Inv.Category
, It.Quantity
FROM InputBody.OrderList.SaleList.Invoice[I].Items.Item[K] AS It
, InputBody.OrderList.Inventory.Item[] AS Inv
WHERE Inv.ItemCode = It.ItemCode
AND Inv.ItemCode = InputBody.OrderList.SaleList.Invoice[I].Items.Item[K].ItemCode
);
IF OutputItem.ItemType = '1' THEN
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].ItemType = OutputItem.ItemType;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item1.itemCode = 'AA';
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item1.Description = OutputItem.Description;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item1.Price = OutputItem.Price;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item1.Category = OutputItem.Category;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item1.Quantity = OutputItem.Quantity;
ELSE
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].ItemType = OutputItem.ItemType;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item2.ItemCode = OutputItem.ItemCode;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item2.Colour = OutputItem.Description;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item2.Price = OutputItem.Price;
SET OutputRoot.DFDL.PurchaseData.SaleList.Invoice[I].Items[K].Item2.Quantity = OutputItem.Quantity;
END IF;
SET TotalQuantity = TotalQuantity + OutputItem.Quantity;
SET K = K + 1;
END WHILE;
SET I = I + 1;
END WHILE;
--Trailer
SET OutputRoot.DFDL.PurchaseData.Trailer.TotalQuantity = TotalQuantity;
IF EXISTS(InputBody.OrderList.PointOfSale1[]) THEN
SET OutputRoot.DFDL.PurchaseData.Trailer.PointOfSaleType = '1';
ELSE
SET OutputRoot.DFDL.PurchaseData.Trailer.PointOfSaleType = '2';
END IF;
RETURN TRUE;
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
END MODULE;
If you are using a Mapping node, double-click the Mapping node to open the Graphical Data Map editor.
Select "OrderList" as the input and "PurchaseData" as the output, and build the required transforms.
Save the message flow.
Creating the Redefine message flow
To create the Redefine message flow that is used in this sample.
In the Application Development view, ensure you are viewing resources as Applications and Libraries. Right-click the application, COBOLApplication. Click New > Message Flow. The New Message Flow wizard opens.
In the Message flow name field, enter Redefine.
Click Finish. The message flow is created, named Redefine, and is opened in the Message Flow editor.
In the Message Flow editor, add an MQInput node, a Compute node and an MQOutput node.
For instructions, see Creating a message flow in the IBM Integration Bus documentation.
Connect the node terminals:
Connect the Out terminal of the MQInput node to the In terminal of the Compute node.
Connect the Out terminal of the Compute node to the In terminal of the MQOutput node.
Configure the node properties as listed in the following table. Accept the default values for all properties unless an alternative value is listed in the table.
For instructions, see Configuring a message flow node in the IBM Integration Bus documentation.
Node
Page
Property
Value
MQInput
Basic
Queue name
BINARYADDR.IN1
Input Message Parsing
Message domain
DFDL
Input Message Parsing
Message model
CustomerAddress.xsd
Input Message Parsing
Message
{}CustomerAddress.xsd
MQOutput
Basic
Queue name
XMLADDR.OUT1
Double-click the Compute node to open it in the ESQL editor.
In the editor view, replace the existing ESQL with the following code:
CREATE COMPUTE MODULE RedefineAddr_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
SET OutputRoot.XMLNSC = InputRoot.DFDL;
RETURN TRUE;
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
END MODULE;
Save the message flow.
Deploying
To deploy your application, drag the application, COBOLApplication onto the execution group to which you want to deploy it. A BAR file is generated automatically, and deployed to the integration node.
Testing
This sample provides some example test data for all three scenarios. Save the following test data files into your file system and drag and drop them into the COBOLLibrary project
OrderList.bin (COBOL input for the OrderList2PurchaseData message flow, queue ORDERLIST.IN1)