Calling A Cobol Program From C; C Include File Cobfunc.h - Compaq COBOL AAQ2G1FTK User Manual

Compaq computer accessories user manual
Table of Contents

Advertisement

Interprogram Communication
12.6 Calling Compaq COBOL Programs from Other Languages
Example 12–7 Calling a COBOL Program from C
#include <stdio.h>
#include "cobfunc.h"
extern int calledfromc();
main(int argc, char **argv)
{
char *arg1="arg1_string";
char *arg2="1234";
int arg3 = 16587;
int func_result;
char *arglist[10];
#ifdef __osf__
cob_init(argc, argv, NULL);
#endif
arglist[0] = arg1;
arglist[1] = arg2;
arglist[2] = (char *) &arg3;
func_result = cobfunc ("calledfromc", 3, arglist);
}
Example 12–8 C Include File cobfunc.h
void cobcancel ( /* CANCEL the named COBOL routine */
char *name
);
int cobcall (
char *name, /* READ: name of the program */
int argc,
char **argv /* READ: array of pointers to the arguments */
);
int cobfunc (
char *name, /* name of the program */
int argc,
char **argv /* array of pointers to the arguments */
);
#ifdef __osf__
void cob_init (
int argc,
char **argv,
char **envp
);
#endif
Note that argv[0] is the first argument to pass and argv[n-1] is the nth. The
maximum number of arguments supported is 254.
For Tru64 UNIX programs, if the main routine is written in C, it must call
cob_init. (See Section 12.1.2, Calling Procedures.) The Compaq COBOL program
must expect its arguments by reference.
12–20 Interprogram Communication
/* Call a COBOL program from a C routine */
/* READ: how many arguments */
/* Call a COBOL program from a C routine, then CANCEL it */
/* how many arguments */
/* init the RTL */
/* argument count */
/* arguments */
/* environment variable pointers */

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?

Table of Contents