Building the COBOL sample

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:

  1. In the Application Development view, ensure you are viewing resources as Applications and Libraries. Click New.
  2. Click Start by creating a library. The New Library wizard opens.
  3. 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:

  1. In the Application Development view, ensure you are viewing resources as Applications and Libraries. Click New.
  2. Click Start by creating an application. The New Application wizard opens.
  3. In the project name field enter COBOLApplication. Click Next
  4. 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:

  1. OrderList
  2. PurchaseData
  3. CustomerAddress

To create a DFDL schema file for each of these COBOL copybooks:

  1. 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.
  2. In the New Message Model wizard, select COBOL. Click Next.
  3. Select Create a DFDL schema file by importing a COBOL copybook or program. Click Next.
  4. Select the copybook that you want to import from your workspace. Click Next
  5. 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.
  6. Leave these options as default. Click Next.
  7. Under Encoding options, select Fixed.
  8. In the Encoding (code page) drop-down list, select UTF-8. Set Byte order to Big Endian.
  9. 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:

  1. 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.
  2. In the Editor view, a choice is displayed as a child of the complex type, OrderList. Expand this choice, and select PointOfSale1.
  3. In the DFDL Properties view, click the Asserts and Discriminators tab.
  4. Select Discriminator, and click Add discriminator.
  5. In the Test Kind drop-down list, select expression.
  6. In the Test Condition field, enter {/OrderList/PointOfSaleType eq '1'}.
  7. In the Editor view, select PointOfSale2.
  8. In the DFDL Properties view, click the Test Conditions tab.
  9. Select Discriminator, and click Add discriminator.
  10. In the Test Kind drop-down list, select expression.
  11. In the Test Condition field, enter {/OrderList/PointOfSaleType eq '2'}.

To add the required discriminators to PurchaseData.xsd:

  1. 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.
  2. In the Editor view, expand SaleList > Invoice > Items > choice, and select Item1.
  3. In the DFDL Properties view, click the Test Conditions tab.
  4. Select Discriminator, and click Add discriminator.
  5. In the Test Kind drop-down list, select expression.
  6. In the Test Condition field, enter {/PurchaseData/SaleList/Invoice/Items/ItemType eq '1'}.
  7. In the Editor view, select Item2.
  8. In the DFDL Properties view, click the Test Conditions tab.
  9. Select Discriminator, and click Add discriminator.
  10. In the Test Kind drop-down list, select expression.
  11. 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:

At this point you can test your DFDL schema files by running a test parse of the sample data, see Testing a DFDL schema by parsing test input data.

Creating the OrderList2PurchaseData message flow

To create the OrderList2PurchaseData message flow that is used in this sample.

  1. 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.
  2. In the Message flow name field, enter OrderList2PurchaseData.
  3. Click Finish. The message flow is created, named OrderList2PurchaseData, and is opened in the Message Flow editor.
  4. 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.
  5. Connect the node terminals: For instructions, see Connecting message flow nodes in the IBM Integration Bus documentation.
  6. 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


  7. If using an ESQL Compute node, double-click the Compute node to open the ESQL Editor.
  8. 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;
    
    
  9. 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.
  10. Save the message flow.

Creating the Redefine message flow

To create the Redefine message flow that is used in this sample.

  1. 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.
  2. In the Message flow name field, enter Redefine.
  3. Click Finish. The message flow is created, named Redefine, and is opened in the Message Flow editor.
  4. 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.
  5. Connect the node terminals: For instructions, see Connecting message flow nodes in the IBM Integration Bus documentation.
  6. 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


  7. Double-click the Compute node to open it in the ESQL editor.
  8. 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;
    
  9. 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

  1. OrderList.bin (COBOL input for the OrderList2PurchaseData message flow, queue ORDERLIST.IN1)
  2. OrderListLogicalInstance.xml (XML input for the OrderList2PurchaseData message flow, queue XMLORDERLIST.IN)
  3. TestInputAddress1.bin (COBOL input for the Redefine message flow, queue BINARYADDR.IN1)

For information on how to use the Test Client, see Test Client Overview.

Back to Read about the sample

Back to sample home