Quantcast
Channel: SCN : Blog List - SAP Gateway
Viewing all articles
Browse latest Browse all 245

How to implement custom dynamic system alias calculation in SAP Gateway

$
0
0

Introduction

 

The standard routing used by the destination finder can be based on user role assignments and host names of the OData client calling the service. It has however turned out that some customers have requirements for the routing that cannot be implemented by just assigning roles.

The standard routing based can thus be enhanced by custom rules. These rules can be implemented in a BadI.

 

This option is described in the SAP Online Help Dynamic System Alias Calculation Via /IWFND/ES_MGW_DEST_FINDER - SAP NetWeaver Gateway - SAP Library. What was missing so far was a simple how to guide that showed how to perform the implementation steps.

 

You can find more detailed information about system aliases in the following blog All About System Alias and Routing of Requests in SAP NetWeaver Gateway and about routing and multi origin in my SCN document Support of multiple backend systems - How to use Multi Origin Composition and Routing

Implementation of the enhancement spot

 

For a detailed description how to implement a BadI see the SAP Online Help: How to Implement a BAdI - Enhancement Framework - SAP Library

 

  • Start transaction SE80 and search for the enhancement spot /IWFND/ES_MGW_DEST_FINDER

 

01 show enhancement spot.png

  • Start to create a BadI implementation by pressing the Create Enhancement Implementation pushbutton.

 

02 create badi implementation.png

 

 

  • In the next screen enter the following values for the enhancement implementation

    03 create badi implementation enter values.png

  • and now you can enter the values for the implementing class for your BAdI impelmentation
    03 create badi implementation 03.png
  • Now you can start to implement the class

    implement_class.png

 

 

We will use the following (very simplified) logic to determine system aliases for our users:

 

 

method /iwfnd/if_mgw_dest_finder_badi~get_system_aliases.

 

     if iv_service_id = 'ZGWSAMPLE_BASIC_0001'.

       case iv_user.

         when 'USER1'.

           delete  ct_system_aliases where system_alias <> 'ERP_1'.

         when 'USER2'.

           delete  ct_system_aliases where system_alias <> 'ERP_2'.

         when others.

           delete  ct_system_aliases where system_alias = 'ERP_1'.

           delete  ct_system_aliases where system_alias = 'ERP_2'.

       endcase.

     endif.

 

   endmethod.

 

 

  • For the service GWSAMPLE_BASIC use the following assignments of system aliases using transaction /n/IWFND/MAINT_SERVICE

    MAINT_SERVICE_SETTINGS.png

 

How does the destination finder works ?

 

 

If USER1 calls the service the destination finder will determine just one system alias, namely ERP_1.

If USER2 calls the service the destination finder will determine also just one system alias, namely ERP_2.

If any other user, for example a user USER3 calls the service the destination finder will determine two system alias entries, namely ERP_3 and ERP_4 where ERP_3 is marked as a default system.

 

Please note that we have assigned no roles since we want to determine the system aliases via custom code shown above.

 

How routing works can best be demonstrated by using the multi origin option to see which system aliases are selected by the destination finder. When three different users USER1, USER2 and USER3 are calling the service GWSAMPLE_BASIC  using the following URI:

 

/sap/opu/odata/IWBEP/GWSAMPLE_BASIC;mo/ProductSet?$filter=ProductID eq 'HT-1000'&$select=SAP__Origin,ProductID&$format=json

 

they would retrieve the following data:

 

Userhttp response
USER1

{

  "d" : {

    "results" : [

      {

        "__metadata" : {        },

        "SAP__Origin" : "ERP_1",

        "ProductID" : "HT-1000"

      }

    ]

  }

}

USER2

{

  "d" : {

    "results" : [

      {

        "__metadata" : {

        },

        "SAP__Origin" : "ERP_2",

        "ProductID" : "HT-1000"

      }

    ]

  }

}

USER3

{

  "d" : {

    "results" : [

      {

        "__metadata" : {

        },

        "SAP__Origin" : "ERP_3",

        "ProductID" : "HT-1000"

      },

      {

        "__metadata" : {

        },

        "SAP__Origin" : "ERP_4",

        "ProductID" : "HT-1000"

      }

    ]

  }

}

 

Please note that USER3 would retrieve data from two backend systems (ERP_3 and ERP_4) in case the multi origin option is used.

 

If this user would try to retrieve data from the same entity set without the multi-origin option the routing would use the destination ERP_3 which has been marked as default.

 

For USER1 and USER2 only one system alias was determined so the choice of the system alias is unique anyway.

 

Please also note that if no system alias is flagged as default the behavior is undetermined. You will find entries in the error log such as

 

No System Alias flagged as "Default" for Service 'ZGWSAMPLE_BASIC_0001' and user 'USER9'

 

I hope this will help you if you have to implement a custom dynamic system alias calculation in SAP Gateway.

 

Best Regards,

Andre


Viewing all articles
Browse latest Browse all 245

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>