Sample N-Way ILC applications
Figure 1. PL/I main
routine of ILC application
*Process lc(101),s,map,list,stmt,a(f),ag;
NWAYILC: PROC OPTIONS(MAIN);
/*Module/File Name: IBMNWAY
/***********************************************************/
/* FUNCTION : Interlanguage communications call to a *
/* C program which in turn calls a *
/* COBOL program. *
/* *
/* Our example illustrates a 3-way interlanguage call from *
/* a PL/I main program to a C program and from C to *
/* a COBOL subroutine. PL/I initializes an array to zeros. *
/* PL/I passes the array and an empty character string to *
/* C program NWAY2C. NWAY2C fills the numeric array with *
/* random numbers and a C character array with lowercase *
/* letters. A COBOL program, NWAY2CB, is called to convert*
/* the characters to uppercase. The random numbers array *
/* and the string of uppercase characters are returned *
/* to PL/I main program and printed. *
/***********************************************************/
/***********************************************************/
/* DECLARES FOR THE CALL TO C *
/***********************************************************/
DCL J FIXED BIN(31,0);
DCL NWAY2C EXTERNAL ENTRY RETURNS(FIXED BIN(31,0));
DCL RANDS(6) FIXED BIN(31,0);
DCL STRING CHAR(80) INIT('Initial String Value');
DCL ADDR BUILTIN;
RANDS = 0;
PUT SKIP LIST('NWAYILC STARTED');
/**********************************************/
/*Pass array and an empty string to C. */
/**********************************************/
J = NWAY2C( ADDR( RANDS ), ADDR( STRING ) );
PUT SKIP LIST ('Returned from C and COBOL subroutines');
IF (J = 999) THEN DO;
PUT EDIT (STRING) (SKIP(1) , A(80));
PUT EDIT ( (RANDS(I) DO I = 1 TO HBOUND(RANDS,1)) )
(SKIP(1) , F(10) );
END;
ELSE DO;
PUT SKIP LIST('BAD RETURN CODE FROM C');
END;
PUT SKIP LIST('NWAYILC ENDED');
END NWAYILC;
Figure 2. C routine
called by PL/I in
a 3-way ILC application
/*Module/File Name: EDCNWAY */
/******************************************************************
* NWAY2C is invoked by a PL/I program. The PL/I program passes *
* an array of zeros and an UNINITIALIZED character string. *
* NWAY2C fills the array with random numbers. It fills the *
* character string with lowercase letters, calls a COBOL *
* subroutine to convert them to uppercase (NWAY2CB), and returns *
* to PL/I. The by reference parameters are modified. *
******************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <leawi.h>
#ifdef __cplusplus
extern "PLI" int NWAY2C (int *c_array 6 , char *chrptr 80 );
extern "COBOL" void NWAY2CB(char *);
#else
#pragma linkage (NWAY2C,PLI)
#pragma linkage (NWAY2CB,COBOL)
void NWAY2CB(char *);
#endif
int NWAY2C (int *c_array 6 , char *chrptr 80 )
{
int *pRns ;
char *pChr ;
char string 80 = "the random numbers are";
int i, ret=999;
fprintf(stderr,"NWAY2C STARTED\n");
/********************************************************/
/* Check chrptr from PLI to verify we got what expected *
/********************************************************/
if(strncmp(*chrptr, "Initial String Value", 20))
{
fprintf(stderr,
"NWAY2C: chrptr not what expected.\n \"%s\"\n", *chrptr);
--ret;
}
/********************************************************/
/*Fill numeric array parameter with random numbers. *
/*Adjust for possible array element size difference. *
/********************************************************/
pRns = *c_array;
for (i=0; i < 6; ++i)
{
pRns i = rand() ;
fprintf(stderr,"pRns %d = %d\n",i,pRns i );
}
/********************************************************/
/* Call COBOL to change lowercase characters to upper. *
/********************************************************/
NWAY2CB(*chrptr);
if(strncmp(*chrptr, "INITIAL STRING VALUE", 20))
{
fprintf(stderr,
"NWAY2C: string not what expected.\n \"%s\"\n", *chrptr);
--ret;
}
fprintf(stderr,"NWAY2C ENDED\n");
return(ret);
}
Figure 3. COBOL program
called by C in
a 3-way ILC application
CBL QUOTE
*Module/File Name: IGZTNWAY
*************************************************
** NWAY2CB is called and passed an 80-character *
* lowercase character string by reference. *
* The string is converted to uppercase and *
* control returns to the caller. *
*************************************************
ID DIVISION.
PROGRAM-ID. NWAY2CB.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
77 STRING-VAL PIC X(80).
PROCEDURE DIVISION USING STRING-VAL.
DISPLAY "NWAY2CB STARTED".
MOVE FUNCTION UPPER-CASE (STRING-VAL)
TO STRING-VAL.
DISPLAY "NWAY2CB ENDED".
GOBACK.