Service Program1

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Service Program1 as PDF for free.

More details

  • Words: 692
  • Pages: 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 D D Number

b pi

C

export 10i 0 10i 0 value

P

return

Number + 1

e

Notice that there's only one routine--OneMoreThan. Dan created a source member in which to store the procedure prototype: D OneMoreThan D Number

pr

10i 0 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 C dow C eval

fmt01 not *in03 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 D D Number C P

b pi

P Twice D D Number C P

b pi

return

e

return

e

export 10i 0 10i 0 value Number + 1 export 10i 0 10i 0 value Number * 2

He also modified the prototype member: D OneMoreThan D Number D Twice D Number

pr pr

10i 10i 10i 10i

0 0 value 0 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

Related Documents

Service Program1
November 2019 14
8th Grade Program1
April 2020 16
Obalka Cams Program1
November 2019 7
Service
April 2020 15
Service
November 2019 35
Service
June 2020 9