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).
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.
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
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'
In order to install and run nwrfc, you need to install {github.com/ffi/ffi Ruby-FFI} which requires compilation. On Windows, you should be running the one-click {rubyinstaller.org/downloads/ Ruby Installer} and install the {github.com/oneclick/rubyinstaller/wiki/Development-Kit DevKit} which is really the easiest way to compile it on Windows.
Then install the nwrfc gem:
On Linux:
sudo gem install nwrfc
On Windows
gem install nwrfc
Documentation is installed locally when you install the gem, but you can install it with ‘rdoc` or `yard` or whatever if you have cloned the repository from GitHub.
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
-
Bug fix for Table#each
-
Add parameter activation/deactivation functionality
-
Fix/add metadata retrieval for DataContainer
-
Basic RFC server functionality
-
More comprehensive type support
-
More table operations
-
Fix loading sapnw library
-
Fix UTF-8 conversion for Windows
-
Enhanced type support
-
Able to call functions
-
Most types work,
-
Getting list of fields from a structure causes a SEGFAULT
-
Improvements to the source code are welcome
-
Indicate on which platforms you have tested the gem
-
Suggestions for improving the API / Hints for idiomatic Ruby