


COBOL routines may be called from C routines. To accomplish this, you call the C function "cobol".
The first parameter passed to "cobol" is the name of the COBOL routine to call. This is resolved just as the name specified in a CALL statement is resolved.
The second parameter is the number of USING parameters you are passing.
The final parameter is an array that contains the USING parameters. This array is of type "Argument" and is described in detail in section C.3.2 under the discussion of the args parameter. Note that only the "a_address" and "a_length" fields need be supplied, although the other fields may be supplied also.
Programs that call the "cobol" routine must be sure to include "sub.h" (included with ACUCOBOL-GT in the "lib" directory). This includes a declaration of the "cobol" routine for all platforms. This ensures that you use the correct calling convention when calling the "cobol" routine. Refer to Appendix M (Host Specific Information) for details about calling subroutines that are located in DLLs.
The "cobol" function returns "0" if successful and "-1" if it fails. If the call fails, the external short integer "A_call_err" will contain the reason why the call failed. This will be one of the following values:
01 - Program file missing or inaccessible
02 - Called file not a COBOL program
03 - Corrupted program file
04 - Inadequate memory available to load program
05 - Unsupported object code version number
06 - Recursive CALL of a program
Example:
call_cobol ( str, length )
char *str;
int length;
{
Argument args[1];
args[0].a_address = str;
args[0].a_length = length;
if ( cobol ( "MYPROG", 1, args ) ) {
printf ("can't load MYPROG, reason code = %d\n",
A_call_err );
}
}