Reputation: 53
I'm trying to call a CL programm from an RPGLE. I didn't do this before. I've always done the oposit ( callin an rpgle from a CL) Is it possible ? through a callp or a QCMDEXC ???
Upvotes: 1
Views: 2210
Reputation: 11
some notes I have from 16 years ago...best of luck.
/IF Defined(*CRTBNDRPG)
H DFTACTGRP(*NO)
/ENDIF
H BNDDIR('QC2LE')
D GoCmd PR 10I 0 Extproc('system')
D CmdStr * value
D options(*string)
D NullString C -1
D Success C 0
D Returncode S 10I 0
D User S 10 Inz(*User) Varying
/free
Returncode = Gocmd('DLYJOB DLY(300)'); //change to another CL command here
Select;
When Returncode = Success; // Command was successful
When Returncode = NullString; // Command string was null
Other;
Endsl;
*INLR=*ON;
/end-free
Upvotes: 0
Reputation: 11473
CALLP
and QCMDEXEC
do two very different things. CALLP
is for executing program objects (*PGM) and ILE sub-procedures (no object type, but contained in *SRVPGM or even *PGM) regardless of which language was used to compile that *PGM (or *SRVPGM) object. QCMDEXEC
is for executing command objects (*CMD).
Let's look at the *PGM object. This is a compiled object created by one of the RPG, COBOL, C/C++, CL, PL/1 or MI compilers/assembler. All program objects can be called by any of these languages as long as the call is defined properly. For RPGLE, you can use CALL or CALLP, though CALLP is preferred because it enforces parameter type checking.
Looking at sub-procedures, these are contained in ILE program and service program (*PGM & *SRVPGM) objects. These can be created using one of the RPG, COBOL, CL, or C/C++ ILE compilers, and can be called from any ILE program regardless of the language it was created with. In fact, a single service program can contain sub-procedures from multiple languages. Sub-procedures are called in RPGLE using CALLB or CALLP, though CALLP is preferred because, as in calling program objects, it enforces parameter type checking. One caveat here, if a sub-procedure resides in a program object (*PGM) it can only be called from within that program object. Shared sub-procedures must be compiled into service programs. There is a type of sharing where sub-procedure source is shared, and the modules are then linked directly into the program object. I don't really consider this shared code since only the source is shared, the executable is not.
That brings us to command objects (*CMD) These are special objects created by CRTCMD. Commands can be executed on the command line by just typing the command name like WRKACTJOB
. They may have parameters, or not. These are the things executed by QCMDEXEC
, which, by the way, is a program object, so is callable using CALLP
in an RPGLE program.
Upvotes: 1
Reputation: 3202
You can call any program from RPGLE like you call QCMDEXC, you have to define a prototype with extpgm keyword and use it like a procedure
dcl-pr name_inside_rpgle extpgm('*LIBL/CLPGMNAME'); // program name MUST be uppercased
...
end-pr;
name_inside_rpgle(...);
Upvotes: 3