C3 AI Documentation Home

SAP HANA Connector

The C3 Agentic AI Platform has a built-in 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 table.
  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.

The following sections include detailed instructions for configuring the connection. 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, you can 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 >",
    "id": "< USER_DEFINED_ID >",
    "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)

JdbcStore.forName("SAPSourceSystem").setCredentials(creds, ConfigOverride.APP);
JdbcStore.forName("SAPSourceSystem").setExternal(ConfigOverride.APP);

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, you can 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 with a schema name that case-sensitively matches the name of the table in the SAP HANA table.

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 consisting of the database user and table name separated by a dot. You can use the inferSourceType() method to access the table's C3 AI data types, which the platform infers from the source data types.

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;
    }

FieldTypes

SAP HANA data types are mapped 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

You can also access the source data types to validate the type inference:

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

SourceDataTypes

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"
}

In the example DataTypesExample Type, the VARCHAR_COL column is used as the id field.

Read data from the table

After completing the External Entity Type definition, you can validate the configuration by fetching the External Type data from the SAP HANA table.

FetchOutput

See also

Was this page helpful?