(1) Link your C program to call your COBOL program by declaring your C and COBOL functions as follows:
Declare a function in C that passes an integer value (i) to COBOL:
void CBLRTN(int );
CBLRTN(i);
Use the value “I” from the C program in your COBOL program:
01 I PIC S9(9) BINARY.
PROCEDURE DIVISION USING BY VALUE I.
(2) Link your COBOL program to your C program by having the COBOL program call a C function and pass it a value, as follows:
Call the C subroutine “CFUNC” from COBOL, passing the value “I”:
01 I PIC S9(9) BINARY.
CALL "CFUNC" USING BY VALUE I.
Declare the function in C:
void CFUNC(int i) {
return i;
}
(3) Declare a “pragma_linkage” at the top of your C program to explicitly declare a linkage to COBOL, which is required by some compilers. The syntax for the pragma linkage is:
“#pragma linkage(function, COBOL)”.
You declare the pragma linkage and create a C function to pass a value to COBOL as follows:
#pragma linkage(CBLRTN,COBOL)
void CBLRTN(int i);
CBLRTN(i);
You then use the passed variable in your COBOL program as follows:
01 I PIC S9(9) USAGE IS BINARY
PROCEDURE DIVISION USING I.
(4) Declare a “pragma linkage” at the top of your C program to explicitly link the COBOL program to C. This is
required by some compilers. The pragma linkage is always done in the C program, even when the COBOL program is
passing the value to the C program.
You declare the variable in the COBOL program and call the C function as follows:
01 I PIC S9(9) USAGE IS BINARY
CALL 'CFUNC' USING BY CONTENT I.
You then declare the pragma linkage to COBOL and define the function in C as follows:
#pragma linkage(CFUNC,COBOL)
void CFUNC(int p1) {
2012年5月9日 星期三
How to Link COBOL & C Together on z/OS
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言