Midware Ltd.

Using External Procedures

Home
Services
News
AS/400
Employment

Sign-up for e-mail notifications

Take our weekly poll

Dow Jones Intraday

Nasdaq Intraday

 

 

Up to this point, we've created a separate source member containing multiple procedure and compiled it into a module.  Any exported procedures are now available to other modules.

Note:  All examples from this point forward will assume that all the procedure prototypes are included in a copy member called PROTOTYPES.

Using external procedure is exactly the same as using internal procedures.  The following short program demonstrates using the IsWorkday and DayOfWeek procedures that we developed.

H*======================================================
H datedit(*ymd) option(*srcstmt)
 *
 /copy qrpglesrc,prototypes
 *
 * Define some stand-alone test fields...
D @TestDate1      S              8  0 inz(19990430)
D @TestDate2      S              6  0 inz(990430)

C                   if        IsWorkday(@TestDate1) or
C                             DayOfWeek(@TestDate2) = 6
C***  do something
C                   endif

 *
 * End the program...
C                   eval       *inlr = *on

Because we are using external procedures, we need to use a two-step compile process.  First, use PDM option 15 or the CRTRPGMOD command to create a module.  This is exactly the same as we did with the procedure source member.  Recall that a module is not executable on it's own.

The next step is to bind our compiled mainline module with our procedure module.  There are two different ways to bind these together - static and dynamic.  We'll cover static binding first.


CRTPGM command

Recall that an ILE program is actually composed of one or more modules.  In our example, it will be composed of two - the module compiled from the mainline code we just wrote, and the module containing the procedures:

 

The CRTPGM command is used to bind the components together and create an executable program.  Enter CRTPGM on a command line and press F4 to prompt it.

Enter the name and library of the program you want created.  Typically, you will name the program the same as the mainline source member.  Next, enter the names of the two modules.

Next, we need to tell the CRTPGM command which module gets control when the program is called (ENTMOD).  Although this is obvious to us, it is not to the CRTPGM command.  The default is the first module listed.  Because we specified *NOMAIN in our procedure module, we could not, even if we wanted to, use that as the entry point module.

The only other parameter you might have to change is to specificy OPTION(*DUPPROC).  This parameter allows duplicate procedure names in the modules.  Don't get caught up in this detail right now.  This is one of those things that probably could have been handled better by IBM.

The CRTPGM program should execute very quickly.  If it completes sucessfully, you will have an executable program.

  Back to Creating a Module

Next to Static Binding

 
Home Feedback Contents Search

Send mail to midware@midwareservices.com with questions or comments about this web site.
Copyright © 2000 Midware, Ltd.

Last Modified:  September 06, 2000