Skip to Content
Technical Articles
Author's profile photo Praveer Kumar Sen

SAP HANA and Go Language


Why let the Pandemic interfere with your hunger for knowledge?

Here’s a learning on Go Language which doesn’t belongs to SAP but which has given several options to connect with databases like HDB, MySQL, etc.

Golang Information, IDE’s and basic Setting:

Go programming language is a statically-typed language with syntax similar to that of C. It provides garbage collection, type safety, dynamic-typing capability, many advanced built-in types such as variable length arrays and key-value maps.

Below are the few important links to learn more about Go Language:

  4.        (An online editor to practice go language)

Below are the steps to configure and validate Go Language Environment in your local system:

  1. Download binary release of installation based on your OS from
  2. Below is the initial command to check version, environment and helps
    1. go version
    2. go env
    3. go help


  1. IDE can be used for further go language programming:
    1. VS Code               :                                                                                                  (Required extension need to be installed before start programming )
    2. Goland                 :     
    3. Atom-IO               :     


1st Hello Go ? Language sample Program and save with. go extension:


Output can be seen by using command prompt:

I have used GitBash to execute all Go language programs, below is the command to execute go program file:


Go Language and oData:

Go language has given pre-installed package(net/http) to consume data from oData services.

Below are the details of oData, which I have generated in local HXE server:


To consume this oData service, a deep structure needs to be maintained to map the oData service information into respective fields using a new HTTP request from HTTP package.

Go language has JSON package  with different types of functionality to maintain or read information accordingly.

Below is the USL and a request method using net/http package of Go language.

Then calling the below function to set user id and password to consume the oData result.

I have used below code to skip initial level of proxy setting, as this is local server. This code won’t be required, if we try to consume oData service from any of valid secure server. (I have tried this to consume oData service created in HANA trial cloud server)

Go language uses structures to maintained data which received from oData service. Since the received data into JSON format, which need to be unmarshal ( to defined structure. Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.

Below function need to be called to map the received JSON format information to defined structure.

Below is the raw format of the received data based on maintained structure:

Data stored into HXE server:


Go language supports FOR loop ( in different ways to read range data. I have used to form the received the data into proper readable format:


In next step, I have used template package which is sub-package of HTML ( to form the received information into html table format.

To use a template, a html file should be available and parse into go program to map data into actual HTML file. Below is the template I have used to map received employees information into HTML table:


On executing the GO RUN command in below way, an index.html file will be generating into execution directory.

Final output of index.html file would be:

Go Language and HANA DB Access:

I have gone through below link given by SAP tutorial, to connect HXE server from Go Language.

Addition to above link functionality, I have also tried to fetch record with and without conditions.

HDB has also SQL Commands to fetch records same as other DB.

link has all initial information to use HDB commands in Go language to connectivity, data fetching and other query related functionality.

To do any SQL related activity, go language has provided SQL package , which has pre-defined function to perform different type of activities.

In program, declared a getDbUrl function to maintain HXE server detail as returning string value.

Initially used the SQL open function to check the connectivity from Go language to HXE server by using below code:

Below are the three scenarios:

  1. Program to retrieve the total number of records exist in EMP_MASTER table from HXE server:
  2. Passing condition to fetch specific record from EMP_MASTER table from HXE server:
  3. Program to fetch id, First and last name field value for all records from EMP_MASTER table:

Comment line is another query to fetch specific number of records from the table such as UP TO N ROWS in SAP-ABAP ?

Final output of the all above query would be as below :


Code and Template is available on : github


Lot’s more to learn..


Happy Learning ?


Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.