R Integration with SAP HANA, SAP Blogs

blockchain r package

For the beginners it would be truly helpful to go after the below steps and a slick integration with R studio , love accessing HANA artifacts lightly like accessing the tables/view information & Consuming procedures , intention is to let the people know the integration & want to share more later on this topic once I am friendly in “R” development style – “still in learning mode” J.

Setup the Data source (in this case SAP HANA DB Server)

If you are already working on HANA Studio then you may have the HANA Studio Installed & HANA Client as well if not then you can install , refer below link.

Eclipse with HANA Implements Plugin is used

(-> same as HANA Studio) + download link for HANA Client Software

Once you have installed HANADBClient in your system then you need to setup data source.

Go to -> Control Panel -> Search for data Source (ODBC) -> Set up data sources (ODBC)

You will get the below popup

On Current tab click on Add one popup will emerge for Server/Port information

Inject any data source name/any description for server ad then inject server: port – if you don’t know the server and port name go to your hana studio (SAP HANA Development perspective) and right click on system then click on properties tab -> Extra properties tab -> Host details. After injecting these details click on connect to check if the details are correct or not by coming in the username/password if all ok then you get a prompt on connect that connection is successful.

Once you are done with above now download the R Studio (https://www.rstudio.com/ ) and R package (https://cran.r-project.org/ )

Now install both the Components once you are done with R Studio installation download the RODBC package (https://cran.r-project.org/web/packages/RODBC/index.html ) goto your R Studio now & all install r Studio package.

Once we have added the RODBC package now we can check on R studio using library function

Now we can go ahead for accessing our HANA database artifacts, establish the database connection using R instructions & then execute sqlQuery function for executing sql guidelines on R.

I created one table in HANA server for billing docs that I am accessing using “R” below is the sample code.

Here is the output from “R”

Another sample for consuming procedure in “R”

I created one procedure which comes back Company Code , Accounting doc & fiscal year from BSEG table.

Note – you can also use hdbuserstore set default for storing username/password for you hana server hence you don’t need to expose that into your connection string , below link elaborates the way of securing your username/password when dealing with ODBC –

The secure user store is installed with the SAP HANA client package. After you install the SAP HANA client, the hdbuserstore program is located in one for the following directories:

  • /usr/sap/hdbclient (Linux/UNIX)
  • %SystemDrive%\Program Files\sap\hdbclient (Microsoft Windows)

Your suggestions/questions/improvements are most welcome, I will attempt to share more sample codes I progress in this.

Related video:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *