Custom program for checking webservice availability

In SOAMANAGER you can test if a web service can be reached by pressing the test connection button. Unfortunately there is no standard SAP program that performs this test in the background. So how to monitor the availability of a web service?

Solution: custom Z program that can be run online or in background.

In this case we have chosen to put the alert into SM21 system log. But you can also replace this part of the code with sending an email.

Preparation

In SE92 (see this blog) create a new message for the system log.

Z program for monitoring web service

Now create a new Z program:

REPORT z_bc_ws_check.

CONSTANTS zmesid TYPE char3 VALUE 'ZZ1'. "system log message ID defined in SE92
DATA: zif_soap_ping TYPE REF TO cl_soap_ws_ping.
DATA: zlv_ok TYPE boolean.

PARAMETERS zservice TYPE seoclsname. "webservice name
PARAMETERS zlp TYPE prx_logical_port_name. "logical port name


START-OF-SELECTION.

  AUTHORITY-CHECK OBJECT 'S_SRT_CF_C' "check soap runtime auhtorizations.
      ID 'ACTVT' FIELD '03'.

  IF sy-subrc EQ 0.

* create object for soap ping test
    CREATE OBJECT zif_soap_ping TYPE cl_soap_ws_ping.

* initialize ok code
    zlv_ok = 'X'.

* try the ping test
    TRY.
        CALL METHOD zif_soap_ping->if_soap_ws_ping~ping_ws
          EXPORTING
            service = zservice
            lp_name = zlp.
      CATCH cx_soap_ping.
* any error, clear the ok flag
        zlv_ok = ' '. "not ok
    ENDTRY.

    IF zlv_ok EQ ' '. "not ok
* write to SM21 system log
      WRITE: / TEXT-004. "ping not ok
      CALL FUNCTION 'RSLG_WRITE_SYSLOG_ENTRY'
        EXPORTING
          sl_message_area  = zmesid(2)
          sl_message_subid = zmesid+2
          data_word1       = zservice ##NO_TEXT.

      IF sy-subrc EQ 0.
        WRITE: / TEXT-001. "succes to write to SM21
      ELSE.
        WRITE: / TEXT-002. "fail to write to SM21
      ENDIF.
    ELSE.
      WRITE: / TEXT-003. "ping ok
    ENDIF.
  ELSE.
    WRITE: / TEXT-005. "not authorized
  ENDIF.

Create the text elements accordingly.

You can change the authorization check and in stead of writing system log message in SM21 do some other alerting like sending a mail, or pick up the entry in SAP Focused Run monitoring.

Running the program

Run the program:

Enter the webservice name and logical port. Hit execute.

You can also run the program in background mode. For example every 15 minutes. Create multiple steps for multiple web services to test.

Explanation

The program simply creates the object of type CL_SOAP_WS_PING to perform the web service ping. The ping test is then performed. Based on the result the text ok or an entry to SM21 is written.