Search code examples
abapsaprfchardcoded

Best practice instead of hard-coded RFC destinations?


is there a good way to use not hardcoded RFC destinations?

Right now our solution is to check which system is used and then assign the destination to a variable

IF cl_role EQ 'P'.
      p_dest = 'ESW300'.
   ELSE.
      p_dest = 'EAW300'.
   ENDIF.

which we use when calling our destination function.

CALL FUNCTION 'XYZ' DESTINATION p_dest

Is there a good way to not use the hardcoded destinations?

Thank you for the help!


Solution

  • I saw every company creating its own custom table containing the RFC destinations (maintained differently in every SAP system by administrators; eventually it can be custom entries in the standard table TVARVC), but nobody published anything about it. Eventually this blog post but it's a very complex solution, only documented, but no code provided.

    An easier (and adequate?) way is to create a Logical System (transaction code BD54) for every system, and assign a RFC destination (transaction code BD97).

    In your program, do this kind of thing:

    SELECT SINGLE rfcdest
        FROM tblsysdest
        WHERE logsys = 'CRM' 
        INTO @DATA(crm_system).
    
    CALL FUNCTION 'RFC_PING' DESTINATION crm_system
        EXCEPTIONS OTHERS = 1.
    

    PS: prefer to abstract things, like creating a global class with one method GET_CRM_SYSTEM instead of hardcoding the SELECT in every program.