Anda di halaman 1dari 1

7/22/2018 FREE AS/400, iSeries, and System i / iSeries Downloads

FREE AS/400, iSeries, and System i / iSeries Downloads


HOME >> FREE AS/400, iSeries, and System i / iSeries Downloads >> RPG "Cheat Sheet" #1 - Create an ILE RPG Module

RPG "Cheat Sheet" #1 - Create an ILE RPG Module


Author: Craig Pelkie

Overview
A module is an OS/400 object (type *MODULE). It is the starting point for creating program (*PGM) and service program
(*SRVPGM) objects. A module is created using the CRTRPGMOD command. The module is not "called" like a program. Instead,
other modules call procedures defined in the module or the module might be converted into a program using the CRTPGM
command.
Define / Create a module
Step 1 - Code the module

Code procedure Define a procedure prototype (D-specs) for:


prototypes for all procedures used in
Each procedure that is defined in the module.
the module Procedures that are defined in other modules but are called in this module.
Suggestion: use /INCLUDE source code members to include prototypes for procedures that
are defined in other modules.

Step 2 - Is the module the "main module" of a stand-alone program?

Yes Go to the next step.

Add a control specification (H-spec) with NOMAIN:


No
h nomain

Verify that the module does not contain:


Primary / Secondary files
Detail / Total output
Main routine C-specs, subroutines

Step 3 - Do any of the procedures in this module call procedures in another module?

No Go to the next step.


Yes Identify the binding directory(s) (*BNDDIR) that contains binding directory entries for the modules
and/or service programs that export the procedures that are used.
Add a control specification (H-spec) for the binding directory(s):
h bnddir('RPG_UTILS' : 'RPG_MODS' : 'RPG_SRVPGM')

Note: you can optionally specify the binding directories on the CRTRPGMOD command. It is
preferable to specify the binding directories on the BNDDIR H-spec

Step 4 - Use the CRTRPGMOD command to create the module


Use the Create RPG Module (CRTRPGMOD) command to create a *MODULE object from the source member:
CRTRPGMOD MODULE(libname/module_name)
SRCFILE(libname/srcfile_name)
DBGVIEW(*ALL)
BNDDIR(libname/bnddir_name)

Notes:
The DBGVIEW (Debug View) parameter is optional. Specifying DBGVIEW(*ALL) makes it easier to use the interactive
source debugger to debug code in the module.
The BNDDIR (Binding Directory) parameter is optional. If you specified all of the required binding directories using H-
specs in the source code for the module, you don't need to specify the BNDDIR parameter on the CRTRPGMOD command.
You can specify additional binding directories using the BNDDIR parameter. Any binding directories you specify on the
parameter are in addition to binding directories specified on H-specs in the module.
Step 5 - Use the DSPMOD command to review the module
Use the Display Module (DSPMOD) command to review the attributes of the *MODULE object:
DSPMOD MODULE(libname/module_name)
DETAIL(*ALL)

Notes:
Exported defined symbols (panel 3 of 7) - shows the list of procedures that are exported from the module. You can
call these procedures from other programs and modules that you create. Use this list to verify the following:
All procedures that you intend to use in other modules are listed (the EXPORT keyword was specified for the
procedure)
Only the procedures that you intend to use in other modules are listed (you did not erroneously specify
EXPORT for an internal- use only procedure)
Imported (unresolved) symbols (panel 4 of 7) - shows the list of procedures that are used in this module but are
defined in another module. When you create a program or service program based on this module, the imported
symbols are resolved (located) using the binding directory list (see Reference system objects for bind time, below).
You will see many IBM procedures in the list (names starting with _Q or Q). You do not need to be concerned with
those procedures
Procedure list (panel 5 of 7) - shows the complete list of procedures that are defined in this module. This list includes
procedures that are exported (can be called from other modules) and procedures that are not exported (can only be
called within this module). You will see some IBM procedures in the list (names starting with _Q or Q). You do not
need to be concerned with those procedures.
Reference system objects for bind time (panel 6 of 7) - shows the list of binding directories that will be used to
locate imported symbols when the module is used to create a program or a service program. You will see some IBM
binding directories in the list (names starting with Q). You do not need to be concerned with those binding directories.

Learn how to create ILE RPG subprocedures, modules, service programs and programs!
Order your copy of Subprocedures for RPG Programmers by Craig Pelkie.

© 2018, Rochester Initiative

http://www.lab400.com/RPG-Cheat-Sheet-1.html 1/1

Anda mungkin juga menyukai