|
|
![]() |
|
|
|
|
||
|
Call RPG Subprocedures from CL Hey, Ted: I have an RPG subprocedure that accepts one or two parameters and returns the name of a client. How do I reference this subprocedure from a CL module in order to get a client name for a display screen?
-- Doug Use the Call Procedure (CALLPRC) command. The client name will come back in the RTNVAL parameter. If you plan to call an RPG subprocedure from CL, keep these points in mind:
Here's an example. First, here is the member of prototypes for the subprocedures that open a customer master file, retrieve a customer record, and close the customer master file.
DRtvCustomer pr 25a
D PCompany 3p 0 const
D PCustomer 5p 0 const
DOpenCustomers pr 1a
DCloseCustomers pr 1a
Here is the source code for the subprocedures.
H nomain
Fcustomer if e k disk usropn
/copy prototypes,rtvcust
PRtvCustomer b export
D pi 25
D PCompany const like(Company)
D PCustomer const like(CustNbr)
C Key klist
C kfld PCompany
C kfld PCustomer
C
C key chain CustRec
C if %found
C return CustName
C else
C return '*Not on file*'
C endif
P e
POpenCustomers b export
D pi 1a
C open (e) Customer
C if not %error
C return *off
C else
C return *on
C endif
P e
PCloseCustomers b export
D pi 1a
C close(e) Customer
C if not %error
C return *off
C else
C return *on
C endif
P e
Here's part of the CL caller.
dcl &pcomp *dec 3
dcl &pcust *dec 5
dcl &status *char 2
dcl &cname *char 25
callprc prc(OpenCustomers) rtnval(&status)
if (%sst(&status 1 1) *ne '0') do
sndpgmmsg msgid(CPF9898) msgf(qcpfmsg) +
msgdta('Customer file could not be opened') +
msgtype(*escape)
enddo
callprc prc(RtvCustomer) parm(&pcomp &pcust) rtnval(&cname)
callprc prc(CloseCustomers) rtnval(&status)
This example covers all three points I mentioned.
As of V5R1, you can make the subprocedure pass one-byte values correctly by using the EXTPROC keyword in the procedure prototype. The first parameter of EXTPROC is the special value *CL. The second parameter is the name of the subprocedure. Here is the revised prototype member.
DRtvCustomer pr 25a
D PCompany 3p 0 const
D PCustomer 5p 0 const
DOpenCustomers pr 1a extproc(*CL:'OPENCUSTOMERS')
DCloseCustomers pr 1a extproc(*CL:'CLOSECUSTOMERS')
The CL module could define the one-byte character field properly. dcl &status *char 1 if (&status *ne '0') do -- Ted
|
Editors
Contact the Editors |
|
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |