saprfc

package module
v0.0.0-...-3e56ef9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

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

Documentation

Overview

gorfc wraps the SAP NetWeaver RFC library written in C. Its provides methods for maintaining a connection to an ABAP backend and calling remote enabled functions from Go. The functions of the library take and return Go data types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNWRFCLibVersion

func GetNWRFCLibVersion() (major, minor, patchlevel uint)

GetNWRFCLibVersion returnd the major version, minor version and patchlevel of the SAP NetWeaver RFC library used.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func ConnectionFromDest

func ConnectionFromDest(dest string) (conn *Connection, err error)

ConnectionFromDest creates a new connection with just the dest system id.

func ConnectionFromParams

func ConnectionFromParams(connParams ConnectionParameter) (conn *Connection, err error)

ConnectionFromParams creates a new connection with the given connection parameters and tries to open it. If this is successfull it returns the connection else it returns nil.

func (*Connection) Alive

func (conn *Connection) Alive() bool

Alive returns true if the connection is open else returns false.

func (*Connection) Call

func (conn *Connection) Call(goFuncName string, params interface{}) (result map[string]interface{}, err error)

Call calls the given function with the given parameters and wraps the results returned.

func (*Connection) Close

func (conn *Connection) Close() (err error)

Close closes the connection and sets alive to false.

func (*Connection) GetConnectionAttributes

func (conn *Connection) GetConnectionAttributes() (connAttr ConnectionAttributes, err error)

GetConnectionAttributes returns the wrapped connection attributes of the connection.

func (*Connection) GetFunctionDescription

func (conn *Connection) GetFunctionDescription(goFuncName string) (goFuncDesc FunctionDescription, err error)

GetFunctionDescription returns the wrapped function description of the given function.

func (*Connection) Open

func (conn *Connection) Open() (err error)

Open opens the connection and sets alive to true.

func (*Connection) Ping

func (conn *Connection) Ping() (err error)

Ping pings the server which the client is connected to and does nothing with the error if one occurs.

func (*Connection) PingAndAutoReconnect

func (conn *Connection) PingAndAutoReconnect(interval time.Duration) *time.Ticker

PingAndAutoReconnect tries to reconnect on an error, it checks by the duration defined by the interval param

func (*Connection) RStrip

func (conn *Connection) RStrip(rstrip bool) *Connection

RStrip sets rstrip of the given connection to the passed parameter and returns the connection right strips strings returned from RFC call (default is true)

func (*Connection) Reopen

func (conn *Connection) Reopen() (err error)

Reopen closes and opens the connection.

func (*Connection) ReturnImportParams

func (conn *Connection) ReturnImportParams(returnImportParams bool) *Connection

ReturnImportParams sets returnImportParams of the given connection to the passed parameter and returns the connection

type ConnectionAttributes

type ConnectionAttributes struct {
	Dest                  string // RFC destination
	Host                  string // Own host name
	PartnerHost           string // Partner host name
	SysNumber             string // R/3 system number
	SysId                 string // R/3 system ID
	Client                string // Client ("Mandant")
	User                  string // User
	Language              string // Language
	Trace                 string // Trace level (0-3)
	IsoLanguage           string // 2-byte ISO-Language
	Codepage              string // Own code page
	PartnerCodepage       string // Partner code page
	RfcRole               string // C/S: RFC Client / RFC Server
	Type                  string // 2/3/E/R: R/2,R/3,Ext,Reg.Ext
	PartnerType           string // 2/3/E/R: R/2,R/3,Ext,Reg.Ext
	Rel                   string // My system release
	PartnerRel            string // Partner system release
	KernelRel             string // Partner kernel release
	CpicConvId            string // CPI-C Conversation ID
	ProgName              string // Name of the calling APAB program (report, module pool)
	PartnerBytesPerChar   string // Number of bytes per character in the backend's current codepage. Note this is different from the semantics of the PCS parameter.
	PartnerSystemCodepage string // Partner system code page
	Reserved              string // Reserved for later use
}

func (ConnectionAttributes) String

func (connAttr ConnectionAttributes) String() string

type ConnectionParameter

type ConnectionParameter struct {
	Dest            string
	Client          string
	User            string // Username
	Passwd          string // Password
	Lang            string // Language
	Trace           string
	Ashost          string
	Sysnr           string
	Mshost          string
	Msserv          string
	Sysid           string
	Group           string
	Snc_qop         string
	Snc_myname      string
	Snc_partnername string
	Snc_lib         string
	Mysapsso2       string
	Saprouter       string
}

ConnectionParameter holds all the connection parameters possible (at the moment).

type FieldDescription

type FieldDescription struct {
	Name      string
	FieldType string
	NucLength uint
	NucOffset uint
	UcLength  uint
	UcOffset  uint
	Decimals  uint
	TypeDesc  TypeDescription
}

type FunctionDescription

type FunctionDescription struct {
	Name       string
	Parameters []ParameterDescription
}

func (FunctionDescription) String

func (funcDesc FunctionDescription) String() (result string)

type ParameterDescription

type ParameterDescription struct {
	Name          string
	ParameterType string
	Direction     string
	NucLength     uint
	UcLength      uint
	Decimals      uint
	DefaultValue  string
	ParameterText string
	Optional      bool
	TypeDesc      TypeDescription
}

func (ParameterDescription) String

func (paramDesc ParameterDescription) String() string

type RfcError

type RfcError struct {
	Description string
	ErrorInfo   rfcSDKError
}

func (RfcError) Error

func (err RfcError) Error() string

type TypeDescription

type TypeDescription struct {
	Name      string
	NucLength uint
	UcLength  uint
	Fields    []FieldDescription
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL