This is a test message to test the length of the message box.
Login
ABAP Quick Ping
Created by Software-Heroes

ABAP Quick - Ping system

285

In today's tip, we show you how to test an RFC connection to another system before using it. This will allow you to verify if the connection is available and works.

You want to connect to another system because you want to read data, but you are not sure if the connection is really working or if the system is even there. To test the connection, we want to introduce today to you two simple steps.

 

Read the destination

As a first step, you should check if the connection is set up in the system at all. You can do this in transaction SM59 for the first check whether your ABAP connection is created correctly. You check the most important settings:

  • User and password are stored correctly
  • Connection test works

 

From the technical point of view, you check the RFCDES table to see if the connection is in place before you do the first ping. You can do this with a simple select as shown below:


" Read destination
SELECT SINGLE * 
 FROM rfcdes
 WHERE rfcdest = 'TSTMDT999'
   AND rfctype = '3'.

IF sy-subrc <> 0.
  " Error handling
ENDIF.

 

Check connection

Use the following class/method to check if the connection to the RFC destionation works. With the different flags you can check the ping, the logon to the system and determine the latency. As you can see in the following example, you can also control and check the values individually.


" Call the method
/sdf/cl_rfc_conn_check=>check_connection(
  EXPORTING
    ip_destination   = id_dest
    ip_ping          = abap_true
    ip_logon         = abap_true
    ip_latency       = abap_true
  IMPORTING
    ep_ping_status   = DATA(ld_ping)
    ep_logon_status  = DATA(ld_logon)
    ep_latency_in_ms = DATA(ld_latency)
).

IF ld_ping <> 1.
  " no connection
ELSE.
  " connection ok
ENDIF.

 

After calling the method do not forget to validate the individual values. In our example, we check the value from ld_ping. This can have the status 1 (connection ok) or 3 (connection failed) as well as the other values returned by the method. As a small extra we define the values directly when returning in the program and thus save ourselves the three variables in the head.

 

Hint: This method is the call of the function module RFCPING, which carries out the required action and prepares the data accordingly for the return. Of course, calling a method looks more elegant than calling a function module.

 

Conclusion

With this simple method you can check if a system still exists (system monitoring) or just test the connection properly before use. Just try it out in your system.


Included topics:
QuickPing
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP Quick - RFC Error handling

Category - ABAP

How do you actually handle errors when communicating via a destination in the function module? More about this in our tip.

03/05/2024

ABAP Quick - CLEAR right

Category - ABAP

Delete correctly? In this article we want to take a look at when it makes sense to delete and how you can do it effectively.

05/12/2023

ABAP Quick - Performance chained statements

Category - ABAP

Let's take a look at the performance when creating chained statements with DATA and FIELD-SYMBOL. Which variant will be ahead in terms of performance?

04/28/2023

ABAP - ALV still relevant in 2022?

Category - ABAP

Today the joking question, do we still need reports that generate ALV outputs in 2022? In this article, we want to look into this question.

07/01/2022

ABAP in Change

Category - ABAP

The programming language ABAP has been changing for years and is being modernized in various concepts. In this article, we'll look at it in detail.

06/24/2022