pTAL Conversion Guide

Procedures, Subprocedures, and Procedure
Pointers
pTAL Conversion Guide527302-002
16-18
Dynamically Selected Procedure Calls
Although you cannot create an array of PROCPTRs in pTAL, you can create a
structure that includes a PROCPTR field. You can choose dynamically which
PROCPTR in the structure array to call, as in Example 16-14 on page 16-18.
In Example 16-14 on page 16-18
You must initialize the array s1 to hold the addresses of the procedures that you
want to dynamically call; for example:
@s1[dev_6530].d := @device_6530;
@s1[dev_3270].d := @device_3270;
@s1[dev_dove].d := @device_dove;
Use an index to choose which element of array s1 to call; for example:
CALL s1[dev_6530].d(80, 2);
Example 16-13. CASE Statement for Dynamically Selected Procedure Call
(pTAL)
LITERAL dev_6530, dev_3270, dev_dove;
INT device_type;
INT param1, param2;
PROC device_6530(i, j); INT i, j; EXTERNAL;
PROC device_3270(i, j); INT i, j; EXTERNAL;
PROC device_dove(i, j); INT i, j; EXTERNAL;
PROCPTR p(i, j); INT i, j; END PROCPTR;
CASE device_type of
BEGIN
dev_6530 -> @p := @device_6530;
dev_3270 -> @p := @device_3270;
dev_dove -> @p := @device_dove;
END;
CALL p( param1, param2 );
Example 16-14. PROCPTR Array for Dynamically Selected Procedure Call (pTAL)
LITERAL dev_6530, dev_3270, dev_dove;
STRUCT s1 [dev_6530:dev_dove]; ! Declare array of PROCPTRs
BEGIN
PROCPTR d(device, param);
INT device, param;
END PROCPTR;
END;
PROC device_6530(i, j); INT i, j; EXTERNAL;
PROC device_3270(i, j); INT i, j; EXTERNAL;
PROC device_dove(i, j); INT i, j; EXTERNAL;