Wednesday, July 30, 2008

Execute report from sap mail

By Joyjit Ghosh,
Kolkata, India.

*&---------------------------------------------------------------------*
*& Report Z_DEMO_MAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT z_demo_mail.


*&---------------------------------------------------------------------*
*& Global data declaration
*&---------------------------------------------------------------------*

DATA:
w_document_data LIKE sodocchgi1.

DATA:
i_object_header TYPE STANDARD TABLE OF solisti1,
w_object_header TYPE solisti1,

i_object_content TYPE STANDARD TABLE OF solisti1,
w_object_content TYPE solisti1,

i_contents_hex TYPE STANDARD TABLE OF solix,
w_contents_hex TYPE solix,

i_object_para TYPE STANDARD TABLE OF soparai1,
w_object_para TYPE soparai1,

i_object_parb TYPE STANDARD TABLE OF soparbi1,
w_object_parb TYPE soparbi1,

i_receivers TYPE STANDARD TABLE OF somlreci1,
w_receivers TYPE somlreci1.

*&---------------------------------------------------------------------*
*& Selection screen
*&---------------------------------------------------------------------*
PARAMETER : uname TYPE syuname DEFAULT sy-uname.

*&---------------------------------------------------------------------*
*& Start-of-selection event
*&---------------------------------------------------------------------*
START-OF-SELECTION.

* Populate receiver info
clear: w_receivers.
w_receivers-receiver = uname.
w_receivers-rec_type = 'B'.
append w_receivers to i_receivers.

* Populate header data
w_document_data-obj_name = 'Your action required'.
w_document_data-obj_descr = 'Pl. press execute button'.
w_document_data-sensitivty = 'O'.
w_document_data-proc_type = 'R'.
w_document_data-proc_name = 'RSINCL00'.


* Populate mail content
clear: w_object_content.
concatenate 'Please execute report: '
w_document_data-proc_name
into w_object_content-line separated by space.
append w_object_content to i_object_content.


CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_document_data
DOCUMENT_TYPE = 'RAW'
* PUT_IN_OUTBOX = ' '
* COMMIT_WORK = ' '
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
tables
* OBJECT_HEADER =
OBJECT_CONTENT = i_object_content
* CONTENTS_HEX =
OBJECT_PARA = i_object_para
* OBJECT_PARB =
receivers = i_receivers
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 s000(z_zzz_ca_messages)
with 'Mail send successfully'(001).
ENDIF.

No comments: