C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

Example 7: C Program That Calls a COBOL Function , Example 8: COBOL Function Called by a
C Program , and Example 9: Include File (Prototype Function) shows the contents of three files: a
C program, a COBOL program, and a header file:
Guardian NameOSS NameFile Type
testctestc.cC program
testcobtestcob.cobCOBOL program
cobinclcobincl.hHeader or include file containing
prototype function
In the example files shown on the following pages, file names appear as the OSS versions. If you
are working in the Guardian environment, the file names would be the Guardian versions.
For examples of using TNS C programs to call TNS COBOL functions, see Interfacing to TNS
COBOL (page 119).
Example 7 C Program That Calls a COBOL Function
/* testc.c */
/* #pragma inspect, symbols */
/* #pragma search largec */
#include <stdio.h>
#include "cobincl.h"
short main (void)
{
short ds;
long dl;
char *tx = "Displayed in COBOL";
ds = 100;
dl = 40000;
XCOBFUNC(tx, &ds, &dl);
printf("I am back in C now and program is ending.\n");
}
Example 8 COBOL Function Called by a C Program
The COBOL program for OSS. testcob.cob
================================================================
?env common;innerlist
?SYMBOLS
IDENTIFICATION DIVISION.
PROGRAM-ID. XCOBFUNC.
AUTHOR. MOLLY.
DATE-WRITTEN. 7/25/00.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. TANDEM-K2006.
OBJECT-COMPUTER. TANDEM-K2006.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 D-RESULT PIC S9(09) COMP.
LINKAGE SECTION.
77 D-STRING PIC X(20).
77 D-SHORT NATIVE-2.
Interfacing to Native COBOL 141