Stateful sessions calling Azure Logic App from SAP
Published Apr 13 2022 07:59 PM 2,944 Views
Microsoft

Recently I wanted to make sure that our support of stateful session with the SAP connector for Azure Logic App works not only for calls to SAP but also for call from SAP. While SE37 Function Builder test sequence works for stateful SAP to SAP calls (the sequence are stateful by default), that didn't work for calls to non-SAP systems such as Logic App, because there calls are stateless by default.

 

To exercise the stateful functionality of RFC calls to non-SAP system, you will need an ABAP program. The general principle of stateful calls to non-SAP destinations is explained in the NetWeaver RFC SDK documentation but applicable also to .NET SAP Connector library. You need to call function RFC_SET_REG_SERVER_PROPERTY with EXCLUSIV parameter set to 'Y' to start the session. You need the same function call with EXCLUSIV parameter set to 'N'  to end the session. All calls to the same destination part of the program in-between these two function calls will be on the same session.

 

Here is a sample program you can try with the ABAP Editor dialog accessible from T-Code SE38 in the SAP Logon GUI. Create a new program with the Z_ name of your choosing.

 

*&---------------------------------------------------------------------*
*& Report Z_DAVIBURGTEST
*&---------------------------------------------------------------------*
*& A test report ABAP program to make a stateful call to a non-SAP system
*& RFC_SET_REG_SERVER_PROPERTY is implemented by NW RFC SDK, JCo, NCo
*&---------------------------------------------------------------------*

REPORT Z_DAVIBURGTEST.
DATA: message(128).

CALL
  FUNCTION 'RFC_SET_REG_SERVER_PROPERTY'
  DESTINATION 'DAVIBURG-P720'
  EXPORTING
    EXCLUSIV = 'Y'
  EXCEPTIONS
    SYSTEM_FAILURE = 1 MESSAGE message
    COMMUNICATION_FAILURE = 2 MESSAGE message
  .
IF sy-subrc NE 0.
  WRITE AT / message.
  EXIT.
ENDIF.

CALL FUNCTION 'STFC_CONNECTION' DESTINATION 'DAVIBURG-P720'
  EXPORTING
    REQUTEXT = 'First'
  EXCEPTIONS
    SYSTEM_FAILURE = 1 MESSAGE message
    COMMUNICATION_FAILURE = 2 MESSAGE message
  .

IF sy-subrc NE 0.
  WRITE AT / message.
  EXIT.
ENDIF.

CALL FUNCTION 'STFC_CONNECTION' DESTINATION 'DAVIBURG-P720'
  EXPORTING
    REQUTEXT = 'Second'
  EXCEPTIONS
    SYSTEM_FAILURE = 1 MESSAGE message
    COMMUNICATION_FAILURE = 2 MESSAGE message
  .


IF sy-subrc NE 0.
  WRITE AT / message.
  EXIT.
ENDIF.

CALL
  FUNCTION 'RFC_SET_REG_SERVER_PROPERTY'
  DESTINATION 'DAVIBURG-P720'
  EXPORTING
    EXCLUSIV = 'N'
  EXCEPTIONS
    SYSTEM_FAILURE = 1 MESSAGE message
    COMMUNICATION_FAILURE = 2 MESSAGE message
  .

IF sy-subrc NE 0.
  WRITE AT / message.
  EXIT.
ENDIF.

 

In this sample program the Program ID for my Azure Logic App SAP trigger was 'DAVIBURG-P720' - replace this identifier with the identifier for your application. Save, check and activate the program. Then you can run the program with F8 for direct processing. Then is no output when the program succeeds, but you can observe the result in the Azure management portal for your app.

 

The program is starting a session, then calling Logic App twice with STFC_CONNECTION RFC and a distinct REQUTEXT input.

 

When you receive these calls in Logic App, you will notice in the trigger output a new x-ms-sessionid header. The value for this header will be the same for all the calls in the same session. 

 

A sample stateful call to SAP triggerA sample stateful call to SAP trigger

 

This test was done with April 2022 version of On-Premises Data Gateway.

 

You may then use this session identifier to preserve and recall state in your application between calls. What would be an example of such state? If you are familiar with the stateful client example from SAP, you could now implement with Logic App your own Z_ versions of GET_COUNTER and INCREMENT_COUNTER function modules.

 

Please note that as of April 2022 the currently public version 3.0.24.0 of SAP .NET Connector client library will fail the session start RFC call with error 'PARAMETER EXCLUSIV of FUNCTION RFC_SET_REG_SERVER_PROPERTY (GETTER): cannot convert CHAR24 into Char'. SAP is working on a fix.

1 Comment
Co-Authors
Version history
Last update:
‎Apr 13 2022 07:59 PM
Updated by: