Академический Документы
Профессиональный Документы
Культура Документы
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
H nomain
/copy prototypes,math
P OneMoreThan b export
D pi 10i 0
D Number 10i 0 value
C return Number + 1
P e
D OneMoreThan pr 10i 0
D Number 10i 0 value
CRTRPGMOD MODULE(OURLIB/MATH) +
SRCFILE(OURLIB/SRC) SRCMBR(MATH)
CRTSRVPGM SRVPGM(OURLIB/MATH) EXPORT(*ALL)
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)
CRTRPGMOD MODULE(OURLIB/SNAZZYPGM)
SRCFILE(OURLIB/SRC)
SRCMBR(SNAZZYPGM)
CRTPGM PGM(OURLIB/SNAZZYPGM) BNDSRVPGM(MATH)
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
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.
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.
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.
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