SAP / node-rfc

Asynchronous, non-blocking SAP NW RFC SDK bindings for Node.js
Apache License 2.0
251 stars 73 forks source link

Sequential calls #117

Closed MartinStenzig closed 4 years ago

MartinStenzig commented 4 years ago

I really like the library, but the limitation of not being able to perform multiple RFC calls on one connection is very much limiting the application. Any chance you are planning to add that in?

The examples I have are the following:

  1. I would like to use an RFC to maintain an order in SAP. That RFC though requires a second RFC (BAPI_TRANSACTION_COMMIT) to be sent in the same session. If I don't execute both in sequence the SAP does not commit the changes properly.
  2. Another example would be a list/detail search. I call one BAPI for the list of orders and a subsequent one for the details. Yes, I can do that in the client, but it would be much quicker without the client server communication overhead.
PaulWieland commented 4 years ago

@MartinStenzigRiz I believe you can call BAPI_TRANSACTION_COMMIT with node-rfc.

See this example where I update the name and description of a cost center:

'use strict';

const rfcClient = require('node-rfc').Client;

// ABAP system RFC connection parameters
const abapSystem = {
    user: 'USER',
    passwd: 'SUPERSECRET',
    ashost: '10.x.x.x',
    sysnr: '27',
    client: '100',
    lang: 'EN',
};

// create new client
const client = new rfcClient(abapSystem);

// echo SAP NW RFC SDK and nodejs/RFC binding version
console.log('Client version: ', client.version);

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

    // invoke ABAP function module, passing structure and table parameters

    // ABAP structure
    const structure = {
        CONTROLLINGAREA: "1000",
        TESTRUN: "",
        LANGUAGE:{
            LANGU:"E",
            LANGU_ISO:"EN"
        },
        COSTCENTERLIST:[
            {
                COSTCENTER: "ABCA003341",
                DESCRIPT: "TEST123",
                NAME: "TEST456"
            }]
};

    client.invoke('BAPI_COSTCENTER_CHANGEMULTIPLE', structure, function(err,res){       
        client.invoke('BAPI_TRANSACTION_COMMIT',{}, function(err,res){
            console.log('committed?');
            console.log(err);
            console.log(res);
        });

        if (err) {
            return console.error('Error invoking BAPI_COSTCENTER_CHANGEMULTIPLE:', err);
        }

        console.log('update cc res:', res);
    });

EDIT: That being said, I do not know how to use BAPI_TRANSACTION_COMMIT with a connection pool. @bsrdjan is that possible?

bsrdjan commented 4 years ago

With or without pool is the same, pool only provides connections.

There are more possibilities for sequential calls, like callbacks, as in @PaulWieland example, async/await or promises, like here.

bsrdjan commented 4 years ago

If more questions, please reopen.