22
Fri, Nov
1 New Articles

ILE RPG Tutorial: Using CALLP to Call an ILE Program

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

Learn how to use a prototyped call, an alternative to an ILE RPG sub-procedure, to call one program from another

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

In some situations, when using an ILE sub-procedure in your program, you may 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.

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

H********************************************************

H* DWS0996 – Calling Program

H********************************************************

H DFTACTGRP(*NO) ACTGRP(*NEW)

H********************************************************

F* Display File

FDWS0170FM CF   E             WORKSTN PREFIX(D01_)

F********************************************************

D*

D DWS0997       PR                 EXTPGM('DWS0997')

D   D01_PRDNO           15

D   MSG                 60

D   ERROR_FLAG           1

D

D ERROR_FLAG     S       1

D MSG           S     60

D

D*

/FREE

     ERROR_FLAG = 'N';

     CALLP DWS0997(D01_PRDNO:MSG:ERROR_FLAG);

     *INLR = *ON;

 

/END-FREE

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

H********************************************************

H* DWS0996 – Calling Program  

H********************************************************

H DFTACTGRP(*NO) ACTGRP(*NEW)

H********************************************************

F* Display File

FDWS0170FM CF   E             WORKSTN PREFIX(D01_)

F********************************************************


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.

D*

D DWS0997       PR             EXTPGM('DWS0997')

D   D01_PRDNO           15

D   MSG                60

D   ERROR_FLAG           1

D

D ERROR_FLAG     S       1

D MSG           S     60

D

D********************************************************

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 chapter 7, 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.

/FREE

     ERROR_FLAG = 'N';

       CALLP DWS0997(D01_PRDNO:MSG:ERROR_FLAG);

       *INLR = *ON;

/END-FREE


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

H********************************************************

H* DWS0997 – Called Program

H********************************************************

H DFTACTGRP(*NO) ACTGRP(*CALLER)

H********************************************************

F* PRODUCT MASTER

FMSPMP100 IF   E       K DISK   PREFIX(PM_)

F********************************************************

D*

D DWS0997         PR

D   D01_PRDNO                 15

D   MSG                       60

D   ERROR_FLAG                 1

D DWS0997         PI

D   D01_PRDNO                 15

D   MSG                       60

D   ERROR_FLAG                 1

D********************************************************

/FREE

 

     ERROR_FLAG = 'N';

//READ PRODUCT MASTER USING PRODUCT NUMBER FROM

//SCREEN AS KEY.

     CHAIN(E) (D01_PRDNO) MSPMP100;

     IF NOT %FOUND;

         ERROR_FLAG = 'Y';

         MSG = 'THIS IS A BAD PRODUCT NUMBER +

                                       (XXX00111.01).';

     ENDIF;

 

     *INLR = *ON;

/END-FREE


Now, let’s take this baby apart.

H********************************************************

H* DWS0997 – Called Program

H********************************************************

H DFTACTGRP(*NO) ACTGRP(*CALLER)

H********************************************************

F* PRODUCT MASTER

FMSPMP100 IF   E           K DISK   PREFIX(PM_)

F********************************************************


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.

D*

D DWS0997           PR

D   D01_PRDNO                 15

D   MSG                       60

D   ERROR_FLAG                 1

D DWS0997           PI

D   D01_PRDNO                 15

D   MSG                       60

D   ERROR_FLAG                 1

D********************************************************


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

/FREE

 

     ERROR_FLAG = 'N';

     //READ PRODUCT MASTER USING PRODUCT NUMBER FROM

     //SCREEN AS KEY.

     CHAIN(E) (D01_PRDNO) MSPMP100;

     IF NOT %FOUND;

         ERROR_FLAG = 'Y';

         MSG = 'THIS IS A BAD PRODUCT NUMBER +

                                     (XXX00111.01).';

     ENDIF;

     *INLR = *ON;

 

/END-FREE


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.

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: