Вы находитесь на странице: 1из 4

Adding Subprocedures to a Service Program

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

Вам также может понравиться