|
DB2 Example: Invoker Source Code
/*********************************************************************/
/* SQL Parameter Style Example */
/* -Source code for Procedure Invoker */
/* */
/* Compile Steps: */
/* CRTSQLCI OBJ(KMTEST/CALLPGM2) SRCFILE(KMTEST/SRC) COMMIT(*NONE) */
/* OUTPUT(*PRINT) OPTION(*GEN *SQL) DBGVIEW(*SOURCE) */
/* */
/* CRTPGM PGM(KMTEST/CALLPGM2) MODULE(*PGM) DETAIL(*FULL) */
/* COMMIT(*NONE) */
/* */
/*********************************************************************/
#include
#include /* standard library */
#include /* incl. strg fnctns. */
/* Declarations for expected message */
unsigned char exp_errmc[70] = "Possible Problem Encountered";
/* ch error msg in sqlca */
short exp_errml = 28; /* sqlca error msg length */
/* */
exec sql include sqlca;
main(int argc,char *argv[])
{ /* Start of mainline */
unsigned char inpVar[7]="INPVAL"; /* For parameter - input */
unsigned char outVar[7]=" "; /* For parameter - out */
short int inpIndicator=0; /* Indicator parameter-input */
short int outIndicator=0; /* Indicator parameter-out */
/********************************************************************/
/* Create the Procedure */
/********************************************************************/
exec sql
CREATE PROCEDURE sptest.stylesql
(IN inparm char(6)), OUT outparm char(6))
LANGUAGE C EXTERNAL NAME sptest.stylepgm
PARAMETER STYLE SQL;
/********************************************************************/
/* Call the Procedure */
/********************************************************************/
exec sql
CALL sptest.stylesql(:inpVar :inpIndicator, :outVar :outIndicator);
if ((SQLCODE == -443) && (strncmp(SQLSTATE,"38999",5) == 0))
{
printf("Error in SP SQLSTATE \n");
}
if ((sqlca.sqlerrml == exp_errml) &&
(!strncmp(sqlca.sqlerrmc, exp_errmc, exp_errml)))
{
printf("Potential error message sent by Procedure\n");
}
/* Test the output of the stored procedure */
if (!strncmp(outVar,"INPVAL",6))
{
; /* Stored Procedure call returned what was expected */
}
}
|