Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Call Function using DESTINATION

Former Member
0 Likes
7,182

Hi there!

Abapers, I'm needing some help here with RFCs.

My destinations (SM59):

ERP_100 ERP_120 ERP_130 PI_200 PI_300

I have to call a function in PI from ERP. I'm doing in this way:

CALL FUNCTION 'pi_function_module' DESTINATION 'PI_200' ...

It's working. But the destination can not be hard coded. With the program in ERP_100 (DEV) and ERP_120 (QAS) the destination is PI_200 (PI DEV) and with the program in ERP_130 (PRD) the destination is PI_300 (PI PRD).

How can I handle this?

Thanks in advance!

Best regards,

Charles

1 ACCEPTED SOLUTION
Read only

Sougata
Active Contributor
0 Likes
4,200

Hi Charles,

Refer [this|; thread.

I quote the last post by Micky Oestreich - "This solely depends on the naming conventions you are using. Since the name of the RFC destination is arbitrary, there is 'no' way of determining the name of the destination."

So, your design approach could either be by building a customizing table where you maintain the destination values or use a 'CASE' statement in your code before calling the remote function module....something like:



DATA:
  lv_own_system  TYPE logsys,
  lv_rfcdest     TYPE rfcdest.

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
  IMPORTING
    own_logical_system             = lv_own_system
  EXCEPTIONS
    own_logical_system_not_defined = 1
    OTHERS                         = 2.

IF sy-subrc NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CASE lv_own_system.
  WHEN 'ERP_100' or 'ERP_120'.
     lv_rfcdest = 'PI_200'.
  WHEN 'ERP_130'.
    lv_rfcdest = 'PI_300'.
  WHEN OTHERS.
      
ENDCASE.

"Now call the remote function
CALL FUNCTION 'pi_function_module' DESTINATION lv_rfcdest ...

Hope this helps,

Cheers,

Sougata.

5 REPLIES 5
Read only

mvoros
Active Contributor
0 Likes
4,200

Use variable instead of hard coded string with type rfcdest.

Cheers

Read only

Former Member
0 Likes
4,200

Martin, I know I need to use a variable of the type rfcdest-rfcdest.

But the problem is to get the value automatically. I was thinking of something to bring me that value, maybe a function that returns the destination for the actual environment.

Thanks for try to help. If you have any other idea let me know.

Best regards,

Charles

Read only

mvoros
Active Contributor
0 Likes
4,200

Hi,

it depends on your logic. For example you can create a custom table where you will store correct RFC destination. You will have to maintain it in each system. Another approach could be to derive RFC destination from system ID. Something like


IF sy-sysid EQ 'PRD'.
  dest = 'XXX'.
ELSE.
  dest = 'YYY'.
ENDIF.

Obviously, a solution with table is more flexible.

Cheers

Read only

Sougata
Active Contributor
0 Likes
4,201

Hi Charles,

Refer [this|; thread.

I quote the last post by Micky Oestreich - "This solely depends on the naming conventions you are using. Since the name of the RFC destination is arbitrary, there is 'no' way of determining the name of the destination."

So, your design approach could either be by building a customizing table where you maintain the destination values or use a 'CASE' statement in your code before calling the remote function module....something like:



DATA:
  lv_own_system  TYPE logsys,
  lv_rfcdest     TYPE rfcdest.

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
  IMPORTING
    own_logical_system             = lv_own_system
  EXCEPTIONS
    own_logical_system_not_defined = 1
    OTHERS                         = 2.

IF sy-subrc NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CASE lv_own_system.
  WHEN 'ERP_100' or 'ERP_120'.
     lv_rfcdest = 'PI_200'.
  WHEN 'ERP_130'.
    lv_rfcdest = 'PI_300'.
  WHEN OTHERS.
      
ENDCASE.

"Now call the remote function
CALL FUNCTION 'pi_function_module' DESTINATION lv_rfcdest ...

Hope this helps,

Cheers,

Sougata.

Read only

Former Member
0 Likes
4,200

Thank you Martin Voros and Sougata.

I was just thinking in 'custom table' but wondering a better way to do this. I'll probably go with the table solution.

Best regards,

Charles