RPG Academy: UI Modernization, Part 5 - From ILE to MVC, Explained

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

MVC is a conceptual model, so it can be hard to understand and apply to your code. Let’s explore an example to help you grasp the concept a little better.

In the previous TechTip, I explained each of the MVC layers. I understand if you still have questions—lots of questions—on how to apply it to your code. I’ll try to help with that by presenting an example based on a previously explained fictional program. Now let’s see how that can be applied to an ILE program.

Reengineering an ILE Program Using the MVC Design Pattern

Take a moment to review Figure 1. It’s a simple example of a fictional order-maintenance ILE program, shown a few TechTips ago.

RPG Academy: UI Modernization, Part 5 - From ILE to MVC, Explained - Figure 1

Figure 1: This fictional order-maintenance ILE program was introduced in a previous article.

Just to remind you, let’s go over the several pieces depicted here. You’ll notice that service programs INVDA, ORDDA, and CLIDA are connected to the data access tier of the program. These service programs would provide data access functions, in the form of RPG or SQL I/O Servers, designed to read and write records to the database.

Service programs INVBL, ORDBL, and CLIBL would supply higher-level procedures and functions like Rtv_Item_Description, Rtv_Order_Delivery_Date, Wrt_Order_Record, Upd_Order_Record, Rtv_Client_Name, Upd_Item_Qty, Clc_Delivery_Fee, Clc_Earliest_Delivery_Date, and Chk_Client_Debt, just to name a few. There are many more procedures and functions involved. I didn’t include the utility (to send the order confirmation by email or fax, for instance) and general calculation service programs (such as date operations needed to calculate the actual delivery date assuming it cannot be on a weekend, for example). I also omitted the modules linked to each of the service programs depicted, to try to keep things simple. Only the ORDMNT module was depicted to remind you that the ILE program doesn’t contain code; only the respective entry module (ORDMNT, in this case) does. Program ORDMNT’s binding directory would contain an entry for each of the service programs used. Otherwise, the compiler wouldn’t be able to resolve all of the imports of module ORDMNT.

Let’s take the multi-tier architecture implementation example shown in Figure 1 and apply the MVC design pattern to it. Let’s see what fits where:

  • The model layer—The business logic service programs provide the program with its “brains,” because they contain the procedures used to get the raw data from the database and transform it into useful information. For instance, the Rtv_Order_Delivery_Date procedure uses the I/O Servers provided by the ORDDA service program to check whether the order number it receives as a parameter is valid and then retrieves the respective delivery date. This means that the data access service programs are also part of the model, because they include both the data and the means to retrieve it.
  • The controller layer—The ORDMNT module represents the controller. It will be reacting to user actions (options and function keys), translating that input into calls to the procedures that are part of the model. Imagine, for instance, that there’s an option to show client-related data. When the user chooses that option in the respective display file (omitted for simplicity sake), the controller (ORDMNT) calls procedure Rtv_Client, which in turn uses an I/O Server to read client raw data and pass it back to the controller.
  • The view layer—The omitted display file and the part of the ORDMNT that handles the screen constitute the view, because they’ll receive data from the controller and display it in a new screen or a subfile, for instance. Continuing with the client-related data example, the view part of ORDMNT would present the retrieved data to the user on a new screen.

This is not a perfect example because of the overlap between the controller and view layers in the ORDMNT module. However, if you’re interested in modernizing the UI, you’ll want a graphical user interface, not a green-screen. How, you might ask? Well, there are a few options in the market, some more simple than others, but IBM’s Rational Open Access, formerly known as RPG Open Access is, in my opinion, the most versatile. In the next TechTip, we’ll look at it in more detail, explaining what it is (and what it isn’t) and how can you use it (just to give you a preview, there are two ways to do it—the easy and the hard). Until then, leave your comments, questions, and suggestions in the Comments section below or in the LinkedIn forums where my articles usually pop up.

Stay safe!

Rafael Victoria-Pereira

Rafael Victória-Pereira has more than 20 years of IBM i experience as a programmer, analyst, and manager. Over that period, he has been an active voice in the IBM i community, encouraging and helping programmers transition to ILE and free-format RPG. Rafael has written more than 100 technical articles about topics ranging from interfaces (the topic for his first book, Flexible Input, Dazzling Output with IBM i) to modern RPG and SQL in his popular RPG Academy and SQL 101 series on mcpressonline.com and in his books Evolve Your RPG Coding and SQL for IBM i: A Database Modernization Guide. Rafael writes in an easy-to-read, practical style that is highly popular with his audience of IBM technology professionals.

Rafael is the Deputy IT Director - Infrastructures and Services at the Luis Simões Group in Portugal. His areas of expertise include programming in the IBM i native languages (RPG, CL, and DB2 SQL) and in "modern" programming languages, such as Java, C#, and Python, as well as project management and consultancy.


MC Press books written by Rafael Victória-Pereira available now on the MC Press Bookstore.

Evolve Your RPG Coding: Move from OPM to ILE...and Beyond Evolve Your RPG Coding: Move from OPM to ILE...and Beyond
Transition to modern RPG programming with this step-by-step guide through ILE and free-format RPG, SQL, and modernization techniques.
List Price $79.95

Now On Sale

Flexible Input, Dazzling Output with IBM i Flexible Input, Dazzling Output with IBM i
Uncover easier, more flexible ways to get data into your system, plus some methods for exporting and presenting the vital business data it contains.
List Price $79.95

Now On Sale

SQL for IBM i: A Database Modernization Guide SQL for IBM i: A Database Modernization Guide
Learn how to use SQL’s capabilities to modernize and enhance your IBM i database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: