29
Fri, Nov
0 New Articles

Practical ILE: Building Your Service Program Library, Part 2

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

 

The second step in service programs is telling the world about your procedures, and that's done through prototypes.

 

In our previous article, we began to explore how to build a library of service programs. We reviewed some procedures that you might find in a service program and explained how they were related and why they were built that way. Now we need to use those procedures, and the first step to doing that is to let the rest of your applications know the procedures exist. This is done through prototypes. As your library grows, so will your list of prototypes. This article presents a programming infrastructure you can use to manage that growth.

First, the Prototypes

The initial article outlined a service program with three procedures: CredCalcDates, CredGetProx, and DateSetDay. I presented those procedures in a sort of shorthand, with just the procedure names and some representative names of parameters. Here's the list:

 

CredCalcDates( currentDate: netDays: discDays: proxDay: dueDate: discDate);

CredGetProx( currentDate: proxDay);

DateSetDay( currentDate: dayNumber);

 

While that provides a rough outline of the procedures, it doesn't provide a lot of meaningful information about the procedures. Now it's time to see the real prototypes in detail. Let's first use the traditional prototype definition. Let me show you the prototype for DateSetDay.

 

     **

     * Compute date by setting the day of the month to a specific value

     **

     d DateSetDay   pr              d

     d iDate                      d const

     d iDayOfMonth              3u 0 const

 

If you work your way through the D-specs, you'll see that DateSetDay takes two parameters: the date and the day of the month. It returns the new date. The code is concise, but in fixed-format RPG that conciseness is sometimes overdone to the point of incomprehensibility. As an alternative, I'd like to show you what the free-form version of this prototype looks like:

     //

     // Compute date by setting the day of the month to a specific value

      //

      dcl-pr DateSetDay date;

       iDate date;

       iDayOfMonth uns(3);

      end-pr;

 

The more I use free-form RPG, the more I like it. Some of it is still a little obscure. The keywords dcl-pr and end-pr don't exactly jump off the page with intuitive understanding. Other than that, though, I think the coding for the prototype is pretty straightforward. (Okay, the definition of binary numbers in RPG is and will always be a little arcane, but it's not egregiously difficult and at least you don't have to senselessly specify zero decimal positions.) It takes a little getting used to, but I find that once I've gotten into the free-form rhythm, I can just keep coding. I can even do green-screen programming faster. The other day I put together a quick test program to exercise some new calculations, and it took almost no time. I popped into the Screen Designer in RDi (Rational Developer for i) and threw together a quick screen, and then I just banged out the code. The workstation file was defined just this quickly: "dcl-f MYDSPLY workstn;". I coded a quick exfmt loop that called the procedure with fields from the display, and I was done with the program.

Now, the Copybooks

Okay, we've seen that it's pretty easy to create the prototypes. Now we have to get those prototypes to our calling applications. By far the most appropriate way to do this is through the use of a /COPY statement. Most RPG programmers have used these during their careers, and the concept is called by several different terms: includes, copybooks, and copy members are just a few of the terms. Even my favorite term, copybook, has variants: it can be either one or two words. For consistency within these articles, I'll stick with the term copybook.

 

Generally speaking, you code the prototypes into a source member (the copybook) and then include that member in your application program using the /COPY statement. This is a pretty simple technique, but it does require that you know the name of the copybook. If you have only one copybook, that's pretty simple, but as your environment expands, you'll find that you use more and more of them. You may also be using external copybooks, either from IBM or from other sources. And then one day the unthinkable happens: you have to rearrange your copybooks!

 

Let me give you a simple example. Let's say the above service program eventually grew to where there were a whole bunch of credit procedures. At the same time, you built a very comprehensive set of date-processing functions. At some point, it will probably make sense to split the DateSetDay procedure off of the Credit service program and move it to a separate date-handling service program (that utility service program may do more than dates, of course, but that will depend on your environment). In so doing, you realize that your old naming convention isn't going to cut it anymore. You had just one service program, CREDIT, and one set of prototypes in CREDPROTO. Here's the line of code in your program that includes the prototypes:

 

     /COPY QCPYLESRC,UTLDATPR

 

You sense that your service programs are going to multiply, and you're going to have to try to keep them straight with a solid naming convention. You quickly realize that you can drop back to your traditional IBM i technique of using three-letter abbreviations. So you come up with a naming convention: xxxyyySVC and xxxyyyPR, where xxx is the service program type and yyy is the actual application. Application logic goes into the type APP, while utilities go into UTL. SVC is the service program, PR is the copybook. And so you get APPCRDSVC, APPCRDPR, UTLDATSVC, and UTLDATPR. It all makes perfect sense, except that now you have to go into every program that uses the services and change the /COPY statements.

Nested Copybooks to the Rescue!

What we do instead is to create a copybook named COPYCOMMON that allows you to include all the other copybooks with simple /DEFINE statements. COPYCOMMON has code that looks like this:

 

     * Date handling

     /IF DEFINED(Copy_Dates)

     /COPY QCPYLESRC,UTLDATPR

     /ENDIF

 

     * Credit processing

   /IF DEFINED(Copy_Credit)

     /COPY QCPYLESRC,APPCRDPR

     /ENDIF

 

You can then include the credit routines with two simple statements in your program:

 

     /DEFINE Copy_Credit

     /COPY QCPYLESRC,COPYCOMMON

 

Now if you need to change the name of the credit prototypes, you need to change only one place. Note that you don't need to include the date-processing routines in your program; they're invoked by the Credit routines. But you could include them by simply adding a second /DEFINE that defines Copy_Dates. This technique allows you to copy all sorts of things, including standard includes that you might be familiar with:

 

     * CGIDEV2

     /IF DEFINED(Copy_CGIDEV2)

     /COPY CGIDEV2/QRPGLESRC,PROTOTYPEB

     /COPY CGIDEV2/QRPGLESRC,USEC

     /ENDIF

 

A quick and easy way to include both CGIDEV2 copybooks! This technique has a lot of potential, especially when you need common defines across multiple applications. And it gets us almost all the way through to using service programs. The last thing we need to do is bind them into our program, and we'll see that next. Until then, have fun with copybooks!

 

Joe Pluta

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc. He has been extending the IBM midrange since the days of the IBM System/3. Joe uses WebSphere extensively, especially as the base for PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has written several books, including Developing Web 2.0 Applications with EGL for IBM i, E-Deployment: The Fastest Path to the Web, Eclipse: Step by Step, and WDSC: Step by Step. Joe performs onsite mentoring and speaks at user groups around the country. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Joe Pluta available now on the MC Press Bookstore.

Developing Web 2.0 Applications with EGL for IBM i Developing Web 2.0 Applications with EGL for IBM i
Joe Pluta introduces you to EGL Rich UI and IBM’s Rational Developer for the IBM i platform.
List Price $39.95

Now On Sale

WDSC: Step by Step WDSC: Step by Step
Discover incredibly powerful WDSC with this easy-to-understand yet thorough introduction.
List Price $74.95

Now On Sale

Eclipse: Step by Step Eclipse: Step by Step
Quickly get up to speed and productivity using Eclipse.
List Price $59.00

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: