Quantcast
Channel: SAP HANA Central
Viewing all articles
Browse latest Browse all 711

R Integration with SAP HANA

$
0
0
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

R Integration with SAP HANA

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

R Integration with SAP HANA

Enter any data source name/any description for server ad then enter 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 -> Additional properties tab -> Host details. After entering these details click on connect to check if the details are correct or not by entering the username/password if all ok then you get a prompt on connect that connection is successful.

R Integration with SAP HANA

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.

R Integration with SAP HANA

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

R Integration with SAP HANA

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

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

library (‘RODBC’)

ch<-odbcConnect(“data source name”,uid=”test_hana”,pwd=”test12″);

sqlQuery(ch, ‘SELECT * FROM “_SYS_BIC”.”BILLING_DATA” ‘)

result ->

Here is the output from “R”

R Integration with SAP HANA

Another sample for consuming procedure in “R”

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

sqlQuery(ch, ‘CALL “ABAPDEMO”.”GETDATA”(10 , ? )’);

Output in “R”

R Integration with SAP HANA

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 –

https://help.sap.com/saphelp_hanaplatform/helpdata/en/dd/95ac9dbb571014a7d7f0234d762fdb/content.htm

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)

Viewing all articles
Browse latest Browse all 711

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>