× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jake,

Binding directories do list the modules that you want to contain in that
directory.  I suppose you can think of as a PHYSICAL source file that
contains the different sources.   If you'd like to mess around with it
some.

Create a binding directory in YOUR own personal library.

CRTBNDDIR BNDDIR(LIBRARY/DIRECTORY)

Then in a PHYSICAL SOURCE FILE, preferrably in your own library, create a
new member of RPGLE (name it MATHFUNCS)  just as you would for a normal
program.  In that member, copy the code below to it.

     h Option(*NoDebugIO)
     h NoMain
     ˆ*-------------------------------------------------------
     ˆ*‚                    File Specifications
     ˆ*-------------------------------------------------------
     ˆ*‚Add your file names here, this will allow all procedures
     ˆ*‚to access this files.

     ˆ*-------------------------------------------------------
     ˆ*‚Global Variables (To Be Used In Any Procedure At Any Time).
     ˆ*-------------------------------------------------------

      *‚List Procedure Prototypes Here
     D PROTO_02        PR            15P 5
     D  num1                         15P 5 Const
     D  num2                         15P 5 Const

     ˜*--------------------------------------------------
     ˜*‚Procedures To Use In External Programs.
     ˜*--------------------------------------------------
     P PROTO_02        B                   Export

     ˆ*‚list this procedures interface
     D PROTO_02        PI            15P 5
     D  num1                         15P 5 Const
     D  num2                         15P 5 Const

     ˆ*‚list local variables here, can only be used in this procedure.
     D rtnVal          S             15P 5

      /Free

        //‚Do your stuff here.
        rtnVal = num1 + num2;

        //‚return results to calling program
        Return rtnVal;
      /End-Free
     P PROTO_02        E



Notice in the HSPECS, I have two things defined.  The Option keyword is
telling the compiler that when I'm debugging the source member, DO NOT step
through the fields that are used when a record is read (for this particular
procedure we are not interested in doing it).  The NoMain keyword is
telling the compiler that there is NO MAIN line to this source, instead is
nothing but procedures.

You may define files to use within this module, but they must be defined
globally (outside of any procedures, explained later).

For all procedures in the module you must define a prototype globally (See
above where PROTO_02    PR is before the PSPECS = Procedure
SPECIFICATIONS).

Notice the PSPECS, you name the procedure, the B stands for the begin of
the procedure,  and to enable the use of this procedure in other programs,
you specify the Keyword  Export.

Once you start a procedure, you now have the option to define local
variables, variables that can only be used in the procedure.  Global
variables can be used across procedure, however, local cannot.  you will
need to define the PROCEDURE's interface in the DSPECS of that procedure.
See (PROTO_02   PI   15P 5)  the 15P 5, is the size of the field that is
being returned to the calling program.

Then you put in your code.   Since this procedure is defined as returning a
value, on the RETURN statement you must put the variable you want to
return.

When you are finished with this module, you will then compile it.  However,
this source is going to be compiled with an option 15 (create RPG module
CRTRPGMOD) instead of an option 14 (Create Bound RPG Program CRTBNDRPG)
from PDM.

If compile was good, then you are going to add this new module to a binding
directory.

ADDBNDDIRE BNDDIR(LIBRARY/DIRECTORY) OBJ(MATHFUNCS *MODULE)

-----------------------------------------------------------------------

Now that the module is in a binding directory, you may bind the procedures
inside this module to any program that you wish.  You will do this by
adding this code to the program.  I've always done *NO as the DftActGrp,
but I've seen others that used *CALLER.  I personally can't explain the
difference.  I just know that the default is *YES and it cannot be *YES
when you are using prototypes in an RPGLE program.

In the HSPECS...

      H BndDir('LIBRARY/DIRECTORY')
      H DftActGrp(*NO)

or you can do

      H BndDir('DIRECTORY')
      H DftActGrp(*NO)

if the library is part of the library list of compile and when the program
is ran.

In the DSPECS, you will need to place the PROTOTYPE of the procedure.

     D PROTO_02        PR            15P 5
     D  num1                         15P 5 Const
     D  num2                         15P 5 Const

Now you can just call the PROTO_02 procedure in the program and use the
EVAL statement to return a value from it.

Eval result = PROTO_02(1:2);

You will compile this program as you normally would.

Michael Schutte.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.