Hi Puneet,
You can do it two ways, Either you send the Table in the body of the mail or You download the table into an Excel File and attach it to mail. You can do it programatically using:-
----
SUBROUTINE : SEND_EMAIL_MESSAGE *
----
Description : Subroutine to send the composed EMAIL to assigned *
Processors *
----
Interface : *
-->IT_MESSAGE - Internal table to hold the body of EMAIL *
-->IV_PROCESSOR- Import parameter containing the Recepient's Mail Id*
----
FORM send_email_message USING it_message LIKE gt_message
iv_processor.
CONSTANTS: lc_subject(40) TYPE c
VALUE 'CDOP Object List for you'."#EC NOTEXT
DATA: lt_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
lt_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA: lv_doc_data LIKE sodocchgi1.
Fill the document data.
lv_doc_data-doc_size = 1.
Populate the subject/generic message attributes
lv_doc_data-obj_langu = sy-langu.
lv_doc_data-obj_name = 'SAPRPT'.
lv_doc_data-obj_descr = lc_subject.
lv_doc_data-sensitivty = 'F'.
Describe the body of the message
CLEAR lt_packing_list.
REFRESH lt_packing_list.
lt_packing_list-transf_bin = space.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES lt_packing_list-body_num.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.
Add the recipients email address
CLEAR lt_receivers.
REFRESH lt_receivers.
lt_receivers-receiver = iv_processor.
lt_receivers-rec_type = 'B'.
APPEND lt_receivers.
Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lv_doc_data
TABLES
packing_list = lt_packing_list
contents_txt = it_message
receivers = lt_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.
ENDIF.
ENDFORM. "send_email_message
The above is sample code. You can use the function *module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send mails. Also the *attahments.
Thanks and regards,
Ravi:).
Note: Points keep me alive on SDN 😊.
Hi Puneet,
Find below the report by which you can fetch the values from a DB table say MARA and append them into the body of an email and send it across the desired users.
-
REPORT zsapmailtest .
*Data declaration part
DATA: lv_object_type LIKE sood-objtp.
DATA: BEGIN OF gt_object_hd_change.
INCLUDE STRUCTURE sood1.
DATA: END OF gt_object_hd_change.
DATA: BEGIN OF gt_objcont OCCURS 10.
INCLUDE STRUCTURE soli.
DATA: END OF gt_objcont.
DATA: BEGIN OF gt_objhead OCCURS 0.
INCLUDE STRUCTURE soli.
DATA: END OF gt_objhead.
DATA: BEGIN OF raw_head.
INCLUDE STRUCTURE sorh.
DATA: END OF raw_head.
DATA: BEGIN OF gt_receivers OCCURS 0.
INCLUDE STRUCTURE soos1.
DATA: END OF gt_receivers.
DATA : BEGIN OF gt_mara OCCURS 0,
matnr LIKE mara-matnr,
ernam LIKE mara-ernam,
END OF gt_mara.
PARAMETERS: receiver LIKE gt_receivers-recnam. " Name
*BUILD MESSAGE HEADER
MOVE 'Sort field goes here' TO gt_object_hd_change-objsrt. " Sort field
MOVE 'Name of the object goes here' TO gt_object_hd_change-objnam. " Name
MOVE 'Document title goes here' TO gt_object_hd_change-objdes. " Title
MOVE 'F' TO gt_object_hd_change-objsns. " Functional OBJECT
MOVE 'E' TO gt_object_hd_change-objla. " Language
Object type of the new document
MOVE 'RAW' TO lv_object_type.
CLEAR gt_objcont.
*Body of the mail . Where you can Loop the table and sent it across
<b>SELECT matnr ernam FROM mara
INTO TABLE gt_mara.
gt_objcont-line+0(18) = 'Material Name'.
gt_objcont-line+28(38) = 'Created by'.
APPEND gt_objcont.
gt_objcont-line = '----
'..
APPEND gt_objcont.
*Writing the contents of the internal table to the body of the mail
LOOP AT gt_mara.
CLEAR gt_objcont.
gt_objcont-line+0(18) = gt_mara-matnr.
gt_objcont-line+19(38) = gt_mara-ernam.
APPEND gt_objcont.
ENDLOOP.</b>
Specific header (Dependent on the object type, here RAW)
REFRESH gt_objhead.
DESCRIBE TABLE gt_objcont LINES raw_head-rawsiz.
MOVE raw_head TO gt_objhead.
APPEND gt_objhead.
*RECEIVERS table
CLEAR gt_receivers.
REFRESH gt_receivers.
MOVE receiver TO gt_receivers-recnam. " Name
MOVE 'B' TO gt_receivers-recesc. " Receiver type
MOVE 'X' TO gt_receivers-sndcp. " Send as a copy
MOVE 'X' TO gt_receivers-sndex. " EXPRESS DOCUMENT
APPEND gt_receivers.
*Function module to send mail
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = gt_object_hd_change
object_type = lv_object_type
outbox_flag = 'X'
owner = sy-uname
TABLES
objcont = gt_objcont
objhead = gt_objhead
receivers = gt_receivers.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
-
Hope the above code is simple and fulfills your requirement.
Thanks and regards,
Siva
Hi Puneet,
You can fetch e-mail id of recipient in program and pass the values directly to this field(gt_receivers-recnam) in the above code and append them instead of supplying the values to this field from the input parameter of the selection screen
<b>MOVE receiver TO gt_receivers-recnam. </b>
The above code runs in my system without any Runtime error.I have checked in SAP ENT system.
Thanks and Regards,
Siva
Hi Puneet,
See Rich's post in this thread:
Explore a bit of HTML for including tables in the body of the mail.
Regards,
Ravi
Add a comment