The ILE (Integrated Language Environment) programming environment allows programs from ILE compatible languages (C, C++, COBOL, RPG, Fortran, and CL), to be bound into the same executable and call procedures written in any of the other ILE languages.

The process starts with the creation of a binding directory.  To create simply run this command:

[cc lang=”php”]

CRTBNDDIR BNDDIR(MYLIBRARY/UTILITIES)
TEXT(‘Default utilities binding directory’)

[/cc]

I define all my procedures with 2  source members

  1. The working section of the code and PI statement
  2. The PR statement and/or variables, data structures I want to share with calling program

The PR section

[cc lang=”php”] * COMMAND_CP – run a command from RPG program
d RunCommand pr n
d Incommand 1000a
d OneThousandLong…
d s 1000 inz [/cc]

The PI section – I used QCMDEXEC here , but can be system or QCAPCMD

[cc lang=”php”] H NOMAIN EXPROPTS(*RESDECPOS)
* PROGRAM – COMMAND
* PURPOSE – run a command from an RPG program
* WRITTEN – 12/07/16
* AUTHOR – Jamie Flanary
/copy qprcsrc,COMMAND_CP
d commandLength…
d s 15 5 inz
d Q s 1 inz(””)
d ProcessFlag s 1 inz(‘0’)
*
* Begin Procedure
P RunCommand B export
* Procedure Interface
d RunCommand pi n
d Incommand 1000a
*
d $command pr extpgm(‘QCMDEXC’)
d command 1000

d Length 15 5
/free
*inlr = *on;
reset ProcessFlag;
commandlength = %len(Incommand);
monitor;
$command(InCommand: commandLength);
on-error;
ProcessFlag = *on;
endmon;
return ProcessFlag;
/end-free
p RunCommand e

[/cc]

To compile the procedure 

[cc lang=”php”] CRTRPGMOD MODULE(MYLIBRARY/COMMAND) SRCFILE(MYLIBRARY/QPRCSRC)[/cc]

Then add to binding directory (in this case UTILITIES)

[cc lang=”php”]ADDBNDDIRE BNDDIR(UTILITIES) OBJ((COMMAND *MODULE))[/cc]

example program that uses the command

[cc lang=”php”] H DFTACTGRP(*NO) OPTION(*SRCSTMT: *NODEBUGIO) BNDDIR(‘UTILITIES’)

/copy qprcsrc,COMMAND_CP

*inlr = *on;

// DSPLIB LIB(QGPL) OUTPUT(*PRINT)
OneThousandLong = ‘DSPLIB LIB(QGPL) OUTPUT(*PRINT)’;
monitor;
runcommand(OneThousandLong);
on-error;
endmon;
[/cc]

More Examples

  • CALLER – Retrieve previous called program
  • CHKIFS – Check for existence of IFS or Server Table
  • GETDATE – Get dates in multiple formats
  • ENCRYPT – Encryption and Decryption of a string
  • Get IP Address –  Get IP address from hardware