One of the biggest IT challenges is the growing IT delivery gap and the ever-increasing pace of business changes. This is especially true for established companies saddled with a mix of older applications. In order to efficiently connect these systems to other business components at scale, the application business logic and data must be packaged as easy-to-consume reusable assets.

Due to its monolithic nature, most legacy applications span multiple business domains. As a result, the number of required integrations is typically high. When we consider the complexity of integrating with legacy systems, the shortage of specialized skills, and tight budgets, it’s easy to see why unlocking ERP data and logic is a constant concern for IT leaders.

Technically, this problem boils down to the question: how fast can you build an API that calls the backend business logic, and how much of that work depends on the legacy team? In this how-to guide, I’ll show you how to use the latest version of MuleSoft’s Anypoint Connector for IBM i (AS400) to accelerate wrapping business logic programs into a REST API without any IBM i tools or development required. Once the IBM i (AS400) API is developed, it can be plugged into the Anypoint Platform for added security, governance, and operational insight.

Use Case

Suppose a company is implementing a new order channel for an IBM i based ERP. The ERP has a generic RPG program that already implements all the necessary validations and business logic for creating the order and pushing it through the fulfilment flows. The purpose of this task is to expose the Create Order program to other systems as an easy-to-consume System API.

Implementation

Below is a simplified RPG program definition that we will use for this example – it takes in the order ID and a list of up to 10 line items (each consisting of item code, quantity and price).

1_rpg1. We start with building RAML definition for the API, matching the parameter structure:

[code]
#%RAML 0.8
title: IBM i Program Call API
version: 1.0.0
/orders:
  post:
    body:
      application/json:
        example: |
         {
            "orderID": 12345,
            "orderLines": 2,
            "orderItemsIn": [
              {
                "item": "ITEM1",
                "qty": 123.45,
                "price": 321.45
              },
              {
                "item": "ITEM2",
                "qty": 234.45,
                "price": 987.45
              }
            ]
         }
    responses:
      200:
        body: 
          application/json:
            example: |
              {
                "orderID": 12345,
                "orderLines": 2,
                "orderItemsOut": [
                  {
                    "item": "ITEM1",
                    "qty": 123.45,
                    "price": 321.45
                  },
                  {
                    "item": "ITEM2",
                    "qty": 234.45,
                    "price": 987.45
                  }
                ]                
              }
[/code]

2. Next, right-click on the RAML definition in Anypoint Studio and auto-generate the API scaffolding using APIKit. Method post:/orders:apiConfig will initially return the sample response defined in the RAML above.

3. Finally we need to implement the program call. Drag the IBM i (AS/400) connector to post:/orders:apiConfig flow, set the connection parameters and test the connection:

2_connection

 

4. Select the Program Call operation and set the program name, library, and parameters.

5. Click on the plus sign and fill in parameter details. Pass parameter values from API request body to input or inout parameters.

3_parameters

6. For the order lines data structure, specify the data type as STRUCTURE, count of 10 (as this is an array of structures), and define nested data structure fields. Similarly, define the return data structure for lines returned back.

7. Switch to XML view and confirm the correct sequence of the parameters. Because of the way that Anypoint Studio handles lists of parameters, the order of elements in the list may change. The RPG program requires the parameters to be passed in exactly the same order as they are defined in the program. The resulting program definition looks like this:

Screen Shot 2017-10-11 at 2.12.41 PM

8. And, finally, stick a transformer that converts the API request body to Java map. You can either use DataWeave or a Byte Array to Object transformer and specify target class java.util.Map. I prefer to use DataWeave:

[code]
%dw 1.0
%output application/java
---
payload
[/code]

And that, ladies and gentlemen, is how you build an IBM i API using MuleSoft in 15 minutes!

Run the application, and test it by posting the sample request using the Anypoint Studio API console or any other API client, like Postman:

4_postman

The RPG program I am using for this demo, intentionally updates the values of the order ID and line item details, adding 100 to the order ID, concatenating item numbers using “out” and adding 20 to quantity and 10 to price. There’s no reason behind this other than to show that the data has been transformed on the IBM i back-end.

Final thoughts

It took just a few minutes to expose the IBM i business logic program as a reusable and easy-to-consume order entry API. We received the program name, library, and parameters as input for our task, created RAML schema and/or examples to match the request and response structures, and then defined the parameters in the IBM i (AS/400) connector.

Best of all, in most scenarios, there’s no need to develop or run any additional components on the IBM i server, and MuleSoft developers only need to obtain the program attributes and parameters.

You can find the complete code for this example here.

Of course, this is a demo application that should normally be hardened with exception handling, logging, etc. In some cases, the request or response structures are too complex to fit into program parameters and have to be passed to ERP business logic programs via DB2 staging tables. This blog article explains how IBM i Web Transaction Framework can simplify and streamline the API development for such use cases.

Connecting, modernizing, or migrating off of legacy systems is a complex undertaking. Based on my experience, failure rates in legacy ERP modernization and migration initiatives tend to be high. Anypoint Platform and IBM i (AS400) connector provide a comprehensive toolset for rapidly unlocking legacy business logic. The technology, along with a capable cross-functional delivery team, greatly improves the odds of project success and reduces the costs of large-scale legacy modernization and migration projects.

🌐