Hello Guys,
I have created one abap program which will send the information in mail to requisite receiver giving details about the status and object included in that TR send betweeen nth day to today date. This program is created to give the information in below format.
Transport Date Author System ProgramID ObjectType Object Id
XX0K9932XX 15.05.2013 0906XXXX QXX R3TR MPRO ZMRPXXX
This information is stored in TPALOG(DB Buffer for ALOG File) and E071(Change & Transport System: Object Entries of Requests/Tasks). There will be parameter for Number Of Days(old we want to see the data), Program ID, Receiptents, Object ID and Object Name.
If we give Number Of days as 1 and Program ID as CORR then data should come for date range Today Date - 1 to Today Date and PGMID as CORR.
Logic : It will hit table TPALOG and fetch Transport Number, Author, target System, Time into internal table with condition Systemdate-Number of days<=TRTIME
>=system date.
Then we will read E071 table to fetch Object ID , Object Name and Program ID where Transport number is wat we have fecth above and Program ID which is passed by user in parameter.
Below is the sample code for this:
REPORT ZTRAN***** MESSAGE-ID 00.
tables : BALHDR.
TABLES: e071 ,tpalog.
DATA: BEGIN OF it_tpalog OCCURS 0,
trtime TYPE tpalog-trtime,
trkorr TYPE tpalog-trkorr,
trstep TYPE tpalog-trstep,
truser TYPE tpalog-truser,
tarsystem TYPE tpalog-tarsystem,
retcode TYPE tpalog-retcode,
END OF it_tpalog.
DATA: BEGIN OF it_e071 occurs 0,
trkorr TYPE e071-trkorr,
object TYPE e071-object,
pgmid TYPE e071-pgmid,
obj_name TYPE e071-obj_name,
END OF it_e071.
DATA: BEGIN OF it_final OCCURS 0,
trkorr TYPE tpalog-trkorr,
truser TYPE tpalog-truser,
tarsystem TYPE tpalog-tarsystem,
retcode TYPE tpalog-retcode,
object TYPE e071-object,
pgmid TYPE e071-pgmid,
obj_name TYPE e071-obj_name,
trtime TYPE tpalog-trtime,
END OF it_final.
DATA: date1(14) TYPE n,
date2(14) TYPE n,
date TYPE sy-datum,
stamp(6) TYPE c value '000000'.
PARAMETERS: Days(2) TYPE n DEFAULT '01'.
SELECT-OPTIONS: Prog_ID FOR e071-pgmid,
Obj_Type FOR e071-object,
Obj_Name FOR e071-obj_name.
date = sy-datum - days.
CONCATENATE date stamp INTO date1.
CONCATENATE sy-datum sy-uzeit INTO date2.
************************************************************
* For Mail Sending
************************************************************
data : gv_title(255).
data : l_sysid type xuvalue.
* Email data
DATA: v_recv LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
v_document_data LIKE sodocchgi1.
DATA: object_id LIKE sofolenti1-object_id,
objcont LIKE soli OCCURS 10 WITH HEADER LINE,
OBJECT_HEADER like SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: gv_receiver TYPE somlreci1-receiver.
INITIALIZATION.
clear gv_title.
Concatenate 'The following objects have been imported by transports below. Please review' '*****' into gv_title SEPARATED BY space.
SELECTION-SCREEN BEGIN OF BLOCK B.
SELECT-OPTIONS: s_mail FOR gv_receiver LOWER CASE NO INTERVALS.
SELECTION-SCREEN end of block B.
AT SELECTION-SCREEN.
READ TABLE s_mail INDEX 1.
IF sy-subrc <> 0.
MESSAGE e001 WITH 'Please enter at least one email address'.
ENDIF.
* Reciever's email Id should be valid
LOOP AT s_mail.
IF NOT s_mail-high IS INITIAL.
MESSAGE e001 WITH s_mail-high 'is not valid. Please enter with no intervals'.
ENDIF.
ENDLOOP.
START-OF-SELECTION.
* Select data from the Broadcast table for the selection
PERFORM Z_SELECTDATA.
END-OF-SELECTION.
FORM Z_SELECTDATA.
SELECT trkorr trstep truser tarsystem trtime INTO CORRESPONDING FIELDS OF TABLE it_tpalog FROM tpalog
WHERE retcode IN ('0004', '0000', '0008', '0012') AND trstep = 'I' AND trtime GE date1 AND trtime LE date2.
*WRITE:/ date1.
*write:/ date2.
LOOP AT it_tpalog.
SELECT trkorr object pgmid obj_name INTO CORRESPONDING FIELDS OF TABLE it_e071 FROM e071 WHERE trkorr = it_tpalog-trkorr AND pgmid IN Prog_ID.
* WRITE:/ it_tpalog-trkorr, it_tpalog-trstep, it_tpalog-truser, it_tpalog-tarsystem.
ENDLOOP.
LOOP AT it_e071.
READ TABLE it_tpalog WITH KEY trkorr = it_e071-trkorr.
IF sy-subrc = 0.
it_final-trkorr = it_tpalog-trkorr.
it_final-truser = it_tpalog-truser.
it_final-tarsystem = it_tpalog-tarsystem.
it_final-retcode = it_tpalog-retcode.
it_final-object = it_e071-object.
it_final-pgmid = it_e071-pgmid.
it_final-obj_name = it_e071-obj_name.
it_final-trtime = it_tpalog-trtime.
ENDIF.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
PERFORM Z_DISPLAY.
ENDFORM.
FORM Z_DISPLAY.
data: l_message(300).
* Display Broadcast status as a list.
OBJECT_HEADER-line = gv_title.
append OBJECT_HEADER.
CONCATENATE '*********' 'The following objects have been imported by transports below. Please review' '********' INTO objcont-line SEPARATED BY space.
APPEND objcont.
WRITE: sy-uline(66) TO objcont-line.
APPEND objcont.
CONCATENATE sy-vline ' Transport ' sy-vline 'Date ' sy-vline
'Author ' sy-vline 'System ' sy-vline 'Program ID ' sy-vline 'Object Type ' sy-vline 'Object Id ' INTO objcont-line.
APPEND objcont.
WRITE: sy-uline(66) TO objcont-line.
APPEND objcont.
REFRESH v_recv.
CLEAR v_recv.
LOOP AT s_mail.
* receivers
v_recv-receiver = s_mail-low. "recipient
v_recv-express = 'X'.
v_recv-rec_type = 'U'. "internet email
APPEND v_recv.
ENDLOOP.
LOOP AT it_final.
WRITE: sy-uline(66) TO objcont-line.
CLEAR objcont.
CONCATENATE sy-vline it_final-trkorr sy-vline it_final-trtime+0(8) sy-vline it_final-truser sy-vline
it_final-tarsystem sy-vline it_final-pgmid sy-vline it_final-object sy-vline
sy-vline it_final-obj_name sy-vline into objcont-line.
APPEND objcont.
ENDLOOP.
v_document_data-obj_descr = gv_title.
* clear p_title.
* send mail message
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = v_document_data
document_type = 'RAW'
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
new_object_id = object_id
TABLES
OBJECT_HEADER = OBJECT_HEADER
object_content = objcont
receivers = v_recv
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 <> 0.
MESSAGE s001 WITH 'Email was not sent'.
ELSE.
MESSAGE s001 WITH 'Email was successfully sent'.
ENDIF.
ENDFORM.
When You execute the program the output will be like:
Mail output LIke this:
Thanks
P.S --> Form ZSELECT_DATA can also be written like this in fewer lines:
FORM Z_SELECTDATA.
*
SELECT tp~trkorr tp~trstep tp~truser tp~tarsystem e7~object e7~pgmid e7~obj_name
FROM tpalog AS tp INNER JOIN e071 AS e7 ON e7~trkorr = tp~trkorr INTO CORRESPONDING FIELDS OF TABLE it_final
WHERE tp~retcode IN ('0004', '0000', '0008', '0012') AND tp~trstep = 'I' AND tp~trtime GE date1 AND tp~trtime LE date2 AND e7~pgmid IN Prog_ID.
IF sy-subrc = 0.
** Display data of Broadcast status
* PERFORM Z_DISPLAY.
ELSEIF sy-subrc <> 0.
MESSAGE s001 WITH 'No Errors Occurred.'.
ENDIF.
*ENDFORM.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |