COBOL programs can call and be called by programs written in other languages. However, some languages handle calls differently from COBOL. For example, some language pass parameters in the opposite order from that expected by COBOL programs. To enable COBOL and non-COBOL programs to call each other, you can adjust the calling mechanisms that the COBOL program uses or that it expects to be used.
To specify the calling mechanisms you require, you first construct the call convention number that produces the required mechanisms. The call convention number is a 16-bit number defined as follows:
Bit | Meaning | ||||
---|---|---|---|---|---|
0 |
|
||||
1 |
|
||||
2 |
Any RETURNING phrase is not affected by this bit |
||||
3 |
|
||||
4 | Reserved (always 0) | ||||
5 | Reserved (always 0) | ||||
6 |
|
||||
This has no effect on dynamic calls, but alters the call name on static-linked calls | |||||
7 | Reserved (always 0) | ||||
8 |
|
||||
9 |
|
||||
This call-convention is an instruction to the generator on how to treat the text of a quoted program name or call-name when litlinking. If this bit is 0 the case of the program or call-name might still be significant depending on the CASE generator directive. | |||||
10-15 | Reserved (always 0) |
When you have constructed the call convention number, you convert it to a decimal number, and then assign this decimal number to a name, by defining it the Special Names paragraph. You then use the call convention name in the CALL statement.
For example, if you define the following call conventions:
SPECIAL-NAMES. CALL-CONVENTION 0 IS Microsoft-c CALL-CONVENTION 3 IS Pascal.
you can then use one convention when calling a C program as follows:
CALL Microsoft-c "routine-name" USING parameter-1,parameter-2
and use the other convention when receiving a call from a Pascal program, such as:
PROCEDURE DIVISION Pascal USING parameter-1,parameter-2
If you do not specify a call convention, the standard COBOL convention (call-convention 0) is assumed.
Related Topics: