NWRFC - Wrapper for SAP Netweaver RFC SDK using Ruby-FFI
This library provides a wrapper around the sapnwrfc shared library provided in the SAP Netweaver RFC SDK using Ruby-FFI.
The NW RFC SDK allows you to call remote-enabled function modules on an ABAP server (referred to as RFC, which stands for “Remote Function Call”).
To use this library, you must have the nwrfcsdk (libsapnwrfc.so / sapnwrfc.dll) library and related libraries somewhere in your path.
I am developing the library using the 7.20 patch level 2 version of the NW RFC SDK. I have used 7.11, but found for instance that it suffers from the bug described in note 1058327, where RfcGetStringLength() returns the incorrect length of the string if it is longer than 255 characters (supposed to have been fixed in 7.10 patch 2).
Issues
Ruby-FFI does not seem to be able to take string encoding into consideration, so for example, calling RfcGetVersion() is problematic, because the returned string pointer has (like all NW RFC SDK functions) UTF-16LE encoding, and FFI does not seem to be able to work with this. So far this is not too problematic, but let’s see.
Obtaining the Netweaver RFC shared library
The Netweaver RFC SDK libraries are available from SAP. You cannot, unfortunately, obtain these as a public user; you need to have access via a customer account to download them from SAP Service Marketplace (service.sap.com)
Alternatively, you can download and install one of the Netweaver Trial Editions from SDN (requires signup): www.sdn.sap.com/irj/scn/downloads
After installation, the files are available in /usr/sap/<sysid>/exe
Usage
Connecting to the SAP system:
require 'rubygems'
gem 'nwrfc'
include NWRFC
c = Connection.new {"user" => "martin", "passwd" => "secret",
"client" => "100", "ashost" => "ajax.domain.com", "sysnr" => "00"}
Calling a function:
f = c.get_function("STFC_STRUCTURE") #Obtain description of a function module
fc = f.get_function_call
f.invoke
Setting and getting parameters and fields:
import_struc = fc[:IMPORTSTRUC]
import_struc[:RFCCHAR1] = 'a'
Installation
On Linux:
sudo gem install nwrfc
On Windows
gem install nwrfc
Running the tests
The test are located in the tests/ directory. The file ‘login_params.yaml` contains parameters that you will need to customize to log on to your local system that you are testing with. The YAML file contains parameters for multiple systems, so if you want to switch to a different system, change the following line in `test_nwrfc.rb`:
$login_params = YAML.load_file(File.dirname(__FILE__) + "/login_params.yaml")["system2"]
so that [“system2”] at the end points to whatever label you gave it in the YAML file, then
rake test
Release Notes
What’s new in 0.0.0
-
Able to call functions
-
Most types work,
-
Getting list of fields from a structure causes a SEGFAULT
Contributing
Improvements to the source code are welcome. Email me at martin dot ceronio at infosize dot co dot za.
Also let me know, please on which platforms you have tested the gem.