IBM AS/400 User Manual Page 70

  • Download
  • Add to my manuals
  • Print
  • Page
    / 489
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 69
Coding Considerations
Program Creation
¹ If you specify that a module does not have a main procedure then you cannot
use the CRTBNDRPG command to create the program. (A module does not
have a main procedure if the NOMAIN keyword is specified on a control specifi-
cation.) This is because the CRTBNDRPG command requires that the module
contain a program entry procedure and only a main procedure can be a
program entry procedure.
¹ Similarly, when using CRTPGM to create the program, keep in mind that a
NOMAIN module cannot be an entry module since it does not have a program
entry procedure.
¹ A program that is created to run in the default OPM activation group (by speci-
fying DFTACTGRP(*YES) on the CRTBNDRPG command) cannot contain
bound procedure calls.
Main Procedure Considerations
¹ Because the main procedure is the only procedure with a complete set of spec-
ifications available (except the P specification), it should be used to set up the
environment of all procedures in the module.
¹ A main procedure is always exported, which means that other procedures in
the program can call the main procedure by using bound calls.
¹ The call interface of a main procedure can be defined in one of two ways:
1. Using a prototype and procedure interface
2. Using an *ENTRY PLIST without a prototype
¹ The functionality of an *ENTRY PLIST is similar to a prototyped call interface.
However, a prototyped call interface is much more robust since it provides
parameter checking at compile time. If you prototype the main procedure, then
you specify how it is to be called by specifying either the EXTPROC or
EXTPGM keyword on the prototype definition. If EXTPGM is specified, then an
external program call is used; if EXTPROC is specified or if neither keyword is
specified, it will be called by using a procedure call.
¹ You cannot define return values for a main procedure, nor can you specify that
its parameters be passed by value.
Subprocedure Considerations
¹ Any of the calculation operations may be coded in a subprocedure. However,
all files must be defined globally, so all input and output specifications must be
defined in the main source section. Similarly, all data areas must be defined in
the main procedure, although they can be used in a subprocedure.
¹ The control specification can only be coded in the main source section since it
controls the entire module.
¹ A subprocedure can be called recursively. Each recursive call causes a new
invocation of the procedure to be placed on the call stack. The new invocation
has new storage for all data items in automatic storage, and that storage is
unavailable to other invocations because it is local. (A data item that is defined
in a subprocedure uses automatic storage unless the STATIC keyword is speci-
fied for the definition.)
46 ILE RPG for AS/400 Programmer's Guide
Page view 69
1 2 ... 65 66 67 68 69 70 71 72 73 74 75 ... 488 489

Comments to this Manuals

No comments