gorfc

SAP NW RFC Connector for GO

Github星跟踪图

SAP NW RFC Connector for Go

GoDoc
Go Report Card
license

The gorfc package provides bindings for SAP NW RFC Library, for a comfortable way of calling remote enabled ABAP function modules (RFMs) from Go.

The current release is fully functional on Linux and experimental on Windows, see the Issue #1.

Table of contents

Platforms and Prerequisites

The SAP NW RFC Library is a prerequisite for using the Go RFC connector and must be installed on the same system. It is available on many platforms supported by Go, except macOS, Plan 9 and BSD.

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.

The SAP NW RFC Library is fully backwards compatible, supporting all NetWeaver systems, from today, down to release R/3 4.0. You can and should 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 Go
  2. Install the SAP NW RFC Library for your platform
  3. Install the GORFC package

Install and Configure Go

If you are new to Go, the Go distribution shall be installed first, following GO Installation and GO Configuration instructions. See also GO Environment Variables.

Windows Config Example

After running the MSI installer, the default C:\Go folder is created and the GOROOT system variable is set to C:\Go.

Create the Go work environment directory:

cd c:\
mkdir workspace

Set the environment user varialbes GOPATH and GOBIN, add the bin subdirectories to PATH and restart the Windows shell.

GOPATH = C:\workspace
GOBIN = %GOPATH%\bin
PATH = %GOROOT%\bin;%GOBIN%:%PATH%

See also GO on Windows Example.

Linux

The work environment setup works the same way like on Windows and these instructions describe the installation on Ubuntu Linux for example.

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.

Install GORFC

To install gorfc and dependencies, run following commands:

export CGO_CFLAGS="-I $SAPNWRFC_HOME/include"
export CGO_LDFLAGS="-L $SAPNWRFC_HOME/lib"
go get github.com/stretchr/testify
go get github.com/sap/gorfc
cd $GOPATH/src/github.com/sap/gorfc/gorfc
go build
go install

To test the installation, run the example provided:

cd $GOPATH/src/github.com/sap/gorfc/example
go run hello_gorfc.go

Getting Started

See the hello_gorfc.go example and gorfc_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"
    "github.com/sap/gorfc/gorfc"
    "github.com/stretchr/testify/assert"
    "reflect"
    "testing"
    "time"
)

func abapSystem() gorfc.ConnectionParameter {
    return gorfc.ConnectionParameter{
        Dest:      "I64",
        Client:    "800",
        User:      "demo",
        Passwd:    "welcome",
        Lang:      "EN",
        Ashost:    "11.111.11.111",
        Sysnr:     "00",
        Saprouter: "/H/222.22.222.22/S/2222/W/xxxxx/H/222.22.222.222/H/",
    }   
}

func main() {
    c, _ := gorfc.Connection(abapSystem())
    var t *testing.T

    params := map[string]interface{}{
        "IMPORTSTRUCT": map[string]interface{}{
            "RFCFLOAT": 1.23456789,
            "RFCCHAR1": "A",
            "RFCCHAR2": "BC",
            "RFCCHAR4": "ÄBC",
            "RFCINT1":  0xfe,
            "RFCINT2":  0x7ffe,
            "RFCINT4":  999999999,
            "RFCHEX3":  []byte{255, 254, 253},
            "RFCTIME":  time.Now(),
            "RFCDATE":  time.Now(),
            "RFCDATA1": "HELLÖ SÄP",
            "RFCDATA2": "DATA222",
        },
    }   
    r, _ := c.Call("STFC_STRUCTURE", params)

    assert.NotNil(t, r["ECHOSTRUCT"])
    importStruct := params["IMPORTSTRUCT"].(map[string]interface{})
    echoStruct := r["ECHOSTRUCT"].(map[string]interface{})
    assert.Equal(t, importStruct["RFCFLOAT"], echoStruct["RFCFLOAT"])
    assert.Equal(t, importStruct["RFCCHAR1"], echoStruct["RFCCHAR1"])
    assert.Equal(t, importStruct["RFCCHAR2"], echoStruct["RFCCHAR2"])
    assert.Equal(t, importStruct["RFCCHAR4"], echoStruct["RFCCHAR4"])
    assert.Equal(t, importStruct["RFCINT1"], echoStruct["RFCINT1"])
    assert.Equal(t, importStruct["RFCINT2"], echoStruct["RFCINT2"])
    assert.Equal(t, importStruct["RFCINT4"], echoStruct["RFCINT4"])
    //  assert.Equal(t, importStruct["RFCHEX3"], echoStruct["RFCHEX3"])
    assert.Equal(t, importStruct["RFCTIME"].(time.Time).Format("150405"), echoStruct["RFCTIME"].(time.Time).Format("15.
    assert.Equal(t, importStruct["RFCDATE"].(time.Time).Format("20060102"), e/Users/d037732/Downloads/gorfc/README.mdchoStruct["RFCDATE"].(time.Time).Format(".
    assert.Equal(t, importStruct["RFCDATA1"], echoStruct["RFCDATA1"])
    assert.Equal(t, importStruct["RFCDATA2"], echoStruct["RFCDATA2"])

    fmt.Println(reflect.TypeOf(importStruct["RFCDATE"]))
    fmt.Println(reflect.TypeOf(importStruct["RFCTIME"]))

    c.Close()

To Do

  • Improve the documentation
  • Fix Windows compiler flags

References

主要指标

概览
名称与所有者SAP-archive/gorfc
主编程语言Go
编程语言Go (语言数: 2)
平台
许可证Apache License 2.0
所有者活动
创建于2016-01-25 12:07:42
推送于2024-12-13 13:22:16
最后一次提交2024-12-13 14:22:16
发布数2
最新版本名称v0.1.1 (发布于 )
第一版名称v0.1.0 (发布于 2020-05-04 14:04:20)
用户参与
星数100
关注者数20
派生数46
提交数49
已启用问题?
问题数30
打开的问题数10
拉请求数12
打开的拉请求数1
关闭的拉请求数3
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?