23
Tue, Apr
1 New Articles

Extending IBM i RPG Assets with ASNA Visual RPG

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

Reusing IBM i program objects with Call/Parm has been in RPG programmer kit bags for years. This article shows how to call IBM i program objects from Windows.

 

All IBM i shops have legacy RPG applications. These applications are typically built out of hundreds, sometimes thousands, of RPG programs. It's not uncommon for many of those RPG programs to be reusable program objects that are called by many other RPG programs in the application.

 

Extending the life and value of reusable RPG program projects is something that ASNA Visual RPG (AVR) is very good at. You can build a fat Windows client, or an ASP.NET website, with ASNA Visual RPG and then easily reuse your existing RPG program object portfolio in these apps. Although this article shows AVR calling an ILE RPG–generated program object, AVR can call an IBM program object generated from any language.

 

This product review shows you how simple it is to use AVR to reuse your existing IBM i program objects.

 

Calling IBM i Program Objects

AVR supports calling IBM i program objects with the familiar RPG Call/Parm programming interface. Like RPG on the IBM i, AVR's program call obeys the pass-by-reference semantics for program call parameters. When the IBM i program object changes a parameter value, that change is recognized in AVR after the call.

 

In addition to the typical scalar parameter types (packed, zoned, char, etc.), AVR can also pass data structures and multiple-occurrence data structures with its program call. Let's take a look at an example.

 

Figure 1a below is the ILE RPG program we'll call with AVR. It's written using IBM i's TR7 free-format syntax. Almost. I couldn't for the life of me get a PList to work with TR7 ILE RPG, so I had to jam in two fixed-format lines. If you can TR7-ize lines 8 and 9 for me, I'll buy you a cold one!

 

This program populates an externally defined data structure array with two fields from a file. That data structure is the single parameter for the program call.

 

0001 Ctl-Opt Option(*srcstmt) Dftactgrp(*No) ActGrp('rptest');

0002

0003 Dcl-F CustomerL2 Disk(*ext) Usage(*Input) Keyed;

0004

0005 Dcl-DS CustDS LikeRec(RCMMASTER:*Key) Dim(200);

0006

0007 /end-free

0008 c     *entry       plist

0009 c                   parm                    CustDS

0010 /free

0011

0012 LoadCustDS();

0013

0014 *InLR = *On;

0015 Return;

0016

0017 Dcl-Proc LoadCustDS;

0018     Dcl-S RowCount Packed(12:0);

0019

0020     RowCount = 0;

0021

0022     DoW (RowCount < 16);

0023         RowCount = RowCount + 1;

0024         Read CustomerL2;

0025         CustDS(RowCount).CMCustNo = CMCustNo;

0026         CustDS(RowCount).CMName = CMName;

0027     EndDo;

0028 End-Proc;

Figure 1a: ILE RPG program to be called by AVR

 

The ASNA Visual RPG code to call Figure 1a's ILE RPG program is shown below. A small code narrative follows this code listing.

 

0001 DclDB pgmDB DBName("DevIBMi")

0002

0003 DclDs CustDS Dim(200)  

0004 DclDsFld CMName   Type(*Char) Len(40)

0005 DclDsFld CMCustNo Type(*Packed) Len(9,0)

0006

0007 BegFunc ProgramCallWithDS Access(*Public) Type(*Integer4)

0008     DclFld Counter Type(*Integer4)

0009

0010     Call "*Libl/PgmCall" DB(pgmDB)

0011     DclParm CustDS

0012

0013     Do FromVal(1) ToVal(200) Index(Counter)

0014         Occur CustDS NewIndex(Counter)

0015

0016         If (CMCustNo = 0)

0017             Leave

0018         EndIf        

0019     EndDo

0020

0021     LeaveSr Counter - 1

0022 EndFunc

Figure 1b: AVR snippet to call Figure 1a's ILE RPG program object

 

Line 1:

AVR's database access and program calls are provided by ASNA's DataGate. DataGate is a TCP/IP-based IBM i host server that connects a Windows PC or server to an IBM i. DataGate is secure, performant, and very easy to configure.

 

AVR provides a superset of RPG operation codes. Its DclDB operation code defines the active database name for this program. In AVR parlance, a database name identifies a centrally located set of database connection properties (e.g., IBM i IP address, user profile name, IBM i password, connection pool time, etc). This database name provides AVR with the information it needs to pass along to DataGate to perform file IO and program calls.

 

Lines 3-5:

These three lines define a data structure array. These lines provide a data structure identical to the one defined in Figure 1a's line 5. TR7 ILE RPG added the handy *KEY keyword, which causes an external data structure to include only the key fields AVR's structure needs to explicitly define.

 

Line 7:

AVR supports both subroutines and functions. Variables defined in these routines are local to the routine. AVR's subroutines and functions can also have parameters passed to them. They are essentially AVR's streamlined answer to ILE RPG's subprocedures.

 

Line 8:

Declare a local variable counter to track how many elements are written to the data structure array.

 

Lines 10-11:

These two lines perform the program call to the IBM i. The DB keyword identifies the IBM i (through its database name) to which this program call is occurring. You can fully qualify the program object being called or use, as this example shows, the *Libl library list keyword.

 

Lines 13-19:

The ILE RPG program called arbitrarily defined 200 elements in its data structure array (line 5 of Figure 1a). Lines 13-19 loop over the data structure array elements passed to AVR from the IBM i to count them.

 

Line 21:

AVR's arrays are zero-based (i.e., the first element in an AVR array is the "zeroth" element). To return the number of elements populated by the RPG program, the counter value minus 1 is returned.

 

To benchmark this program call, I modified both programs slightly to conditionally end the RPG program call. When calling the open RPG program, call times averaged about 140 milliseconds per call.

 

Extending IBM i RPG Assets

As you can see, it's very easy to make program calls to IBM i program objects from ASNA Visual RPG. These calls work from fat Windows AVR programs, AVR-powered websites, or Web services. In any use case, AVR's program calls are one of the big ways that AVR can let you extend the life and value of your IBM i RPG assets. AVR gives those old program objects a lease on life.

 

The full code for this example, including the ILE RPG program, are online at ASNA's GitHub account.

 

A Parting Shot

I've seen articles recently bemoaning the slow take-up of TR7's vastly improved free-format syntax. Given the sorry state of TR7-specific free-format docs, it's no wonder no one is using it. You quite nearly need to have Kreskin on your programming team to fully exploit this great new syntax. Both Jon Paris and Susan Ganter's IBM Systems magazine blog and the occasional Barbara Morris PowerPoint are better help than anything you'll find in the IBM i white books. Also take a look at this simple TR7 ILE RPG example.

 

I'm nearly certain that the back of a cereal box would be more helpful than any of IBM i's RPG documentation! Isn't it amazing how some things never change? My documentation beef aside, IBM i's TR7 ILE RPG makeover is very highly recommended. It is expressive and mostly predictable, and it vastly smoothes out the syntactic thorns that have dogged ILE RPG since the mid '90s.

ROGER PENCE

Roger Pence is ASNA's Product Evangelist. Roger has been in the IBM i midrange community for so long that Elvis was alive when he started. He has been with ASNA since 2000. Prior to joining ASNA, Roger was a technical editor for NEWS/400 and the author of the 400/Group's AS/400 and Windows newsletter.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • 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.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • 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

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • 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: