SAP – Check a RFC and send alert by email

Create the following report in you ABAP system.

Then for each RFC destination that you would like to monitor create a variant with the RFC destination name and the email address which accept the alert.

Then create a periodic JOB in your system to execute the program with the correct variant (you can add several steps for several RFCs destinations with different variant)

*&———————————————————————*
*& Report ZBC_CHECK_RFC
*&
*&———————————————————————*
*& This Report will check if a RFC destination is alive or not?
*& In case the RFC is down the report will send an alert by email
*&———————————————————————*

REPORT ZBC_CHECK_RFC.
DATA:
RFC_SUBRC LIKE SY-SUBRC,
rcpttbl TYPE TABLE OF string,
TXT TYPE STRING,
SYSTEMID TYPE STRING,
col1 TYPE STRING.

parameter: RFCDEST TYPE RFCDEST.
parameter: RCPTMAIL TYPE STRING.

SPLIT RCPTMAIL AT ‘,’ INTO TABLE rcpttbl.
CALL FUNCTION ‘CAT_CHECK_RFC_DESTINATION’
EXPORTING
RFCDESTINATION = RFCDEST
IMPORTING

RFC_SUBRC = RFC_SUBRC.

SYSTEMID = SY-SYSID.

IF RFC_SUBRC <> 0.
CONCATENATE ‘ALERT!!! ‘ RFCDEST ‘ IS NOT WORKING @ ‘ SYSTEMID INTO TXT.
WRITE: / TXT.
*****SEND EMAIL*****
* Data Declarations
DATA: LT_MAILSUBJECT TYPE SODOCCHGI1.
DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER LINE.
DATA: LT_MAILTXT TYPE STANDARD TABLE OF SOLI WITH HEADER LINE.
* Recipients

LOOP AT rcpttbl INTO col1.
LT_MAILRECIPIENTS-REC_TYPE = ‘U’.
LT_MAILRECIPIENTS-RECEIVER = col1.
APPEND LT_MAILRECIPIENTS .
CLEAR LT_MAILRECIPIENTS .
ENDLOOP.

* Subject.
LT_MAILSUBJECT-OBJ_NAME = ‘TEST’.
LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.
LT_MAILSUBJECT-OBJ_DESCR = TXT.
* Mail Contents
LT_MAILTXT = TXT.
APPEND LT_MAILTXT. CLEAR LT_MAILTXT.
* Send Mail

CALL FUNCTION ‘SO_NEW_DOCUMENT_SEND_API1′
EXPORTING
DOCUMENT_DATA = LT_MAILSUBJECT
TABLES
OBJECT_CONTENT = LT_MAILTXT
RECEIVERS = LT_MAILRECIPIENTS
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
IF SY-SUBRC EQ 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT RSCONN01 WITH MODE = ‘INT’ AND RETURN.
ENDIF.

ENDIF.