IBM AS/400 manual Example of Module with Multiple Procedures, module

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 64
Image 64
module

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 containin￿g

*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 struc￿ture

 

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 subprocedur

there

is

no

main

procedure. A NOMAIN module compiles faster and require

storage

because

there

is

no

cycle

code that is created for the m

a

NOMAIN

module, by

coding

the

NOMAIN

keyword on the control specificati

For

more

information

on NOMAIN modules,

see “Program Creation” on page 46.

40 ILE RPG for AS/400 Programmer's Guide

Page 64
Image 64
IBM AS/400 manual Example of Module with Multiple Procedures, module