Friday, January 22, 2010

EXTPGM and EXTPROC

EXTPGM:
use the EXTPGM keyword when I want to call a *PGM object from free-form RPG, since free-form does not support the PARM operation code.

Fixed format:
Code:

C Call 'MyPgm'
C Parm FirstParm 6
C Parm SecondParm 2 0

Free-form:
Code:

D myPgm pr ExtPgm('MYPGM')
D FirstParm 6a
D SecondParm 2p 0

/free
Callp myPgm(FirstParm: SecondParm);
/end-free



EXTPROC:
EXTPROC is used to prototype a procedure written in an ILE language (or Java). It can be used to change the name used to invoke the procedure within your program for convenience or due to naming constraints within the language you're using (lower-case or beginning with underscores can't be accessed within ILERPG unless you use extproc)...
Code:

D QpdRptSftErr pr extproc('QpdReportSoftwareError')
D PrbDescAry const like(PrbDescRcds)
D NbrElems 10i 0 const
D ErrCode like(ApiError)
D itoa pr * extproc('__itoa')
D val 10i 0 value
D strptr * value
D base 10i 0 value

It *must* be used to invoke Java(TM) classes...
Code:

D String_getBytes...
D pr 1024a extproc(*JAVA:'java.lang.String':
D 'getBytes')

EXTPGM is used to define external program calls with a prototype. This ensures you pass the proper parameters, as well as allowing you to code the call in a free-form RPG spec.
Code:

* --- Resignal escape message ---
D QMHRSNEM PR EXTPGM('QMHRSNEM')
D MsgKey 4a Const
D ApiErr Like(ApiError) Options(*VARSIZE)
/free
QMHRSNEM(' ' : APIERROR);
/end-free

1 comment:

  1. Wow...Nice to see these Stuff here. Good Work Yogesh....Let me know if u need any details. we can make it BIGGER...!!!

    ReplyDelete