IBM AS/400 Frozen Dessert Maker User Manual


 
Example of Module with Multiple Procedures
*=================================================================*
* Source for module CVTPROCS. This module does not have a
* main procedure, as indicated by the keyword NOMAIN.
*=================================================================*
H NOMAIN
*-----------------------------------------------------------------*
* The prototype must be available to EACH module containing
* a prototyped procedure. The /COPY pulls in the prototype
* for NumToChar.
*-----------------------------------------------------------------*
/COPY QRPGLESRC,CVTPROCP
*-----------------------------------------------------------------*
* NumToChar converts a numeric field to a character field
*
* Parameters: NUMPARM (input)
* Globals: (none)
* Returns: character string
*
* The subprocedure will be called by procedures outside of this
* module, and so the keyword EXPORT is required to indicate this.
*-----------------------------------------------------------------*
P NumToChar B EXPORT
D NumToChar PI 31A
D NUMPARM 30P 0 VALUE
* Local declarations
D POS S 5P 0
D SIGN S 1A INZ(' ')
D ZONEDS DS
D NUM 30S 0
D CHAR 30A OVERLAY(NUM)
*
* Body of procedure:
* Handle special case of zero
C IF NUMPARM = 0
C RETURN '0'
C ENDIF
* Handle negatives. Set sign to '-' and make positive.
C IF NUMPARM < 0
C EVAL NUMPARM = - NUMPARM
C EVAL SIGN = '-'
C ENDIF
* Get the input number in character form using a data structure
C EVAL NUM = NUMPARM
* Left-justify
C
C '0' CHECK CHAR POS
C EVAL CHAR = %SUBST(CHAR:POS)
* Return the value adding the sign
C RETURN %TRIML(SIGN + CHAR)
P NumToChar E
Figure 20. Source for module CVTPROCS, containing subprocedure NumToChar
CVTPROCS is a NOMAIN module, meaning that it consists only of subprocedures;
there is no main procedure. A NOMAIN module compiles faster and requires less
storage because there is no cycle code that is created for the module. You specify
a NOMAIN module, by coding the NOMAIN keyword on the control specification.
For more information on NOMAIN modules, see “Program Creation” on page 46.
40 ILE RPG for AS/400 Programmer's Guide