jokame / node-rfc

SAP RFC Connector for NodeJS

Home Page:http://sap.github.io/node-rfc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The nodejs RFC Connector

This node module provides bindings for SAP NetWeawer RFC Library, for a comfortable way of calling ABAP modules from nodejs, via SAP Remote Function Call (RFC) protocol.

Platforms & Prerequisites

The node-rfc has been initially built with nodejs v0.10.26, on Linux 64 bit platform and later enhanced, mostly used and tested on Linux and Windows 64 platforms.

OS X and ARM platforms are currently not supported, as SAP NW RFC Library is not available for those platforms.

To start using node-rfc you need to obtain SAP NW RFC Library from SAP Service Marketplace, following these instructions.

A prerequisite to download is having a customer or partner account on SAP Service Marketplace and 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 therefore always use the newest version released on Service Marketplace and connect to older systems as well.

Version

The latest supported nodejs version is in master branch, for older versions check other branches.

Documentation

For full documentation please refer to node-rfc documentation, complementing SAP NW RFC Library programming guide and documentation provided on SAP Service Marketplace.

Install

Clone from the GitHub repository to build and run tests and examples locally

git clone https://github.com/SAP/node-rfc.git
cd node-rfc
npm install

Getting started

In order to call remote enabled ABAP function module, we need to create a client with valid logon credentials, connect to NetWeaver system and then invoke a remote enabled ABAP function module from node. The client can be used for one or more subsequent RFC calls.

"use strict";

var rfc = require('node-rfc');

var abapSystem = {
  user: 'name',
  passwd: 'password',
  ashost: '10.11.12.13',
  sysnr: '00',
  client: '100',
  saprouter: '/H/111.22.33.177/S/3299/W/tdkf9d/H/132.139.17.14/H/'
};

// create new client
var client = new rfc.Client(abapSystem);

// echo the client NW RFC lib version
console.log('RFC client lib version: ', client.getVersion());

// and connect
client.connect(function(err) {
  if (err) { // check for login/connection errors
    return console.error('could not connect to server', err);
  }

  // invoke remote enabled ABAP function module
  client.invoke('STFC_CONNECTION',
    { REQUTEXT: 'H€llö SAP!' },
    function(err, res) {
      if (err) { // check for errors (e.g. wrong parameters)
        return console.error('Error invoking STFC_CONNECTION:', err);
      }

      // work with result;  should be something like:
      // { ECHOTEXT: 'Hello SAP!',
      //   RESPTEXT: 'SAP R/3 Rel. 702   Sysid: E1Q      Date: 20140613   Time: 142530   Logon_Data: 001/DEMO/E',
      //   REQUTEXT: 'Hello SAP!' }
      console.log('Result STFC_CONNECTION:', res);
    });


  // invoke more complex ABAP function module
  var importStruct = {
    RFCFLOAT: 1.23456789,
    RFCCHAR1: 'A',
    RFCCHAR2: 'BC',
    RFCCHAR4: 'DEFG',

    RFCINT1: 1,
    RFCINT2: 2,
    RFCINT4: 345,

    RFCHEX3: 'fgh',

    RFCTIME: '121120',
    RFCDATE: '20140101',

    RFCDATA1: '1DATA1',
    RFCDATA2: 'DATA222'
  };

  var importTable = [importStruct];

  client.invoke('STFC_STRUCTURE',
    { IMPORTSTRUCT: importStruct, RFCTABLE: importTable },
    function(err, res) {
      if (err) {
        return console.error('Error invoking STFC_STRUCTURE:', err);
      }
      console.log('Result STFC_STRUCTURE:', res);
  });

});

Finally, the connection is closed automatically when the instance is deleted by the garbage collector or by explicitly calling the client.close() method on the client instance.

For more examples check the unit tests source code. Maintain your NW test system parameters first in the source code, before running those examples.

Running the Unit Tests

To run the unit tests, first ensure that you have followed the Build from Source documentation, in order to install all dependencies and successfully build the node-rfc connector. Once you have done that, ensure that mocha and should are installed, either as dependencies:

npm install

or globally:

npm install -g mocha should

Run the tests with:

mocha

REST API

Example how to create REST APIs using node-rfc, node, express and gulp: https://github.com/Adracus/noderfc-restapi.

Links

Nodejs Addons

node-gyp

Classes

Libuv

Exceptions

C++ Strings

About

SAP RFC Connector for NodeJS

http://sap.github.io/node-rfc

License:Apache License 2.0


Languages

Language:C++ 49.2%Language:Makefile 25.8%Language:JavaScript 21.5%Language:Python 3.5%