Interprogram Communication
12.6 Calling Compaq COBOL Programs from Other Languages
Example 12–10 C Program Using cobcall, cobfunc, and cobcancel
/* File: progc.c */
#include "stdlib.h"
#include "stdio.h"
/* printf */
#include "string.h"
/* strlen */
void
cobcancel(char *name);
int
cobcall
(char *name, int argc, char **argv);
int
cobfunc
(char *name, int argc, char **argv);
extern int progcob();
/* COBOL returns int */
int
retval = 0;
/* progcob returns int */
char *a_list[NUMARGS];
/* progcob needs 4 args */
int arg1 = 1, arg2 = 2, arg3 = 3, arg4 = 4;
a_list[1] = (char *) &arg2;
/* address of 2nd arg */
a_list[2] = (char *) &arg3;
/* address of 3rd arg */
a_list[3] = (char *) &arg4;
/* address of 4th arg */
retval = cobcall("progcob", NUMARGS, a_list);
display("[1] After calling cobcall:", retval, arg1);
display("[2] After calling cobfunc:", retval, arg1);
retval = cobcall("progcob", NUMARGS, a_list);
display("[3] After calling cobcall again:", retval, arg1);
display("[4] After calling cobcancel:", retval, arg1);
retval = cobcall("progcob", NUMARGS, a_list);
display("[5] After calling cobcall again:", retval, arg1);
}
unsigned int i = 0;
printf("\n%s\n", s);
for (i = 0; i < strlen(s); i++) printf("=");
printf("\n
retval = %d", r);
printf("\n
arg1
= %d", a);
printf("\n");
}
Following is progcob.cob, the COBOL program that is called by the C program:
Example 12–11 COBOL Called Program "PROGCOB"
identification division.
* File progcob.cob
**************************************************************
* The C program calls this COBOL program with four arguments:
*
arg1, arg2, arg3, arg4.
*
* This program performs:
*
arg1, myVal get the value of arg1 + arg2 + arg3 + arg4
*
* When cobfunc or cobcancel is called the values in
* working-storage are reset to their initial values.
*
* retVal: to demonstrate the value returned by this program.
* myVal : to demonstrate cobcancel in the C program
* arg1
: to demonstrate cobcall and cobfunc in the C program.
**************************************************************
(continued on next page)
12–22 Interprogram Communication
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......