saprfc

call SAP ABAP Code from Golang (Remote Function Call)

Github stars Tracking Chart

SAP NW RFC Connector for GO

this is only a fork, but it seems that origin is very static

all credit for this code goes to @bsrdjan

The saprfc package provides bindings for SAP NW RFC Library, for an easy way of interacting with SAP systems

The goal of this fork is the best possible compatibility with Linux, if you want work with Windows use the original package

Table of contents

Badges

GoDoc
Go Report Card
codebeat badge
license

automatic CI Tests are not possible since the SAP library SAP NW RFC is not open source

Platforms and Prerequisites

The SAP NW RFC Library is a prerequsite for using the GO RFC connector and must be installed on a same system. It is available on platforms supported by GO, except OSX.

A prerequisite to download SAP NW RFC Library is having a customer or partner account on SAP Service Marketplace . If you are SAP employee please check SAP OSS note 1037575 - Software download authorizations for SAP employees.

SAP NW RFC Library is fully backwards compatible, supporting all NetWeaver systems, from today, down to release R/3 4.0. You can always use the newest version released on Service Marketplace and connect to older systems as well.

Install

To start using SAP NW RFC Connector for GO, you shall:

  1. Install and Configure Golang
  2. Install SAP NW RFC Library for your platform
  3. Install SAPRFC package

Install SAP NW RFC Library

To obtain and install SAP NW RFC Library from SAP Service Marketplace, you can follow the same instructions as for Python or nodejs RFC connectors.
The Download is here, but the SAP page is the worst, maybe it's better to search for a torrent or ask a friend at SAP.

Install SAPRFC

To install saprfc and dependencies, run following commands:

export CGO_CFLAGS="-I $SAPNWRFC_HOME/include"
export CGO_LDFLAGS="-L $SAPNWRFC_HOME/lib"
go get simonwaldherr.de/go/saprfc
cd $GOPATH/src/simonwaldherr.de/go/saprfc
go build
go install

Getting Started

See the hello_gorfc.go example and saprfc_test.go unit tests.

The GO RFC Connector follows the same principles and the implementation model of Python and nodejs RFC connectors and you may check examples and documentation there as well.

package main

import (
    "fmt"
    "simonwaldherr.de/go/golibs/arg"
    saprfc "simonwaldherr.de/go/saprfc"
    "time"
)

var SAPconnection *saprfc.Connection

func printTable(table string) {
    params := map[string]interface{}{
        "QUERY_TABLE": table,
        "DELIMITER":   ";",
        "NO_DATA":     "",
        "ROWSKIPS":    0,
        "ROWCOUNT":    0,
    }
    r, err := SAPconnection.Call("RFC_READ_TABLE", params)
    if err != nil {
        fmt.Println(err)
        return
    }

    echoStruct := r["DATA"].([]interface{})
    for _, value := range echoStruct {
        values := value.(map[string]interface{})
        for _, val := range values {
            fmt.Println(val)
        }
    }
    return
}

func main() {
    arg.String("table", "USR01", "read from table", time.Second*55)
    arg.String("dest", "", "destination system", time.Second*55)
    arg.String("client", "", "client", time.Second*55)
    arg.String("user", "RFC", "username", time.Second*55)
    arg.String("pass", "", "password", time.Second*55)
    arg.String("lang", "DE", "language", time.Second*55)
    arg.String("host", "127.0.0.1", "SAP server", time.Second*55)
    arg.String("sysnr", "00", "SysNr", time.Second*5)
    arg.String("router", "/H/127.0.0.1/H/", "SAP router", time.Second*55)
    arg.Parse()

    SAPconnection, _ = saprfc.ConnectionFromParams(saprfc.ConnectionParameter{
        Dest:      arg.Get("dest").(string),
        Client:    arg.Get("client").(string),
        User:      arg.Get("user").(string),
        Passwd:    arg.Get("pass").(string),
        Lang:      arg.Get("lang").(string),
        Ashost:    arg.Get("host").(string),
        Sysnr:     arg.Get("sysnr").(string),
        Saprouter: arg.Get("router").(string),
    })

    printTable(arg.Get("table").(string))

    SAPconnection.Close()
}

To Do

  • Improve the documentation
  • Fix Windows compiler flags

References

Main metrics

Overview
Name With OwnerSimonWaldherr/saprfc
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:Apache License 2.0
所有者活动
Created At2016-05-29 18:39:36
Pushed At2018-11-07 15:04:29
Last Commit At2018-11-07 16:04:28
Release Count0
用户参与
Stargazers Count14
Watchers Count2
Fork Count6
Commits Count12
Has Issues Enabled
Issues Count2
Issue Open Count0
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private