SAP BW - Calling a remote FM in ECC from BW

There are scenarios where in a particular attribute can only be reterieved by executing a Function Module in SAP ECC environment. If you need that attribute in BW, one can call that FM from BW transformation/Update Rules/Transfer Rules and update the returned value into BW Data targets. Below are the steps to achieve this.

1. The FM should be 'Remote Enabled  for the BW to be able to call the FM on SAP ECC, so first turn on 'Remote-Enabled Module' radiobox of the FM under attributes tab (tcode SE37).
    You might need to check 'Pass Value' check box for all the import and export parameters of the FM before you try turn on the Remote Enabled module. All the import/export parameters must be of type pass value for a remote FM.


2. Now that the FM is remotely enabled we should be able to call this FM from BW update rule and retrieve our value. Let assume this FM takes parameter USER as input and returns ORG as an export (put) value. 
    So to call this function module from BW update rule the code looks like below.
   CALL 'REMOTE_FM_NAME' DESTINATION DBWCLNT160
        EXPORTING 
             USER = COMM_STRUCTURE-USERID
        IMPORTING
            ORGANIZATION = ORG.
    RESULT = ORGANIZATION.
     In the above code we are just passing user id value in the communication structure to the FM and assigning returned ORG value to RESULT which will updated in the data targets. 
    One thing to note here is that I have hardcoded SAP target system (DBWCLNT16) to our SAP development environment so this code will not work when I transport this to QA or production environments. There are couple of options to avoid this issue. 
    One is to maintain a mapping table between all BW and SAP environments and lookup the the source SAP environment details from this table and use that as destination in above code.
    The option is to use LOGSYS attribute in the communication structure. Most of the SAP datasources have LOGSYS as one of the fields and LOGSYS contains the SAP source system details. You can just use COMM_STRUCTURE-LOGSYS as distination system in the above code.
     One more thing to keep in mind is calling a remote FM from BW update rules/transformation/transfer rules will have an performance impact as it has to call the FM for each and every record.