HP RPG/XL Programmer's Guide (30318-90001)

5- 19
Columns 18-23 contain the name of the internal subroutine INQRY.
Columns 28-32 contain BEGSR to mark the beginning of the
internal subroutine.
3 This line transfers control to the end of the internal
subroutine. You cannot use GOTO operations to transfer control
out of the subroutine.
4 This line ends the internal subroutine.
Columns 18-23 contain the tag, INQRY9. (A tag is used in this
particular example, though it is optional.)
Columns 28-32 contain ENDSR to end the internal subroutine.
External Subroutines
External subroutines are separate procedures; you do not code them as
part of an RPG program. For example, you can code an external subroutine
in Business BASIC. You then compile it, and place it in an executable
library using HP Link Editor/XL. To execute the external subroutine from
an RPG program, enter an EXIT Calculation Specification operation. The
HP RPG Reference Manual
contains information on how to create external
subroutines in COBOL and other languages.
There are two ways to pass information to external subroutines. The
first method uses the Calculation Specification operation, RLABL, to name
the fields, arrays, tables or indicators that you want to pass. The
second method uses the Calculation Specification operation, PARM, to name
the fields, arrays and tables to pass. PARM is more limited than RLABL
because you cannot pass indicators. Also, PARM values are available only
to the subroutine executed with the PARM operation(s). The next two
sections explain how to use external subroutines and how to pass
parameters to them using RLABL and PARM.
Using RLABL. RLABL passes field names, tables, arrays and indicators to
external subroutines. Values passed by RLABL are available to all
external subroutines in the program.
Figure 5-15 shows a portion of a C procedure that is used as an external
subroutine. Just the statements defining the data that is passed to the
procedure (the field, PNAME, and the indicator, IN20) are shown. Figure
5-16 shows how to execute this C procedure from an RPG program.
_____________________________________
| |
| VOID SUB01() |
| { |
| EXTERN CHAR PNAME[]; |
| EXTERN INT IN20; |
| . |
| . |
| . |
| } |
| |
_____________________________________
Figure 5-15. An External Subroutine written in C
Figure 5-16 lists the Specifications that execute the external
subroutine, SUB01, shown in the previous figure. The RPG program passes
indicator 20 (IN20) and the field (PNAME) to the subroutine.