16.20 - Example Using FNC_CallSP - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void xsp_getregion ( VARCHAR_LATIN *region,
                     char          sqlstate[6])
{

  void  *argv[2];
  int    ind[2];
  parm_t dtype[2];
  INTEGER regionCount;   /* OUT argument from addRegion */

  /* Set the pointers to the stored procedure arguments */
  argv[0] = region;         /* IN */
  argv[1] = &regionCount;   /* OUT */

  /* Set the indicator for the IN argument */
  ind[0] = 0;
  memset(dtype, 2, sizeof(parm_t)*2);

  /* Data type for the VARCHAR IN argument */
  dtype[0].datatype = VARCHAR_DT;
  dtype[0].direction = IN_PM;
  dtype[0].charset = LATIN_CT;
  dtype[0].size.length = strlen((const char *)region);

  /* Data type for the INTEGER OUT argument */
  dtype[1].datatype = INTEGER_DT;
  dtype[1].direction = OUT_PM;
  FNC_CallSP((SQL_TEXT *)"addRegion", 2, argv, ind, dtype, sqlstate);  

  if (strcmp(sqlstate, "00000") != 0)
      return;

  ...
}