Sample ILC applications
Figure 1 and Figure 2 contain an example of an ILC application. The C++ routine CPP1 statically calls the COBOL CBL1 program. CBL1 statically CALLs C++ routine CPP2.
Figure 1. Static call from C++ to COBOL program
/* Module/File Name: EDCXCB */
/******************************************************************/
/* Illustration of Interlanguage Communication between C++ */
/* and COBOL. All parameters passed by reference. */
/* */
/* CPP1 ---------> CBL1 ---------> CPP2 */
/* static static */
/* call call */
/******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern "COBOL" {
void CBL1(short *, long, float, char *);
void CPP2( int& num, char * newstring);
}
/********************* CPP1 routine example ***********************/
int main()
{
signed short int short_int = 2;
signed long int long_int = 4;
double floatpt = 8.0;
char string[80];
CBL1( &short_int, long_int, floatpt, string );
fprintf(stderr,"main ENDED\n");
}
void CPP2( int& num, char* newstring)
{
fprintf(stderr,"num is %d, newstring is %s\n",num,newstring);
fprintf(stderr,"CPP2 ended\n");
}
Figure 2. Static call from COBOL to C++ routine
* CBL LIB,QUOTE
*Module/File Name: IGZTXCB
****************** CBL1 routine example ********************
IDENTIFICATION DIVISION.
PROGRAM-ID. CBL1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 var1 PIC S9(9) BINARY VALUE 5.
01 msg-string PIC X(80).
LINKAGE SECTION.
77 int2 PIC S9(4) BINARY.
77 int4 PIC S9(9) BINARY.
77 float COMP-2.
77 char-string PIC X(80).
PROCEDURE DIVISION USING int2 int4 float char-string.
DISPLAY "CBL1 STARTED".
IF (int2 NOT = 2) THEN
DISPLAY "INT2 NOT = 2".
IF (int4 NOT = 4) THEN
DISPLAY "INT4 NOT = 4".
IF (float NOT = 8.0) THEN
DISPLAY "FLOAT NOT = 8".
* Place null-character-terminated string in parameter
STRING "PASSED CHARACTER STRING", X'00' LOW-VALUE
DELIMITED BY SIZE INTO msg-string
* MAKE A STATIC CALL TO C FUNCTION
CALL "CPP2" USING var1, msg-string.
DISPLAY "CBL1 ENDED".
GOBACK.