This blog post is contributed by one of our partners, Infoview Systems.

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 the 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 program 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 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 fulfillment flows. The purpose of this task is to expose that 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. We start with building RAML definition for the API, matching the parameter structure:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

#%RAML 0.8

title:IBMiProgram 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

}

]

}

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 (AS400) connector to post:/orders:apiConfig flow, set the connection parameters and test the 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 input 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:

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:

1

2

3

4

5

6

%dw1.0

%outputapplication/java

---

payload

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:

The RPG program I am using for this demo, intentionally updates the values of the order ID and line item details, adding 100 to order ID, concatenates item numbers using “out” and adds 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 an 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 (AS400) 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.

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.

We'd love to hear your opinion on this post

One Response to “How to Build an IBM i (AS400) API in 15 Minutes”

We have a large table with millions of rows. I am building a Mule service that takes those records, creates a CSV file, and uploads it to an FTP. My question is, does this connector allow record-by-record streaming, so that the entire dataset is not put in memory?

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

MuleSoft provides the most widely used integration platform for connecting any application, data source or API, whether in the cloud or on-premises. With Anypoint Platform®, MuleSoft delivers a complete integration experience built on proven open source technology, eliminating the pain and cost of point-to-point integration. Anypoint Platform includes CloudHub™ iPaaS, Mule ESB™, and a unified solution for API management™, design and publishing.