I am busy with a C++ project on IBM i and is trying to call an RPG procedure that is in a service program, but I am not sure how to do that.
I only find examples on the internet and the documentation that shows how to call an RPG program (*PGM) object by defining it as follows:
extern "OS"
{
void RPGPROGRAM(void);
}
int main()
{
RPGPROGRAM();
return 0;
}
The documentation says they are calling an RPG "procedure" but if you look at the actual source it is just a RPG program (*PGM) object that they call from within C++ using #pragma map
.
Lets say I have the following RPG service program (lets name it RPGSP) with a procedure named rpg_doSomething
defined in it:
ctl-opt nomain;
dcl-proc rpg_doSomething export;
dcl-pi *n int(10);
dcl-parm p_test char(20);
end-pi;
p_test = "It Works!!";
return 1;
end-proc;
How should I declare and call the above procedure in my C++ program?
I have tried declaring it within the extern
block but it ends up looking for the rpg_doSomething
object at runtime and cannot find it. I have also tried binding the service program to the C++ program when compiling but that does not work either.
Any help on this would be appreciated.
First off which C++ compiler are you using?
The native ILE one? Then it should be pretty easy. Pretty sure you just need:
extern "RPG"
on the function declaration.
Or the AIX on in PASE? Then take a look at Calling ILE procedures
One thing to note, RPGLE is case insensitive and by default, uppercases names. While C/C++ is case sensitive. Your C++ program needs to be calling RPG_DOSOMETHING
or you need to apply a case sensitive name to the RPG procedure using EXTPROC('rpg_DoSomething')