25
Mon, Nov
1 New Articles

PRACTICAL ILE - ILE: Calling One Program from Another

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

Maybe you don’t want to just use a sub-procedure in your program. Maybe you actually want to write the sub-procedure up as a small program and then call it from another program. Granted, that is not technically a sub-procedure, but we will let that go for the moment and concentrate on the call of one program by another.

Editor's Note: This article is excerpted from article 8 of 21st Century RPG: /Free, ILE, and MVC, by David Shirey.

Back in the olden days, we would have used a CALL with a PARM list. But the regular, old CALL was not carried over into /Free. It wasn’t efficient enough. And so the new way to call from one program to another is via the CALLP, a prototyped call.

What is a prototyped call? Well, as we have already seen, it is a structured call where the parameters are defined in both the calling and the called program.

Fortunately, you have already had a look at the prototyping tools in the previous article: PRACTICAL ILE - ILE Subroutines to Sub-Procedures. They are the PR and PI D-specs.

OK, enough titillation. Let’s create a simple program that prototype calls another very simple program. Now there’s a top 10 skill for me. Simple stuff.

Calling Program: DWS0996

Obviously, we will need two programs to do this, so here’s the first one, the calling program, DWS0996. I am using the same basic program that I used for the previous article. I figure that way you at least have a feel for what I am doing. Here it is.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 1

See, pretty simple really. But let’s break it down anyway.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 2

We will start with the H- and F-specs. The H spec is needed to make sure this program gets compiled as ILE and that it is assigned to the activation group *NEW. If your compile command defaults to DFTACTGRP(*NO) instead of *YES, then you don’t have to bother with that parm, although as we will see later, you should set the activation group (otherwise it will default to QILE). You can use CALLP with OPM programs, so it won’t blow up if you don’t have that in there, but since this book is about ILE—sort of seems wrong not to go that direction. It’s the sub-procedures that have to be done in ILE. CALLP can be used in both ILE and OPM.

I then have only the display file, the theory being that I get my product number from that file. I know I don’t have logic in the program to read that file, but that just seemed like a distraction from what we are really doing.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 3

That brings up the D-specs. We have the prototype D-spec (the PR), but this time there is an additional parameter there, a keyword EXTPGM('DWS0997'), representing the program we are going to call.

Some people like to call the D-spec something other than the program name, like VAL_PRDNO or something like that. Something more English language-oriented that can easily be identified. And that is fine. It is not a sign of psychosis or anything bad. I just like using the program ID. Not very creative, I guess.

What is important is that the actual name of the program you want to call is in the EXTPGM  keyword. If you fail to put in the EXTPGM keyword, the compile will fail in the binding stage. If you put in the EXTPGM keyword but use a value in it that is not a valid object, then the compile and bind will work, but the job will fail when you run it.

Then we define the ERROR_FLAG and the MSG since things aren’t really defined in the PR. We saw this in the previous article, but it is worth remembering. And, as it always has, D01_PRDNO is in the DWS0170FM and so does not need to be defined separately.

Also, please note that the calling program has a PR spec but no PI spec.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 4

Then, finally, there are the actual code statements. Note that the CALLP statement is the same as the one that we used for the call to the sub-procedure in the previous article except that I am using the program ID now rather than VAL_PRDNO. You can do it either way, but the name of the D-spec is the one that must appear in the CALLP. So you can’t really do it either way. What I meant is you have to use the name of the PR D-spec, but that name could be either DWS0997 or VAL_PRDNO. Please note there are no quote marks in this CALLP statement.

The Called Program: DWS0997

And now, the program you are calling, the program that represents the sub-procedure logic. Hang onto your hats, folks.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 5

Now, let’s take this baby apart.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 6

No surprises here. I included an H-spec to make sure (in my outdated environment) that I end up with an ILE program. And F-specs to define the Product Master that will be used for the validation. I don’t need the display file because that is in my calling program, and the value I entered there will be passed in via the prototype specs.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 7

Now the D-specs look a little different. For one thing, there are two of them. We start with the PR, the prototype spec, just like we had in the calling program.

To that we now add the PI, the procedure interface, which we had used in the sub-procedure D-specs in the previous article. The name for both of these D-specs must match—each other, you know. As must the subfields that are being specified. Otherwise you will get a compile error.

I haven’t included the SP_PRDNO—there’s no need. Since we are not using sub-procedures here, and so there is no need to show off local variables. I will just use D01_PRDNO from the display file.

There is one more thing here. Where are the definitions for the D01_PRDNO, MSG, and ERROR_FLAG field? And the answer is, even though the PR doesn’t really define a variable, the PI does. I don’t know the reason for that. Never asked, don’t really care. It makes no sense that one does and one doesn’t, but if I insisted that everything make sense, I would still be waiting.

PRACTICAL ILE - ILE: Calling One Program from Another - Figure 8

And finally, the logic statements. They are identical to what we used in the sub-procedure except that I am just using the D01_PRDNO field and not bothering with the SP_PRDNO local variable.

PRACTICAL ILE - ILE: Calling One Program from Another - Now It's Your Turn

What Ya Shoulda Learned

Basically, a lot of the same stuff that you should have learned in the last article. In fact, both program sets are almost identical, aren’t they?

So which one is better?

Using the sub-procedure or the separate program, I mean? And the answer, like most things is: it depends.

Certainly the sub-procedure is more efficient, although with the new CALLP they are both pretty quick. If you get hung up worrying about which is faster, then you really need to switch to decaf.

Obviously, there are advantages to putting the validation logic in a separate program so it can be more easily used in other situations. Although, as we will see in the next article, we can make a sub-procedure available to multiple programs without using a separate program call.

Also, please note that I assume you did this by compiling both programs with CRTBNDRPG. But you could have also used CRTRPGMOD on both of them and then CRTPGM to bind them together. We will talk more about the differences in these two approaches later. For now, let’s keep things simple, shall we?

Before we can decide which is best, there is one more option.

Yes, you guessed it. A dark and dangerous option. An option that is spoken of only in whispers where the ragged IT people go. An option so terrifying and powerful that few mere mortals have attempted to capture and tame it.

Service Programs.

Want to learn more?  You can pick up Dave Shirey's book, 21st Century RPG: /Free, ILE, and MVC, at the MC Press Bookstore Today!

David Shirey

David Shirey is president of Shirey Consulting Services, providing technical and business consulting services for the IBM i world. Among the services provided are IBM i technical support, including application design and programming services, ERP installation and support, and EDI setup and maintenance. With experience in a wide range of industries (food and beverage to electronics to hard manufacturing to drugs--the legal kind--to medical devices to fulfillment houses) and a wide range of business sizes served (from very large, like Fresh Express, to much smaller, like Labconco), SCS has the knowledge and experience to assist with your technical or business issues. You may contact Dave by email at This email address is being protected from spambots. You need JavaScript enabled to view it. or by phone at (616) 304-2466.


MC Press books written by David Shirey available now on the MC Press Bookstore.

21st Century RPG: /Free, ILE, and MVC 21st Century RPG: /Free, ILE, and MVC
Boost your productivity, modernize your applications, and upgrade your skills with these powerful coding methods.
List Price $69.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

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: