on 2007 Jul 18 1:34 PM
Hai,
we have developed a workflow for sales order.Once sales order creation & approval done the mail should go to customer(external mail).
The below code(sample code got from internet & modified) is works fine .But do not want to send attachement.We want to remove attachement part from the coding.Ie we want to send only message,not attachement.
Any tips?
Points will be given......Jaheer.
-
TABLES: VBAK.
PARAMETERS: Email TYPE somlreci1-receiver.
TYPES: BEGIN OF T_VBAK,
VBELN TYPE VBAK-VBELN,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
END OF T_VBAK.
DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,
WA_VBAK TYPE T_VBAK.
TYPES: BEGIN OF T_CHARVBAK,
VBELN(10) TYPE c,
VKORG(5) TYPE c,
VTWEG(8) TYPE c,
SPART(18) TYPE c,
END OF T_CHARVBAK.
DATA: WA_CHARVBAK TYPE T_CHARVBAK.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_xls_data_table.
END-OF-SELECTION.
perform populate_email_message_body.
write: 'Dear customer,'.
write:/20 'your sales document number has been approved:',vbak-vbeln
,
/40 'Best Regards'.
skip 1.
write:/20 'Name :----
'.
write:/20 'Signature:----
'.
write:/20 'Date :',sy-datum.
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using Email
'CUSTOMER .xls documnet attachment'
'XLS'
'CUSTOMER'
' '
' '
' '
changing gd_error
gd_reciever.
*
PERFORM initiate_mail_execute_program.
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data from vbeln table and populate itab it_vbak
----
FORM data_retrieval.
INCLUDE <CNTN01>.
DATA:CONTAINER LIKE SWCONT OCCURS 0 WITH HEADER LINE.
DATA obj_key TYPE swo_typeid. " Object key
SWC_SET_ELEMENT CONTAINER 'AUN' vbak-vbeln.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
OBJECT_TYPE = 'BUS2096'
OBJECT_KEY = OBJ_KEY
EVENT = 'ASSIGNED'
COMMIT_WORK = 'X'
EVENT_LANGUAGE = SY-LANGU
LANGUAGE = SY-LANGU
USER = SY-UNAME
IFS_XML_CONTAINER =
IMPORTING
RETURN_CODE =
EVENT_ID =
TABLES
INPUT_CONTAINER = CONTAINER
MESSAGE_LINES =
MESSAGE_STRUCT =
.
IMPORT vbak-vbeln FROM MEMORY ID 'SALESDOCUMENT'.
SELECT SINGLE * FROM VBAK WHERE VBELN = vbak-vbeln.
ENDFORM. " DATA_RETRIEVAL
&----
*& Form BUILD_XLS_DATA_TABLE
&----
Build data table for .xls document
----
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE c VALUE '0D', "OK for non Unicode
con_tab TYPE c VALUE '09'. "OK for non Unicode
CONCATENATE 'Sales Document' 'Sales Organization' 'Distribution
Channel' 'Division'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT IT_VBAK INTO WA_CHARVBAK.
CONCATENATE WA_CHARVBAK-VBELN WA_CHARVBAK-VBELN
WA_CHARVBAK-VKORG WA_CHARVBAK-VKORG
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
&----
Send email
----
FORM send_file_as_email_attachment tables pit_message
pit_attach
using sendmail
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
*
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = sendmail.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
w_doc_data-doc_size = 1.
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
CLEAR t_receivers.
*
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
*
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
ld_error = sy-subrc.
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM. "send_file_as_email_attachment
&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&----
Instructs mail send program for SAPCONNECT to send email.
----
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
&----
*& Form POPULATE_EMAIL_MESSAGE_BODY
&----
Populate message body text
----
form populate_email_message_body.
REFRESH it_message.
it_message = 'has been approved by CRISTAL'.
CONCATENATE 'Dear Customer,
Your Sales Document' VBAK-VBELN IT_MESSAGE 'Created by:' VBAK-ERNAM
'Sales office:'vbak-vkbur INTO IT_MESSAGE SEPARATED BY ' '.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
Try to do not use the Tables CONTENTS_BIN and CONTENTS_HEX in the call function of SO_DOCUMENT_SEND_API1.
I hope that work.
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this code. It is working fine for me,
REPORT ZMAIL.
data : document_data like SODOCCHGI1.
data : receivers like SOMLRECI1 OCCURS 0 WITH HEADER LINE,
object_content like SOLISTI1 OCCURS 0 WITH HEADER LINE.
subject line
document_data-obj_descr = 'My subject Line'.
Mail Content
object_content-line = 'My Content 1'.
APPEND object_content.
object_content-line = 'My Content 2'.
APPEND object_content.
Receiver type and ids
receivers-receiver = 'myname@myname.com'.
receivers-REC_TYPE = 'U'. "Email message
APPEND receivers.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = SENT_TO_ALL
NEW_OBJECT_ID = NEW_OBJECT_ID
TABLES
OBJECT_HEADER = OBJECT_HEADER
OBJECT_CONTENT = OBJECT_CONTENT
CONTENTS_HEX = CONTENTS_HEX
OBJECT_PARA = OBJECT_PARA
OBJECT_PARB = OBJECT_PARB
receivers = 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
U need to change the receiver type based on the type of mail that u send.
Thanks,
Prasath N
Hi Jaheer,
Why do you use code in stead of the standard send mail step? You can use this step also to send a mail to an external email address.
By the way if you use the code button to insert the code it would be better to read. But from the code I would say leave table t_attachment empty and the part from describe table t_attachment and the next 6 lines.
Regards,
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.