Adding Subprocedures to a Service Program
August 30, 2002 Timothy Prickett Morgan
Hey, Ted:
I’m still new to ILE, procedures, and service programs. I thought you could add procedures to the end of a service program, then recreate the service program and use it without recreating any existing program that has it bound in. Is this true, or am I off track?
|
— Tim
You need to learn and use binder language, Tim.
Here’s an example that I hope will help you get started.
Once there was an RPG programmer named Dan D. Koder. Dan decided to create a service program for frequently used math routines.
Here’s the source code:
H nomain /copy prototypes,math P OneMoreThan b export D pi 10i 0 D Number 10i 0 value C return Number + 1 P e
Notice that there’s only one routine–OneMoreThan.
Dan created a source member in which to store the procedure prototype:
D OneMoreThan pr 10i 0 D Number 10i 0 value
Dan used the following commands to create the service program:
CRTRPGMOD MODULE(OURLIB/MATH) + SRCFILE(OURLIB/SRC) SRCMBR(MATH) CRTSRVPGM SRVPGM(OURLIB/MATH) EXPORT(*ALL)
Notice EXPORT(*ALL) in the Create Service Program (CRTSRVPGM) command. This says that the service program is to have the same exports as those of the module. In this case, there is one export–a subprocedure named OneMoreThan.
With the service program ready for action, Dan wrote a program that used the OneMoreThan subprocedure. He named the program SNAZZYPGM. Here is part of the source code for that program:
/copy prototypes,math C exfmt fmt01 C dow not *in03 C eval num2 = OneMoreThan(num1)
Dan compiled SNAZZYPGM using the following commands:
CRTRPGMOD MODULE(OURLIB/SNAZZYPGM) SRCFILE(OURLIB/SRC) SRCMBR(SNAZZYPGM) CRTPGM PGM(OURLIB/SNAZZYPGM) BNDSRVPGM(MATH)
Everything was copasetic.
One day Dan decided to add a subprocedure called Twice to the math service program:
H nomain /copy prototypes,math P OneMoreThan b export D pi 10i 0 D Number 10i 0 value C return Number + 1 P e P Twice b export D pi 10i 0 D Number 10i 0 value C return Number * 2 P e
He also modified the prototype member:
D OneMoreThan pr 10i 0 D Number 10i 0 value D Twice pr 10i 0 D Number 10i 0 value
Dan recreated the service program using the same Create RPG Module (CRTRPGMOD) and Create Service Program (CRTSRVPGM) commands as before.
When a user ran the SNAZZYPGM program, everything was no longer copasetic. The user got escape message MCH4431 (Program signature violation) followed by CPF0001 (Error found on CALL command).
Here’s what caused the problem: The program SNAZZYPGM expected the MATH service program to have one export, but MATH had two!
Now, let’s look at how Dan should have handled this project.
Before creating the service program for the first time, Dan should have created another source physical file, called QSRVSRC. He should have added a member named MATH into it. He should have keyed the following into the member.
STRPGMEXP PGMLVL(*CURRENT) EXPORT SYMBOL('ONEMORETHAN') ENDPGMEXP
This is called binder language, which allows a programmer to tell the RPG compiler about the exports in the service program.
Dan should have created the service program this way:
CRTSRVPGM SRVPGM(OURLIB/MATH) + EXPORT(*SRCFILE) + SRCFILE(OURLIB/QSRVSRC)
Notice that EXPORT(*ALL) has been replaced by EXPORT(*SRCFILE) and the SRCFILE parameter has been filled in. This tells the compiler to use the binder language to resolve the exports.
Dan would have created SNAZZYPGM as before.
Later, when Dan added the Twice routine to the RPG source member, he should have revised the binder language like this example:
STRPGMEXP PGMLVL(*CURRENT) EXPORT SYMBOL('ONEMORETHAN') EXPORT SYMBOL('TWICE') ENDPGMEXP STRPGMEXP PGMLVL(*PRV) EXPORT SYMBOL('ONEMORETHAN') ENDPGMEXP
When the service program was recreated using this revised binder language, the service program would have two signatures–a current one with two exports and a previous one with only one export. SNAZZYPGM would have continued to run as always.
Dan learned his lesson. Later he added another subprocedure–OneThirdOf. He changed the binder language so that it had three signatures–a current signature with three exports and two previous signatures–and everything ran smoothly.
STRPGMEXP PGMLVL(*CURRENT) EXPORT SYMBOL('ONEMORETHAN') EXPORT SYMBOL('TWICE') EXPORT SYMBOL('ONETHIRDOF') ENDPGMEXP STRPGMEXP PGMLVL(*PRV) EXPORT SYMBOL('ONEMORETHAN') EXPORT SYMBOL('TWICE') ENDPGMEXP STRPGMEXP PGMLVL(*PRV) EXPORT SYMBOL('ONEMORETHAN') ENDPGMEXP
Here’s the moral of the story: Don’t EXPORT(*ALL) when creating a service program.
— Ted
Sponsored By WORTH CONSULTING |
Improve Legacy Programs with Super/Windows Summary: This newly released tool for the iSeries is used to improve user and programmer productivity and efficiency. Pop-up windows (or selection windows) are what users want to make their jobs easier and more accurate. They have been exposed to “list boxes” when on the Internet or when using a typical windows-based program. This feature makes it so that the user does not need those sticky notes and reference material at their grasp to know what value to key in entry fields. Programmers have been reluctant to put the selection window feature in entry programs because it takes substantial programming efforts to build the information and display it on the screen. It also requires major additions to the display files. Super/Windows easily enables pop-up selection windows to your application programs in an affordable manner. Very few changes are required to be made to your existing RPG, COBOL, and CL programs. Changes to your display files are not needed! Your existing code or table files are used to populate the information in the windows from which your users make selection. You can also use the codes file (and maintenance program) that is included with Super/Windows. One of Super/Windows’ functions generates the program source for each file ID using a simple entry program where the file and descriptive information is recorded. The source can be modified to return additional fields. You do not have to make wholesale changes to your application software, can optimize your staff’s existing skills, and little user training is needed. They will welcome Super/Windows with open arms! Business Owner Benefits:
Programmer Benefits:
User Benefits:
Click here to learn more about Super/Windows. |