Creating a Module Object - IBM - RPG

A module is a nonrunnable object (type *MODULE) that is the output of an ILE compiler.

It is the basic building block of an ILE program. An ILE RPG module consists of one or more procedures, and the file control blocks and static storage used by all the procedures in the module. The procedures that can make up an ILE RPG module are:

  • an optional main procedure which consists of the set of H, F, D, I, C, and Ospecifications that begin the source. The main procedure has its own LR semantics and logic cycle; neither of which is affected by those of other ILE RPG modules in the program.
  • zero or more subprocedures, which are coded on P, D, and C specifications.Subprocedures do not use the RPG cycle. A subprocedure may have local storage that is available for use only by the subprocedure itself.

The main procedure (if coded) can always be called by other modules in the program. Subprocedures may be local to the module or exported. If they are local, they can only be called by other procedures in the module; if they are exported from the module, they can be called by any procedure in the program.

Module creation consists of compiling a source member, and, if that is successful, creating a *MODULE object. The *MODULE object includes a list of imports and exports referenced within the module. It also includes debug data if you request this at compile time.

A module cannot be run by itself. You must bind one or more modules together to create a program object (type *PGM) which can then be run. You can also bind one or more modules together to create a service program object (type *SRVPGM). You then access the procedures within the bound modules through static procedure calls.

This ability to combine modules allows you to:

  • Reuse pieces of code. This generally results in smaller programs. Smaller programs give you better performance and easier debugging capabilities.
  • Maintain shared code with little chance of introducing errors to other parts of the overall program.
  • Manage large programs more effectively. Modules allow you to divide your old program into parts that can be managed separately. If the program needs to be enhanced, you only need to recompile those modules which have been changed.
  • Create mixed-language programs where you bind together modules written in the best language for the task required.

Using the CRTRPGMOD Command
You create a module using the Create RPG Module (CRTRPGMOD) command. You can use the command interactively, as part of a batch input stream, or from a Command Language (CL) program.

If you are using the command interactively and need prompting, type CRTRPGMOD and press F4 (Prompt). If you need help, type CRTRPGMOD and press F1 (Help).

lists the parameters of the CRTRPGMOD command and their system-supplied defaults. The syntax diagram of the command and a description of the parameters are found in “The Create Commands,”.

CRTRPGMOD Parameters and Their Default Values Grouped by Function

CRTRPGMOD Parameters and Their Default Values Grouped by Function

When requested, the CRTRPGMOD command creates a compiler listing which is for the most part identical to the listing that is produced by the CRTBNDRPG command. (The listing created by CRTRPGMOD will never have a binding section.)

For information on using the compiler listing, see “Using a Compiler Listing”. A sample compiler listing is provided in Appendix D, “Compiler Listings,”.

Creating a NOMAIN Module
In this example you create an NOMAIN module object TRANSSVC using the CRTRPGMOD command and its default settings. TRANSSVC contains prototyped procedures that perform transaction services for procedures in other modules. The source for TRANSSVC is shown. The prototypes for the procedures in TRANSSVC are stored in a /COPY member, as shown below.

  1. To create a module object, type:
  2. CRTRPGMOD MODULE(MYLIB/TRANSSVC) SRCFILE(MYLIB/QRPGLESRC)

    The module will be created in the library MYLIB with the name specified in the command, TRANSSVC. The source for the module is the source member TRANSSVC in file QRPGLESRC in the library MYLIB.

    You bind a module containing NOMAIN to another module using one of the following commands:

    a.CRTPGM command
    b.CRTSRVPGM command
    c.CRTBNDRPG command where the NOMAIN module is included in a binding directory.
  3. Once it is bound, this module object can be debugged using a statement view. A compiler listing for the module is also produced.
  4. Type one of the following CL commands to see the compiler listing.
    • DSPJOB and then select option 4 (Display spooled files)
    • WRKJOB
    • WRKOUTQ queue-name
    • WRKSPLF

Source for TRANSSVC member

Source for TRANSSVC member

Source for TRANSP /COPY member
Source for TRANSSVC member

Creating a Module for Source Debugging

In this example, you create an ILE RPG module object that you can debug using the source debugger. The module TRANSRPT contains a main procedure which drives the report processing. It calls the procedures in TRANSSVC to perform certain required tasks. The source for this module is shown.

To create a module object, type:

The module is created in the library MYLIB with the same name as the source file on which it is based, namely, TRANSRPT. This module object can be debugged using a source view. For information on the other views available, see “Preparing a Program for Debugging”.

A compiler listing for the TRANSRPT module will be produced.

Source for TRANSRPT module
Source for TRANSRPT module

The DDS for the file TRNSDTA is shown. The /COPY member is shown.

DDS for TRNSDTA
DDS for TRNSDTA

Additional Examples
For additional examples of creating modules, see:

  • “Sample Service Program”, for an example of creating a module for a service program.
  • “Binding to a Program”. for an example of creating a module to be used with a service program.
  • “Managing Your Own Heap Using ILE Bindable APIs” for an example of creating a module for dynamically allocating storage for a run-time array
  • “Sample Source for Debug Examples”, for example of creating an RPG and C module for use in a sample debug program.

Behavior of Bound ILE RPG Modules
In ILE RPG, the main procedure is the boundary for the scope of LR semantics and the RPG cycle. The module is the boundary for the scope of open files.

In any ILE program, there may be several RPG cycles active; there is one RPG cycle for each RPG module that has a main procedure. The cycles are independent: setting on LR in one main procedure has no effect on the cycle in another.

Related CL Commands

The following CL commands can be used with modules:

  • Display Module (DSPMOD)
  • Change Module (CHGMOD)
  • Delete Module (DLTMOD)
  • Work with Modules (WRKMOD)

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM - RPG Topics