cobcall

Calls a COBOL program, subprogram or entry point from C.
Restriction: This function is supported for native COBOL only.

Syntax:

#include "cobcall.h"

cobrtncode_t cobcall (const cobchar_t *name, int argc, 
                      cobchar_t **argv);

Parameters:

name A null-terminated string that specifies the name of the COBOL program to be called
argc The number of arguments passed in argv
argv Arguments to be passed to the COBOL program

Comments:

This function is used to call the COBOL program of the specified name using the arguments passed in argv.  Parameters are passed BY REFERENCE.

The result of a cobcall() is a COBOL type call as defined in the ANSI '74 standard and behaves in the same way as if the COBOL entry point had been called from COBOL.

Using this function is equivalent to calling a COBOL program directly from C code, using C syntax.

If the specified name is an entry point of an already loaded COBOL program, that program is called. Alternatively, if the specified name is a C function, then that is called. Otherwise, a program with a basename of the specified name is searched for on disk using the following search order: 

  • If the sub-program is already loaded, or is statically linked, it is located and the search ends.
  • If COBPATH is set, the list of paths in the variable are searched, in order; if COBPATH is not set, the current directory is searched.
  • On Windows platforms, if you are calling dynamic link libraries (.dll files) without a specific path, the COBPATH environment variable is searched.
  • The path of the calling program is searched.

If no program of the specified name can be found a run-time error is produced. 

If the COBOL entry point does not expect any arguments then argc should be 0 and argv should be NULL.

Equivalent COBOL Syntax:

call "name" [using ...] [returning ...]

Example:

To call a COBOL entry point cobep with two string arguments from a C function, use either:

cobchar_t *argv[2];
argv[0] = arg1;
argv[1] = arg2;
cobcall("cobep", 2, argv);

or:

cobep(arg1, arg2);