Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow
Execute Native SQL on HANA Database from ABAP using Secondary Database Connection
I have recently created a secondary database connection to SAP HANA database with a valid HANA database user authorization data using DBCO transaction code.
This tutorial shows how to run native SQL or SQLScript using an ABAP program on a SAP HANA database.
Let's create a very simple Column Table on SAP HANA database using following Create Table DDL command.
Then populate new table with sample data using INSERT commands.
Let's now try to execute a native SQL SELECT query from ABAP program.
If you refer to ABAP tutorial on how to create database connection for SAP HANA database, you will be able to create a secondary connection to the target HANA database.
Then as seen in following ABAP program, first declare your type and internal table definitions in your code that will match to sample HANA database table.
Second section includes declaration of objects from SAP ADBC ABAP Database Call Interface package including object in Database Connection CL_SQL_CONNECTION class type.
This object with type CL_SQL_CONNECTION enables ABAP programmers to create a connection to HANA database and execute SQL statements via this connection.
ABAP programmers can add following objects into theri debug list and check how their properties are set with each executed ABAP code line.
Please note that when NEXT_PAGE() method is executed, the internal table is populated with data from native SQL command execution on the HANA database.
Without closing the database connection, ABAP programmers can execute a second query in a similar way to shown in below.
Please note that the programmer should add type and data definitions for the second query too, which I did not repeat the similar ABAP code lines here.