Program for Short Dump Email Tool:-
Objective of Program is to Notify ABAP Short dumps to monitoring DL’s for specified time duration.
Upon execution of program based on the selection of Time duration we can be able to Mail/Notify the Short dumps encountered in last destined hours so that manual check can be avoided .
REPORT Z_SHORTDUMP_MONITOR LINE-SIZE 200.
* Include for declaration of data types
INCLUDE Z_SHORTDUMP_MONITOR_TOP.
* Include for Selection Screen elements.
INCLUDE Z_SHORTDUMP_MONITOR_SEL.
* Include for storing all forms used
INCLUDE Z_SHORTDUMP_MONITOR_FORM.
START-OF-SELECTION.
* Fetching data and calculations
PERFORM GET_DATA.
* Creating message
PERFORM create_message.
* Sending Message
PERFORM send_message.
----------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include Z_SHORTDUMP_MONITOR_TOP
*&---------------------------------------------------------------------*
TABLES : SNAP_BEG,somlreci1,AGR_USERS .
DATA:
* Declaration of types to be used in the Function module for sending mail
it_objbin TYPE STANDARD TABLE OF solisti1, " Attachment data
it_objtxt TYPE STANDARD TABLE OF solisti1, " Message body
it_objpack TYPE STANDARD TABLE OF sopcklsti1, " Packing list
it_reclist TYPE STANDARD TABLE OF somlreci1, " Receipient list
it_objhead TYPE STANDARD TABLE OF solisti1. " Header
* Declaration of Work Area to be used in the Function module for sending mail
DATA: wa_docdata TYPE sodocchgi1, " Document data
wa_objtxt TYPE solisti1, " Message body
wa_objbin TYPE solisti1, " Attachment data
wa_objpack TYPE sopcklsti1, " Packing list
wa_reclist TYPE somlreci1. " Receipient list
RANGES: r_email FOR somlreci1-receiver.
DATA: w_tab_lines TYPE i. " Table lines.
DATA : var(4) TYPE c,
Rvalue(10) TYPE c,
v_mailbody type solisti1.
* Declaration of variables to be used for the Time range calculations
* to be used in the Radio buttons
DATA :l_lines type i ,
lv_time TYPE SNAP_BEG-uzeit ,
lv_time1 TYPE SNAP_BEG-uzeit ,
lv_time2 TYPE SNAP_BEG-uzeit ,
lv_time3 TYPE SNAP_BEG-uzeit,
lv_time0 TYPE SNAP_BEG-uzeit .
* Declaration of Structure of Internal Table to be used for storing selective data from SNAP-BEG table
TYPES: BEGIN OF TY_FINAL1,
date type SNAP_BEG-DATUM,
time type SNAP_BEG-UZEIT,
server type SNAP_BEG-AHOST,
user type SNAP_BEG-UNAME,
wp type SNAP_BEG-MODNO,
seqno type SNAP_BEG-SEQNO,
e_line type SNAP_BEG-FLIST,
errorid type c length 250,
END OF TY_FINAL1 .
* Declaration of Structure of Internal Table to be used for importing to FM for sending mail
TYPES: BEGIN OF TY_FINAL,
date type SNAP_BEG-DATUM,
time type SNAP_BEG-UZEIT,
server type SNAP_BEG-AHOST,
user type SNAP_BEG-UNAME,
wp(4) type c,
seqno type SNAP_BEG-SEQNO,
e_line type SNAP_BEG-FLIST,
errorid type c length 250,
END OF TY_FINAL .
DATA : it_final1 TYPE TABLE OF ty_final1 ,
it_final TYPE TABLE OF ty_final,
wa_final1 TYPE ty_final1,
wa_final TYPE ty_final.
data : v_errorid type c length 250,
v_id(2) type c ,
v_len(3) type c .
lv_time = sy-uzeit .
* IF lv_time LE 100000 .
lv_time0 = 000001 .
lv_time1 = lv_time - 3600 .
lv_time2 = lv_time - 7200 .
lv_time3 = lv_time - 21600.
* ENDIF.
--------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include Z_SHORTDUMP_MONITOR_SEL
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
parameters:
* Describing Radio Buttons.
Last1Hrs radiobutton group rbg1 ,
Last2Hrs radiobutton group rbg1 ,
Last6Hrs radiobutton group rbg1 .
SELECTION-SCREEN END OF BLOCK b1.
* Selection screen for accepting Mail id's for broadcasting.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
SELECT-OPTIONS EmailId FOR somlreci1-receiver NO INTERVALS DEFAULT 'abc@xyz.com' OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
----------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include Z_SHORTDUMP_MONITOR_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
* Fetching records for Last 1 hour
IF Last1Hrs EQ 'X'.
Rvalue = '1' .
IF sy-uzeit LE '010000'.
SELECT DATUM UZEIT AHOST UNAME MODNO SEQNO FLIST
FROM SNAP_BEG
INTO TABLE it_final1
WHERE DATUM eq sy-datum and SEQNO = '000' and UZEIT BETWEEN lv_time0 AND lv_time.
Else.
SELECT DATUM UZEIT AHOST UNAME MODNO SEQNO FLIST
FROM SNAP_BEG
INTO TABLE it_final1
WHERE DATUM eq sy-datum and SEQNO = '000' and UZEIT BETWEEN lv_time1 AND lv_time.
Endif.
* Fetching records for Last 2 hours.
ELSEIF Last2Hrs EQ 'X'.
Rvalue = '2' .
IF sy-uzeit LE '020000'.
SELECT DATUM UZEIT AHOST UNAME MODNO SEQNO FLIST
FROM SNAP_BEG
INTO TABLE it_final1
WHERE DATUM eq sy-datum and SEQNO = '000' and UZEIT BETWEEN lv_time0 AND lv_time .
- Else.
SELECT DATUM UZEIT AHOST UNAME MODNO SEQNO FLIST
FROM SNAP_BEG
INTO TABLE it_final1
WHERE DATUM eq sy-datum and SEQNO = '000' and UZEIT BETWEEN lv_time2 AND lv_time .
Endif.
* Fetching records for Last 6 hours.
ELSEIF Last6Hrs EQ 'X'.
Rvalue = '6' .
IF sy-uzeit LE '060000' .
SELECT DATUM UZEIT AHOST UNAME MODNO SEQNO FLIST
FROM SNAP_BEG
INTO TABLE it_final1
WHERE DATUM eq sy-datum and SEQNO = '000' and UZEIT BETWEEN lv_time0 AND lv_time .
Else .
SELECT DATUM UZEIT AHOST UNAME MODNO SEQNO FLIST
FROM SNAP_BEG
INTO TABLE it_final1
WHERE DATUM eq sy-datum and SEQNO = '000' and UZEIT BETWEEN lv_time3 AND lv_time .
Endif.
- ENDIF.
SORT it_final1 by date user server wp.
DELETE ADJACENT DUPLICATES FROM it_final1 comparing date user server wp .
IF sy-subrc = 0.
DESCRIBE TABLE it_final1 LINES l_lines.
LOOP AT it_final1 INTO wa_final1.
v_id = wa_final1-e_line+0(2).
v_len = wa_final1-e_line+2(3).
v_errorid = wa_final1-e_line+5(v_len).
*Populate it_final
wa_final-date = wa_final1-date.
wa_final-time = wa_final1-time .
wa_final-server = wa_final1-server.
wa_final-user = wa_final1-user.
var = wa_final1-wp.
wa_final-wp = var.
wa_final-seqno = wa_final1-seqno.
wa_final-e_line = wa_final1-e_line.
wa_final-errorid = v_errorid .
Clear var.
APPEND wa_final to it_final .
SORT it_final by time.
IF SY-SUBRC EQ 0.
CLEAR wa_final.
CLEAR wa_final1.
- ENDIF.
- ENDLOOP.
Loop at it_final into wa_final.
* WRITE:/ , 5 wa_final-server ,30 wa_final-user,50 wa_final-wp ,70 wa_final-errorid .
ENDLOOP.
- else.
* WRITE: ' NO Run Time errors found', /.
- ENDIF.
- " GET_DATA
*&---------------------------------------------------------------------*
*& Form CREATE_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM CREATE_MESSAGE .
** 1 Title, Description & Body.
PERFORM create_title_desc_body.
**2 Receivers
PERFORM fill_receivers.
- " CREATE_MESSAGE
*&---------------------------------------------------------------------*
*& Form CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* Title, Description and body
*----------------------------------------------------------------------*
FORM CREATE_TITLE_DESC_BODY .
* ...Title
wa_docdata-obj_name = 'Email notification'.
*...Description
wa_docdata-obj_descr = 'ABAP Runtime Error Alert'.
*...Message Body in HMTL
wa_objtxt-line = '<html> <body style="background-color:#FFE4C4;">'.
APPEND wa_objtxt TO it_objtxt.
*CONCATENATE 'Hi Team' 'This is to notify the ABAP runtime errors encountered today as listed below for last' Rvalue 'Hrs' INTO wa_objtxt-line SEPARATED BY SPACE.
wa_objtxt-line = 'Hi Team ,Please be notified of the ABAP runtime errors encountered today as listed below for last '.
* wa_objtxt-line = Rvalue .
* WRITE: l_lines, 'Run Time errors found', /.
CONCATENATE wa_objtxt-line Rvalue 'Hours'
INTO wa_objtxt-line SEPARATED BY space .
APPEND wa_objtxt TO it_objtxt.
* table display
wa_objtxt-line = '<table style="MARGIN: 10px" bordercolor="NavajoWhite" '.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = ' cellspacing="0" cellpadding="3" width="800"'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = ' border="1"><tbody><tr>'.
APPEND wa_objtxt TO it_objtxt.
* table header
wa_objtxt-line = '<th><font color="RoyalBlue">Server Name </font></th>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = '<th><font color="RoyalBlue">User Id</font></th>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = '<th><font color="RoyalBlue">Time</font></th>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = '<th><font color="RoyalBlue">Work Process Id</font></th>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = '<th><font color="RoyalBlue">Message Id</font></th>'.
APPEND wa_objtxt TO it_objtxt.
* table Contents
LOOP AT it_final INTO wa_final.
wa_objtxt-line = '<tr>'.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td><center>' wa_final-server '</center></td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td><center>' wa_final-user '</center></td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td><center>' wa_final-time '</center></td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td><center>' wa_final-wp '</center></td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td><center>' wa_final-errorid '</center></td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO it_objtxt.
CLEAR : wa_final.
ENDLOOP.
* table close
wa_objtxt-line = '</tbody> </table>'.
APPEND wa_objtxt TO it_objtxt.
* Signature color
wa_objtxt-line = '<br><br>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = '<p> Regards,</p>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt-line = '<p><b> Support Team</b></p>'.
APPEND wa_objtxt TO it_objtxt.
* HTML close
wa_objtxt-line = '</body> </html> '.
APPEND wa_objtxt TO it_objtxt.
* Document data
DESCRIBE TABLE it_objtxt LINES w_tab_lines.
READ TABLE it_objtxt INTO wa_objtxt INDEX w_tab_lines.
wa_docdata-doc_size =
( w_tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ).
* Packing data
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = w_tab_lines.
* we will pass the HTML, since we have created the message
* body in the HTML
wa_objpack-doc_type = 'HTML'.
APPEND wa_objpack TO it_objpack.
- " CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
*& Form FILL_RECEIVERS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_RECEIVERS .
** wa_reclist-receiver = 'xyz@abc.com'.
* wa_reclist-rec_type = 'U'.
* APPEND wa_reclist TO it_reclist.
* CLEAR wa_reclist.
LOOP AT EmailId INTO r_email.
MOVE r_email-low TO wa_reclist-receiver .
wa_reclist-rec_type = 'U'.
APPEND wa_reclist TO it_reclist.
ENDLOOP.
* CLEAR wa_reclist.
- " FILL_RECEIVERS
*&---------------------------------------------------------------------*
*& Form SEND_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SEND_MESSAGE .
* Send Message to external Internet ID
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
object_header = it_objhead
contents_txt = it_objtxt
receivers = it_reclist
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 NE 0.
* WRITE: /'Sending Failed'.
* ELSE.
* WRITE: /'Sending Successful'.
* ENDIF.
- " SEND_MESSAGE
--------------------------------------------------------------------------------------------------------