Login Form
Main Menu
ERPGenie Websites
ERP Software Corner
Check RFC connections in the background
- Details
- Category: Basis
- Published on Wednesday, 17 October 2007 19:37
- Written by Kevin Wilson
- Hits: 10466
I wrote a report to check RFC destinations on our production servers. It's intended to run in the background. If it finds an error where the RFC destination (as defined in SM59) is not responding it sends an email to the stated email address.
It can be implemented in dev and executed in dev to check the production servers. It takes an RFC destination as input and will execute the required function module call on this server. It will then loop through a list of RFC destinations that is also a selection option and test each destination on that server or servers.
You can schedule a job to run this report every 5 minutes checking the RFC destinations.
*&-------------------*
*& Report ZRFC
*&-------------------*
REPORT zrfc MESSAGE-ID sr.
TABLES: rfcdes.
INCLUDE zca_email_data.
DATA: commmess TYPE char120,
sysmess TYPE char120,
rfcdes2 TYPE string,
rfcdes1(32) TYPE c.
SELECT-OPTIONS: rfcdest FOR rfcdes-rfcdest OBLIGATORY,
destin FOR rfcdes-rfcdest OBLIGATORY.
INCLUDE zca_email_parameters.
START-OF-SELECTION.
REFRESH: out_text.
CLEAR t_error.
LOOP AT rfcdest.
t_email = email.
rfcdes1 = rfcdest-low.
FORMAT COLOR COL_GROUP.
WRITE: /1 'Checking server:', rfcdes1.
CONCATENATE 'Checking server:' rfcdes1
INTO out_text-line SEPARATED BY space.
APPEND out_text.
LOOP AT destin.
rfcdes2 = destin-low.
FORMAT COLOR COL_HEADING.
WRITE: /5 'Checking destination:',
rfcdes2.
* asynchronous call to destination
CLEAR: commmess,
sysmess.
CALL FUNCTION 'RFC_GET_SYSTEM_INFO'
DESTINATION rfcdes1
EXPORTING
destination = rfcdes2
IMPORTING
dest_communication_message = commmess
dest_system_message = sysmess
EXCEPTIONS
communication_failure = 1
system_failure = 2.
IF sy-subrc = 0.
IF commmess IS INITIAL AND
sysmess IS INITIAL.
FORMAT COLOR COL_POSITIVE.
WRITE: /10 'All good'.
CONCATENATE rfcdes2 ' -> All Good'
INTO out_text-line SEPARATED BY space.
APPEND out_text.
ELSEIF NOT commmess IS INITIAL.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'COMMUNICATION FAILURE: ',
commmess.
CONCATENATE rfcdes2 ' -> COMMS FAILURE: '
commmess
INTO out_text-line SEPARATED BY space.
APPEND out_text.
t_error = 'x'.
ELSEIF NOT sysmess IS INITIAL.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'SYSTEM FAILURE: ',
sysmess.
CONCATENATE rfcdes2 ' -> SYSTEM FAILURE: '
sysmess
INTO out_text-line SEPARATED BY space.
APPEND out_text.
t_error = 'x'.
ENDIF.
ELSEIF sy-subrc = 1.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'COMMUNICATION FAILURE: ',
commmess.
CONCATENATE rfcdes2 ' -> COMMS FAILURE: '
commmess
INTO out_text-line SEPARATED BY space.
APPEND out_text.
t_error = 'x'.
ELSEIF sy-subrc = 2.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'SYSTEM FAILURE: ',
sysmess.
CONCATENATE rfcdes2 ' -> SYSTEM FAILURE: '
sysmess
INTO out_text-line SEPARATED BY space.
APPEND out_text.
t_error = 'x'.
ELSEIF sy-subrc = 8.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'TIMEOUT'.
CONCATENATE rfcdes2 ' -> Time Out'
INTO out_text-line SEPARATED BY space.
APPEND out_text.
t_error = 'x'.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'Other error'.
CONCATENATE rfcdes2 ' -> Other Error'
INTO out_text-line SEPARATED BY space.
APPEND out_text.
t_error = 'x'.
IF NOT commmess IS INITIAL.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'COMMUNICATION FAILURE: ',
commmess.
CONCATENATE rfcdes2 ' -> COMMS FAILURE: '
commmess
INTO out_text-line SEPARATED BY space.
APPEND out_text.
ELSEIF NOT sysmess IS INITIAL.
FORMAT COLOR COL_NEGATIVE.
WRITE: /10 'SYSTEM FAILURE: ',
sysmess.
CONCATENATE rfcdes2 ' -> SYSTEM FAILURE: '
sysmess
INTO out_text-line SEPARATED BY space.
APPEND out_text.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
FORMAT COLOR OFF.
END-OF-SELECTION.
IF t_error = 'x'.
INCLUDE zca_send_email.
ENDIF.
*&-----------------------------------*
*& Include ZCA_EMAIL_DATA
*&-----------------------------------*
data: so_type like sood-objtp value 'RAW',
so_hdr like sood1,
so_flag like sonv-flag value 'X',
so_reces like sonv-flag value 'B',
so_objsns like sood1-objsns value 'P',
so_owner like soud-usrnam,
email_addr(24) type c,
t_deep(4) type c,
t_email,
t_error.
data: begin of out_text occurs 0.
include structure soli.
data: end of out_text.
data: begin of out_text2 occurs 0.
include structure soli.
data: end of out_text2.
data: begin of tab_recvr occurs 10.
include structure soos1.
data: end of tab_recvr.
*&------------------------------------------*
*& Include ZCA_EMAIL_PARAMETERS
*&------------------------------------------*
parameters: email type flag as checkbox,
emaila(50) type c.
*&-----------------------------------*
*& Include ZCA_SEND_EMAIL
*&-----------------------------------*
data : object_id_new like soodk,
office_object_key like swotobjid-objkey,
e_send_request_oid type os_guid,
sosc_tab
type standard table of sosc,
objcat type table of sxobjcat,
application_object
type standard table of swotobjid.
if t_email = 'X' and not out_text[] is initial.
move sy-datum to tab_recvr-rcdat .
move sy-uzeit to tab_recvr-rctim.
move '1' to tab_recvr-sndpri.
move 'X' to tab_recvr-sndex.
move 'U' to tab_recvr-recesc.
move '5' to tab_recvr-sortclass.
if emaila is initial.
emaila = '
This email address is being protected from spambots. You need JavaScript enabled to view it.
'.
endif.
tab_recvr-recextnam = emaila.
append tab_recvr.
so_owner = sy-uname.
so_hdr-objdes = 'RFC ALERT!!!'.
call function 'SO_OBJECT_SEND'
exporting
object_hd_change = so_hdr
object_type = so_type
owner = so_owner
importing
object_id_new = object_id_new
office_object_key = office_object_key
e_send_request_oid = e_send_request_oid
tables
objcont = out_text
* objhead = out_text
receivers = tab_recvr
application_object = application_object
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
originator_not_exist = 20
x_error = 21.
commit work.
if sy-subrc <> 0.
message i999(b1)
with 'Call to email failed. SUBRC = ' sy-subrc.
else.
refresh sosc_tab.
select *
from sosc
into table sosc_tab
where objno = object_id_new-objno.
call function 'SX_SEND_DISPATCHER'
exporting
sosc_tab = sosc_tab
output = 'X'
* IMPORTING
* nr_so_objects = nr_objects
tables
obj_cat = objcat
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid
type 'I'
number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
message i999(b1)
with 'Email sent to ' emaila.
endif.
endif.
endif.


