Did you include this code in your C program since you have BY REFERENCE in your CALL statement?3. COBOL turns on the high order bit of the address of the last parameter when it is passed by reference. This can cause problems in the C program if it is using the address (since it will be treated as a negative number). If a C program does need to use the address of the last parameter, one of the following techniques can be used to bypass this problem:
* If the COBOL program is an Enterprise COBOL program, instead of passing the parameter by reference, pass the address of the item by value. For example, use a call statement that looks like this:
CALL "C" using by value address of C-PARM1
by value address of C-PARM2
* If the COBOL program is not Enterprise COBOL, code needs to be added to mask out the high-order bit in the C routine. The sample code below shows how to do this:
#include <stdio.h>
#include <string.h>
void A1CC01BA(char* myString)
{
myString = (char*)((int)myString & 0x7fffffff);
printf("My String: %s \n", myString);
return;
}
Communicating between programs can be difficult in a single language (considering addressing modes, static versus dynamic calls, and so forth). Adding multiple languages to the mix vastly complicates the communication, especially with two languages so fundamentally different as COBOL and C. It can be done, but the mere fact that there is a manual devoted to nothing but interlanguage communication should indicate how tough the process is.
If I were in your shoes, I'd start by passing a simple structure (or even just a character variable) back and forth to make sure I could get that right. I would then add in the RETURNING phrase with an integer (COBOL PIC S9(09) COMP) value. After verifying that this works, I'd put in one piece at a time until I got the desired data structures going back and forth -- putting multiple things in the interface at once makes it difficult to know what isn't working, precisely. And make sure you use LIST,NOOFFSET on your compile options so you know exactly what COBOL is generating for the CALL -- COBOL doesn't always do what you think it will.