Showing posts with label nodejs. Show all posts
Showing posts with label nodejs. Show all posts

Tuesday, July 17, 2018

Issues while setting up SAP RFC Connector for NodeJS (node-rfc) connector

In one of my last posts I wrote about nodejs RFC Connector provided by SAP to connect SAP backend systems. The Connector works very well. However, while I was setting it up I faced few issues. I’m listing them here with solutions how to overcome them; perhaps it will be useful for someone else too.

1. Library MSVCP120.dll missing

One of prerequisites of nodejs RFC Connector is that SAP NW RFC SDK needs to be present on machine which will be used for making called to the SAP system. However sometimes SAP NW RFC SDK is not installed correctly on the machine. Basic check of the installation is to run command rfcexec. In case of issue there is an error like:
The program can’t start because MSVCP120.dll is missing...




Solution is to install Microsoft Visual C++ (2010, 2013, or newer depending on your OS platform) Redistributable component. Once installed there shall be following output of rfcexec:




2. NPM module xyz can’t be found

On attempt to run nodejs app using the Connector call there is a following error thrown:

Error: The specified module could not be found.

Basically the node-rfc tries to find rfc.node in specific folder /build/rfc but it's not in there because by default when it is installed another subfolder is placed there. In my case on OS Windows it is the subfolder "win32_x64". Solution is to just move or copy the rfc.node file to one level up.


3. Issues related to path variable.
As mentioned in point no.1 SAP NW RFC SDK needs to be present on the machine where the calls will be performed from. The folder where the SDK is installed needs to be included in path variable e.g.:

Tuesday, April 17, 2018

How to call BAPI in SAP from nodejs app

Recently I used nodejs RFC Connector provided by SAP. The module called node-rfc provides bindings for SAP NetWeawer RFC Library. Via the library it is possible to call RFC enabled function modules residing in SAP NetWeaver based ABAP system from nodejs, leveraging SAP Remote Function Call (RFC) protocol. For installation of the module into your nodejs framework see here.

Below I provide two example nodejs apps showcasing possibilities to passing values to BAPI’s parameters like single values, structures and tables.

I think that the node-rfc module is great option how to interface with SAP systems from heavily used nodejs app like in case of web based apps.

You can find both examples on my github:

demo_BAPI_params1.js      usage of table and variable parameter

//demo prg to showcase usage of table and variable parameters of SAP's BAPI while called from nodejs app via SAP/node-rfc nodule
"use strict";
var rfc = require('node-rfc');
var abapSystem = {
    user: 'sap_user',
    passwd: 'sap_user_pwd',
    ashost: 'sap.nodomain',
    sysnr: '01',
    client: '800'
};
var client = new rfc.Client(abapSystem);
var MAX_ROWS = 3;
var SELECTION_RANGE_str = {
               PARAMETER: "USERNAME",
               SIGN:      "I",
               OPTION:    "CP",
               LOW:       "A*"
        };     
var SELECTION_RANGE_tab = [SELECTION_RANGE_str];
       
client.connect(function(err) {
    if (err) {
        return console.error('could not connect to server', err);
    }  
    client.invoke('BAPI_USER_GETLIST', {
                       MAX_ROWS: MAX_ROWS,
                       SELECTION_RANGE: SELECTION_RANGE_tab
        },
        function(err, res) {
            if (err) {
                return console.error('Error invoking BAPI_USER_GETLIST:', err);
            }
               console.log('Result BAPI_USER_GETLIST:', res);
        });   
});

demo_BAPI_params2.js      usage of structure parameter of SAP's BAPI

//demo prg to showcase usage of structure parameter of SAP's BAPI while called from nodejs app via SAP/node-rfc nodule
"use strict";
var rfc = require('node-rfc');
var abapSystem = {
    user: 'sap_user',
    passwd: 'sap_user_pwd',
    ashost: 'sap.nodomain',
    sysnr: '01',
    client: '800'
};
var client = new rfc.Client(abapSystem);
 
client.connect(function(err) {
  if (err) {
    return console.error('could not connect to server', err);
  }
  var IMPORTSTRUCT = {
    RFCDATA1: 'some value of structure field RFCDATA1',
    RFCDATA2: 'some value of structure field RFCDATA2'
  };
  client.invoke('STFC_STRUCTURE',
    { IMPORTSTRUCT: IMPORTSTRUCT },
    function(err, res) {
      if (err) {
        return console.error('Error invoking STFC_STRUCTURE:', err);
      }
      console.log('Result STFC_STRUCTURE:', res);
  });
});