Skip to content

SAP-archive/gorfc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecation Notice

This public repository is no longer maintained. Please see this issue for details.


SAP NetWeawer RFC SDK client bindings for GO

For more details on the SAP NetWeaver Remote Function Call (RFC) Software Development Kit (SDK) please see its support page.

license REUSE status Go Report Card GoDoc

Features

  • Stateless and stateful connections (multiple function calls in the same ABAP session / same context)
  • Automatic conversion between GO and ABAP datatypes

Supported Platforms

  • macOS, Linux

  • Windows is not supported until the #21 fixed

Requirements

All platforms

  • GOLANG requirements

  • SAP NWRFC SDK 7.50 PL3 or later must be downloaded (SAP partner or customer account required) and locally installed

    • Using the latest version is recommended as SAP NWRFC SDK is fully backwards compatible, supporting all NetWeaver systems, from today S4, down to R/3 release 4.6C.
    • SAP NWRFC SDK overview and release notes
  • Build from source on macOS and older Linux systems, may require uchar.h file, attached to SAP OSS Note 2573953, to be copied to SAP NWRFC SDK include directory: documentation

Windows

macOS

  • Build toolchain requires GCC and Xcode Command Line Tools:
$ xcode-select --install
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off

SPJ articles

Highly recommended reading about RFC communication and SAP NW RFC Library, published in the SAP Professional Journal (SPJ)

Installation

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"
export CGO_CFLAGS_ALLOW=.*
export CGO_LDFLAGS_ALLOW=.*
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()

Licensing

Please see our LICENSE file for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

References