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:

1
2
CRTBNDDIR BNDDIR(MYLIBRARY/UTILITIES)
TEXT('Default utilities binding directory')

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

1
2
3
4
5
 * COMMAND_CP - run a command from RPG program
d RunCommand pr n
d Incommand 1000a
d OneThousandLong...
d s 1000 inz

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 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

To compile the procedure 

1
 CRTRPGMOD MODULE(MYLIBRARY/COMMAND) SRCFILE(MYLIBRARY/QPRCSRC)

Then add to binding directory (in this case UTILITIES)

1
ADDBNDDIRE BNDDIR(UTILITIES) OBJ((COMMAND *MODULE))

example program that uses the command

1
2
3
4
5
6
7
8
9
10
11
12
 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;

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

Leave a Reply

Your email address will not be published. Required fields are marked *