Compaq AAQ2G1FTK Marine Radio User Manual


 
Interprogram Communication
12.6 Calling Compaq COBOL Programs from Other Languages
Example 1211 (Cont.) COBOL Called Program "PROGCOB"
data division.
working-storage section.
01 retVal pic 9(9) comp value 987654321.
01 myVal pic 9(9) comp value 0.
01 arg1 pic 9(9) comp value 0.
01 arg2 pic 9(9) comp value 0.
01 arg3 pic 9(9) comp value 0.
01 arg4 pic 9(9) comp value 0.
arg1 arg2 arg3 arg4 giving retVal.
p0. display " +------------------- From COBOL --------------------".
display " | myVal = " myVal with conversion.
display " | arg1 = " arg1 with conversion.
display " | arg2 = " arg2 with conversion.
display " | arg3 = " arg3 with conversion.
display " | arg4 = " arg4 with conversion.
display " | retVal = " retVal with conversion.
add arg1 arg2 arg3 arg4 giving arg1 myVal.
display " + After add arg1 arg2 arg3 arg4 giving arg1 myVal:".
display " | myVal = " myVal with conversion.
display " | arg1 = " arg1 with conversion.
display " | arg2 = " arg2 with conversion.
display " | arg3 = " arg3 with conversion.
display " | arg4 = " arg4 with conversion.
display " | retVal = " retVal with conversion.
display " +---------------------------------------------------".
Note that the C program progc.c does not have a function called
main
. The
function name "main" has to be renamed, because the COBOL RTL already
contains a symbol called
main
on Windows NT Alpha. To resolve this, progc.c is
called from a dummy COBOL program called progmain.cob. On Tru64 UNIX, if a
COBOL routine is not the main program, you need to call cob_init.
Here is progmain.cob:
identification division.
* file progmain.cob
program-id. progmain.
procedure division.
s1.
call "mainx".
stop run.
end program progmain.
The return value from the COBOL program is an
int
. Therefore, it is customary
to use the
int
data type for the variables in C and COBOL programs that are
passed back and forth. For example,
retval
,
arg1
,
arg2, arg3,
and
arg4
are
declared as
int
and
pic(9)
in the C and COBOL programs, respectively.
Here are the commands to compile, link, and run on different platforms:
[OpenVMS] $ cobol PROGMAIN.COB, PROGCOB.COB
$ cc PROGC.C
$ link PROGMAIN.OBJ +PROGCOB.OBJ +PROGC.OBJ (*)
$ run PROGMAIN.EXE
[UNIX] % cobol progmain.cob progcob.cob progc.c (*)
% a.out
Interprogram Communication 1223