The following example shows a COBOL program that calls a C++ function by using a CALL statement that passes arguments BY REFERENCE.
COBOL program driver:
cbl pgmname(mixed)
Identification Division.
Program-Id. "driver".
Data division.
Working-storage section.
01 A pic 9(8) binary value 11111.
01 B pic 9(8) binary value 22222.
01 R pic 9(8) binary.
Procedure Division.
Display "Hello World, from COBOL!"
Call "sub" using by reference A B
returning R
Display R
Stop Run.
C++ function sub:
#include <iostream.h>
extern "C" long sub(long& A, long& B) {
cout << "Hello from C++" << endl;
return A + B;
}
Output:
Hello World, from COBOL! Hello from C++ 00033333
related tasks
Passing data between COBOL and C/C++
related references
CALL statement (COBOL for AIX Language Reference)