C3 AI Documentation Home

SAP HANA Connector

The C3 Agentic AI Platform has a built-in Java Database Connectivity (JDBC) connector for integrating with SAP HANA databases.

To connect to SAP HANA from your application:

  1. Add a SqlSourceSystem modeling the SAP HANA source system to your package.
  2. Configure the JdbcCredentials authorizing the connection to the external SAP HANA database.
  3. Add a SqlSourceCollection modeling the target SAP HANA table to your package.
  4. Create an External Type modeling the schema of the external SAP HANA table.

For more information, see the SAP HANA Getting Started Guide and JDBC Connection Properties.

Model the source system

Create a SqlSourceSystem and set the name field as the identifier for the external database system.

For example, add the following SAPSourceSystem.json to the \metadata\SqlSourceSystem directory of your package:

JSON
{
    "name": "SAPSourceSystem"
}

Configure the credential used to authorize the JDBC connection

Create a JdbcCredentials Type instance to configure the connection to the external SAP HANA database.

JavaScript
var credsRaw = {
    "name": "< USER_DEFINED_NAME >",
    "url": "jdbc:sap://< SERVER_HOSTNAME >:443/?databaseName=< DATABASE_NAME >&encrypt=true&validateCertificate=false",
    "username": "< DB_USERNAME >",
    "password": "< DB_PASSWORD >",
    "datastore": DatastoreType.HANA
    }

creds = JdbcCredentials.make(credsRaw)

SqlSourceSystem.forName("SAPSourceSystem").setCredentials(creds);

Model the table containing the data

To model the external SAP HANA table in your application, create a SqlSourceCollection and set the following fields:

  • name: Identifier for the SAP HANA table
  • source: Name of the External Type that models the schema of the external SAP HANA table
  • sourceSystem: Name of the SAP HANA SqlSourceSystem

For example, to model a table called DataTypesExample, add the following DataTypesExample.json to the \metadata\SqlSourceCollection directory of your package:

JSON
{
    "name": "DataTypesExample",
    "source": "DataTypesExample",
    "sourceSystem": 
    {
      "type": "SqlSourceSystem",
      "name": "SAPSourceSystem"
    }
}

Model the table schema

To model the schema of the SAP HANA table in your application, create an External entity Type. Give the entity Type a schema name that matches the name of the SAP HANA table exactly. The schema name is case sensitive.

Start by adding the following DataTypesExample.c3typ file to the \src directory of your package:

Type
entity type DataTypesExample mixes External, NoSystemCols schema name 'DBADMIN.DATA_TYPES_EXAMPLE'

For the DataTypesExample table, the schema name is a qualified name: the database user and the table name, separated by a dot. Use the inferSourceType() method to see the C3 AI data types that the platform infers from the source data types of the table:

JavaScript
var schema = SqlSourceCollection.forName("DataTypesExample").inferSourceType().declaredFieldTypes;

var myObject = {};
for (let i = 0; i < schema.length; i++) {
        schemaName = schema[i].schemaName;
        myObject[schemaName] = schema[i].valueType.name;
    }

Inferred C3 data types for each column of the SAP HANA table

The platform maps SAP HANA data types to C3 AI data types according to the following table:

SAP HANA Data TypesC3 AI Data Types
DATE, TIME, SECONDDATE, TIMESTAMPdatetime, string, datetime, datetime
TINYINT, SMALLINT, INTEGER, BIGINT, SMALLDECIMAL, DECIMAL, REAL, DOUBLEint32, int32, int32, int, decimal, decimal, float, double
BOOLEANboolean
VARCHAR, NVARCHAR, ALPHANUM, SHORTTEXTstring
VARBINARYbinary
BLOB, CLOB, NCLOB, TEXTbinary, string, string, string
REAL_VECTORstring
ST_GEOMETRY, ST_POINTstring

To validate the type inference, view the source data types:

JavaScript
SqlSourceCollection.forName("DataTypesExample").connect().columns;

Source columns of the SAP HANA table with their data types

Complete the External entity Type definition:

Type
entity type DataTypesExample mixes External, NoSystemCols schema name 'DBADMIN.DATA_TYPES_EXAMPLE' {
  id: ~ schema name "VARCHAR_COL"
  bigIntCol: int schema name "BIGINT_COL"
  binaryCol: binary schema name "BINARY_COL"
  blobCol: binary schema name "BLOB_COL"
  booleanCol: boolean schema name "BOOLEAN_COL"
  charCol: string schema name "CHAR_COL"
  dateCol: datetime schema name "DATE_COL"
  decimalCol: decimal schema name "DECIMAL_COL"
  doubleCol: double schema name "DOUBLE_COL"
  integerCol: int32 schema name "INTEGER_COL"
  nCharCol: string schema name "NCHAR_COL"
  nClobCol: string schema name "NCLOB_COL"
  nVarCharCol: string schema name "NVARCHAR_COL"
  realCol: float schema name "REAL_COL"
  realVectorCol: string schema name "REAL_VECTOR_COL"
  secondDateCol: datetime schema name "SECOND_DATE_COL"
  smallDecimalCol: decimal schema name "SMALLDECIMAL_COL"
  smallIntCol: int32 schema name "SMALLINT_COL"
  timestampCol: datetime schema name "TIMESTAMP_COL"
  tinyIntCol: int32 schema name "TINYINT_COL"
  varBinaryCol: binary schema name "VARBINARY_COL"
  varCharCol: string schema name "VARCHAR_COL"
}

The example DataTypesExample Type uses the VARCHAR_COL column as the id field.

Read data from the table

After you complete the External entity Type definition, validate the configuration. Call DataTypesExample.fetch() to fetch the External Type data from the SAP HANA table.

DataTypesExample record fetched from SAP HANA

See also

Was this page helpful?