Interprogram Communication
12.6 Calling Compaq COBOL Programs from Other Languages
Example 12–11 (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 12–23
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......