23
Tue, Apr
0 New Articles

Get a Grip on ILE Binding, Part 2

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

Getting a grip on ILE binding requires you to properly manage the exports and signatures of service programs. Implementing export and signature controls though binder language makes applications flexible, modular, dependable, easier to enhance and modify, and less prone to costly production errors.

A service program is a collection of ILE procedures that can be statically called from ILE programs or other service programs. Service programs are bound to their callers by reference during the ILE program creation process.

Binder language is a special language that allows the programmer to control how service programs bind to their callers. Binder language gives a programmer a way to list a service program’s exports, the procedures and data to which calling procedures have direct access. Listing exports through binder language means that calling programs can continue to use a service program, even after that service program has been modified.

The Importance of Signatures

When a service program is compiled, OS/400 generates a special 16-byte signature from the exportable procedures and data items of the service program. This is similar in concept to the level identifiers that OS/400 generates for record formats when files are created. OS/400 uses signatures to ensure that the programs that call the service program use a compatible program-calling interface. If the program-calling interface is not compatible, a program signature violation error will occur. You can use binder language to avoid such conflicts.

When you compile an ILE service program, you have two ways to specify exports. If you specify EXPORT(*ALL) in the Create Service Program (CRTSRVPGM) command, the system generates a signature from all the exported variables and subprocedures. If programs or other service programs are already using the service program, and the list of exports has changed since those callers were compiled, you’ll have to recompile all the callers in order to avoid signature violations (level checks). Recompiling programs is not productive; binder language lets you eliminate the need to do so.

Binder language gives you a way to list the procedures and data items you want to export. You can also specify what service program signature you wish to have when you create the service program.

To avoid the need to recompile callers when a service program’s list of exports changes, specify EXPORT(*SRCMBR) on the CRTSRVPGM command. This means that you have entered binder language statements into a source member. CRTSRVPGM will use this source member when creating the ILE service program.

You can specify more than one list of exports in a binder language source member. Each list will generate a different signature.

You can use the Display Service Program (DSPSRVPGM) command to view the exports and signatures of a service program. This signature will be displayed in hexadecimal format.

Example ILE Payroll Application

To illustrate how to take charge of binding, consider an RPG IV service program designed for a payroll application. Initially, it calculates federal taxes and net pay for one employee. Later, I will add procedures to compute the state and social security taxes. The purpose of this approach is to show how to avoid program interface errors when adding new exported procedures to an existing service program.

The service program I’ll use is named CalcTaxes (see Figure 1). It copies one source member that contains procedure prototypes (Figure 2), and then it exports two items—subprocedures CalcFedTax and CalcNetPay.

Binder language is stored in member CALCTAXBL, shown in Figure 3. Notice that the syntax is similar to CL. Each line begins with a command and is followed by parameters in keyword format. The Start Program Export (STRPGMEXP) and End Program Export (ENDPGMEXP) binder statements start and end the export declarations. The PGMLVL(*CURRENT) parameter of the STRPGMEXP statement stipulates that this export list generates the current service program signature. The LVLCHK(*YES) parameter specifies that the signature should be verified at runtime, when the service program is called. The EXPORT statements indicate what procedures are to be exported.

First, create a module from the CALCTAXES member. Then create the service program using the binder language source. The commands needed to complete these steps are shown in Figure 4. Notice the SRCMBR parameter on the CRTSRVPGM command. It tells the compiler where to find the binder language source code.

When the service program is created, it can be bound by reference to a calling program. Binding by reference, as opposed to by copy, saves disk space. Also, more than one calling program can use this service program [see “Get a Grip on ILE Binding, Part 1,” MC, October 1998].

In order to demonstrate how to use the CalcTaxes service program, I wrote a calling program named CalcTaxesPrn. Because of space limitations, we cannot publish the entire code in this article. However, all of the code for this article, including CalcTaxesPrn, is available free from the Midrange Computing Web site at http://www.midrangecomputing.com/mc/98/11.

The code snippet used by CalcTaxesPrn is displayed in Figure 5. Notice the use of the EVAL and CALLP commands. These are the commands that access the procedures in the CalcTaxes service program [see “RPG IV Subprocedures,” MC, August 1996].

Enhancing the Service Program Assume the CalcTax service program has been in production for a while and is being called by various programs. Now you’re told to add some procedures that will calculate state and social security taxes to the CalcTaxes service program. To do so, you must modify three source code members:

• CalcTaxes (the service program)
• CalcTaxesPr (subprocedure prototypes)
• CalcTaxesBL (binder language)

You can see the revised service program and prototype source in Figures 6 and 7, respectively. The revised binder language, shown in Figure 8, updates the service program export list to include the new procedures. The previous version of the export list is supported by the PGMLVL(*PRV) keyword in the second STRPGMEXP statement. This ensures backward compatibility with the previous versions of the service program. That is, callers who expect to find the old version of the CalcTaxes service program will be able to use the CalcFedTax and CalcNetPay subprocedures in the new version of the service program.

Design Your Own Signature

If you wish, you can specify a service program signature of your choosing by using the SIGNATURE keyword of the STRPGMEXP statement, as in Figure 9. You might want to do this to further control which programs can access your service programs.

Speaking in Binder Language Will Make Your Applications Better

Learning to use binder language is not difficult; it doesn’t take much time or effort, and the application results are definitely worth it. Service programs are important in ILE application development. The better your service programs are implemented, the stronger your applications will be.

References

AS/400 ILE Concepts V4R2 (SC41-4606, CD-ROM QB3AQ701) ILE Application Development Example V4R2 (SC41-5602, CD-ROM QB3AQ400) ILE RPG for AS/400 Programmer’s Guide V4R2 (SC09-2507, CD-ROM QB3AGY00)

Moving to ILE RPG V4R2 (GG24-4358)

Figure 1: CalcTaxes service program, version 1

* Source member - CalcTaxes
H NOMAIN

/copy qrpglesrc,calcpr

P CalcFedTax B EXPORT
D PI 6 2
D WageAmt 4s 0 VALUE
D FedPercent 2s 2 VALUE
C return WageAmt * FedPercent
P CalcFedTax E

P CalcNetPay B EXPORT
D PI
D NetPay 6 2
D WageAmt 4s 0
D FedTax 6 2
D StTax 6 2
D FICATax 6 2
C eval NetPay = WageAmtC FedTaxC StTaxC FICATax
P CalcNetPay E

* Source member - clacpr
D CalcFedTax PR 6 2
D 4s 0 VALUE
D 2s 2 VALUE
D CalcNetPay PR
D 6 2
D 4s 0
D 6 2
D 6 2
D 6 2 STRPGMEXP PGMLVL(*CURRENT) LVLCHK(*YES)
EXPORT SYMBOL(CalcFedTax)
EXPORT SYMBOL(CalcNetPay)

ENDPGMEXP CRTRPGMOD MODULE(XXX/CALCTAXES)
CRTSRVPGM SRVPGM(XXX/CALCTAXES) +

MODULE(XXX/CALCTAXES) SRCMBR(CALCTAXBL) *----------------Declare standalone variablesD EmployeeName S 20a

D WageAmt S 4s 0

D FedPercent S 2s 2

D StPercent S 2s 2

D FICAPercent S 2s 2

D TotPayAmt S 6 2

D StTaxAmt S 6 2

D FedTaxAmt S 6 2

D FICATaxAmt S 6 2

D NetPayAmt S 6 2

* Issue static procedure calls with the eval command

*

C eval FedTaxAmt = CalcFedTax(WageAmt:

C FedPercent)

*

* Issue static procedure calls with the callp command

C callp CalcNetPay(NetPayAmt:

C WageAmt:

C FedTaxAmt:

C FICATaxAMT:

C STTaxAmt)

Figure 2: Subprocedure prototypes, version 1 Figure 3: Binder language, version 1 Figure 4: Compiling a service program with binder language Figure 5: Code snippets for CalcTaxesPrn driver module

* Source member CalcTaxes Version 2
H NOMAIN

/copy qrpglesrc,calcpr
/copy qrpglesrc,calcpr2

P CalcFedTax B EXPORT
D PI 6 2
D WageAmt 4s 0 VALUE
D FedPercent 2s 2 VALUE
C return WageAmt * FedPercent
P CalcFedTax E

P CalcNetPay B EXPORT
D PI
D NetPay 6 2
D WageAmt 4s 0
D FedTax 6 2
D StTax 6 2
D FICATax 6 2
C eval NetPay = WageAmtC FedTaxC StTaxC FICATax
P CalcNetPay E

P CalcStTax B EXPORT
D PI 6 2
D WageAmt 4s 0 VALUE
D STPercent 2s 2 VALUE
C return WageAmt * STPercent
P CalcStTax E

P CalcFICATax B EXPORT
D PI 6 2
D WageAmt 4s 0 VALUE
D FICAPercent 2s 2 VALUE
C return WageAmt * FICAPercent
P CalcFICATax E * Source member calcpr2
D CalcStTax PR 6 2
D 4s 0 VALUE
D 2s 2 VALUE
D CalcFICATax PR 6 2
D 4s 0 VALUE
D 2s 2 VALUE STRPGMEXP PGMLVL(*CURRENT) LVLCHK(*YES)
EXPORT SYMBOL(CalcFedTax)
EXPORT SYMBOL(CalcNetPay)
EXPORT SYMBOL(CalcStTax)
EXPORT SYMBOL(CalcFICATax)
ENDPGMEXP
STRPGMEXP PGMLVL(*PRV)
EXPORT SYMBOL(CalcFedTax)
EXPORT SYMBOL(CalcNetPay)

ENDPGMEXP

Figure 6: CalcTaxes service program, version 2 Figure 7: Subprocedure prototypes, version 2

Figure 8: Binder language, version 2 Figure 9: Specifying a signature of choice

STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('CALCTAXPR2')

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: