2007 Jul 12 4:54 AM
i am having internal table contains values.
i want that output should be send as an email attachment to email id given in selection screen.
but chinese can't diaplay rightly in attachment.eg:'批次; ','日期,and so on,all can't display rightly!
.please help me its urgent.thank you
*&---------------------------------------------------------------------*
*& Report YPD00010A
*&
*&---------------------------------------------------------------------*
*& DEVELOPER/DATE : SJDU / 12.06.2007
*& REPORT: display barcodes which can't be updated in the sta
*& of x_ray
*&---------------------------------------------------------------------*
REPORT YPD00010A no standard page heading
line-count 90
line-size 120 .
selection-screen begin of block sel with frame.
PARAMETERS:
PA_WERKS LIKE YP043D-WERKS OBLIGATORY DEFAULT '8000',
PA_MAIL like ys054-mailaddress MATCHCODE OBJECT ZMAILADDRESS,
PA_MAIL1 like ys054-mailaddress MATCHCODE OBJECT ZMAILADDRESS,
PA_ZBAT like YP043D-ZBAT OBLIGATORY MATCHCODE OBJECT ZZBAT. "File
selection-screen end of block sel.
DATA: BEGIN OF Line1,
ZBARCD LIKE yp043d-zbarcd,
END OF Line1.
DATA: ta_yp043d like Line1 occurs 0 with header line.
*****************************************************
data: begin of TAB,
X(1) type x value '09',
end of tab,
C(10) type c.
class cl_abap_char_utilities definition load.
c+5(1) = cl_abap_char_utilities=>horizontal_tab.
*********************************************************
DATA:
it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER
LINE,
it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER
LINE.
data: p_email TYPE somlreci1-receiver .
data: p_email2 TYPE somlreci1-receiver .
DATA: TP_MAIL(255) TYPE C.
DATA: TP_MAIL_MAIN(255) TYPE C.
DATA: TP_MAIL_TMP(255) TYPE C.
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_doc_data LIKE sodocchgi1,
w_cnt TYPE I,
w_sent_all(1) TYPE C,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA:COUNT1 TYPE I VALUE 0,
COUNT2 TYPE I VALUE 0.
INITIALIZATION.
clear: ta_yp043d, it_attach, it_message.
REFRESH: ta_yp043d, it_attach, it_message.
START-OF-SELECTION.
PERFORM GET_DATA.
IF PA_MAIL <> ' ' OR PA_MAIL1 <> ' '.
READ TABLE TA_YP043D INDEX 1.
IF SY-SUBRC = 0 .
pERFORM SEND_EMAIL.
ENDIF.
ENDIF.
END-OF-SELECTION.
PERFORM GET_WRITEDATA.
TOP-OF-PAGE.
PERFORM GET_HEADER.
END-OF-PAGE.
*&---------------------------------------------------------------------*
*& Form GET_HEADER *
*&---------------------------------------------------------------------*
*& To display the header *
*&---------------------------------------------------------------------*
FORM GET_HEADER.
data:
tp_header(120) type c.
TP_HEADER = '山东公司条码表'.
WRITE:4 '程序序号:',10 'YPD00010', 42 tp_header,
92 '日期:',102 SY-DATUM+0(4),
106 '年',
108 SY-DATUM+4(2),110 '月',112 SY-DATUM+6(2),114 '日',
/92 '时间 :',SY-TIMLO,
/3 '上传凭证:',18 PA_ZBAT, 92 '页码 :', SY-PAGNO.
ULINE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
DATA:TP_ZBARCD LIKE YP043-ZBARCD,
TP_ZBARCD1 LIKE YP043-ZBARCD,
TP_ZVALS LIKE YP043D-ZVALS.
SELECT ZBARCD INTO CORRESPONDING FIELDS OF TABLE ta_yp043d FROM YP043D
WHERE WERKS = PA_WERKS AND ZBAT = PA_ZBAT
AND ZUPDS = 'N' AND ZVALS = 'B' AND ZLVORM <> 'X'.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form GET_WRITEDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_WRITEDATA .
WRITE: /'硫化未上传的条码有:'.
SKIP.
LOOP AT TA_YP043D.
WRITE:TA_YP043D-ZBARCD,' '.
ENDLOOP.
ENDFORM. " GET_WRITEDATA
*&---------------------------------------------------------------------*
*& Form SEND_EMAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SEND_EMAIL.
READ TABLE TA_YP043D INDEX 1.
IF SY-SUBRC = 0 .
* Retrieve sample data from table ekpo
* PERFORM DATA_RETRIEVAL.
* Populate table with detaisl to be entered into .htm file
PERFORM BUILD_XLS_DATA_TABLE.
* Populate message body text
PERFORM POPULATE_EMAIL_MESSAGE_BODY.
* Send file by email attached as .htm file
PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
TABLES it_message
it_attach
USING p_email
'条码系统出库有问题的条码'
'HTML'
'WC_Document'
' '
' '
' '
CHANGING gd_error
gd_reciever.
* Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
ENDIF.
ENDFORM. " SEND_EMAIL
*&---------------------------------------------------------------------*
*& Form BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_XLS_DATA_TABLE .
CONCATENATE '<' 'HTML' '>' INTO it_attach .
APPEND it_attach.
CONCATENATE '<' 'HEAD' '>' INTO it_attach .
APPEND it_attach.
CONCATENATE
'<meta http-equiv=Content-Type content=' '"' 'text/html; charset= GB2312
''"' '>' INTO it_attach.
APPEND it_attach.
CONCATENATE '<' '/HEAD' '>' INTO it_attach .
APPEND it_attach.
CONCATENATE '<P style=''font-size:12.0PT''><B> 批次:' pa_zbat
'</B></P>' INTO it_attach SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>horizontal_tab.
APPEND it_attach.
CONCATENATE '<P style=''font-size:12.0pt''><B> 日期:' sy-datum
'</B></P>' INTO it_attach SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>horizontal_tab.
APPEND it_attach.
CONCATENATE '<P style=''font-size:12.0pt''><B>' '硫化未上传的条码有: '
'</B></P>' INTO it_attach SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>horizontal_tab.
APPEND it_attach.
*CONCATENATE '<P style=''font-size:12.0pt''><B>' ' ' ' </B></P>' INTO
*it_attach.
*APPEND it_attach.
LOOP AT TA_YP043D .
*CONCATENATE '< style=''font-size:12.0pt''><B> ' TAB-ZBARCD '</B>'
CONCATENATE '<B> ' TA_YP043D-ZBARCD ' </B>' INTO
it_attach .
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
*& Form POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM POPULATE_EMAIL_MESSAGE_BODY .
DATA: TP_TEST0(255) TYPE C,
TP_TEST3(255) TYPE C,
TP_TEST(255) TYPE C.
TP_TEST = '当轮胎进行X光机数据上传时,有些条码在硫化阶段不存在资料'.
TP_TEST0 = '请您查看并尽快解决.'.
CONCATENATE TP_TEST TP_TEST0 INTO TP_TEST3 SEPARATED BY ' , '.
APPEND '尊敬的先生/女士,' TO it_message.
APPEND ' ' TO it_message.
APPEND TP_TEST3 TO it_message.
APPEND '具体问题请查看附件.' TO it_message.
APPEND ' ' TO it_message.
APPEND '谢谢.' TO it_message.
APPEND ' ' TO it_message.
APPEND '来自,' TO it_message.
APPEND SY-UNAME TO it_message.
ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
*&----------------------------------------------------------------------
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT *
*&---------------------------------------------------------------------*
*& Send email *
*&---------------------------------------------------------------------*
FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES pit_message
pit_attach
USING p_email
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_email2 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 value
'no-reply@silverstoneluhe.com.cn',
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: TMP_MAIL(40) TYPE C.
DATA: MAIN_EMAIL(40) TYPE C.
DATA: TMP_POS TYPE I .
DATA: ADD_EMAIL(40) TYPE C.
DATA: L_POS TYPE I, R_POS TYPE I, MAIL_LEN TYPE I.
ld_email = p_email.
ld_email2 = p_email2.
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.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
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'.
* Fill the document data and get size of attachment
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[].
* Describe the body of the message
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-obj_name = ld_attfilename.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
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.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
TP_MAIL_MAIN = PA_MAIL.
TP_MAIL = PA_MAIL1.
if sy-subrc = 0 .
t_receivers-receiver = TP_MAIL_MAIN.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
ENDIF.
********************************************
*READ FROM TP_MAIL LIST
TP_MAIL_TMP = TP_MAIL .
WHILE SY-SUBRC = 0 .
SEARCH TP_MAIL_TMP FOR ', ' .
MAIL_LEN = STRLEN( TP_MAIL_TMP ) .
IF SY-SUBRC = 0 .
TMP_POS = sy-fdpos .
ADD_EMAIL = TP_MAIL_TMP+0(TMP_POS) .
R_POS = TMP_POS + 2 .
L_POS = MAIL_LEN - TMP_POS .
TP_MAIL_TMP = TP_MAIL_TMP+R_POS(L_POS) .
ELSE.
ADD_EMAIL = TP_MAIL_TMP .
ENDIF.
t_receivers-receiver = ADD_EMAIL.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
t_receivers-COPY = 'X' .
APPEND t_receivers.
ENDWHILE.
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.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
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
Message was edited by:
shanjing du
Message was edited by:
shanjing du
2007 Jul 12 7:47 AM
I haven't use cl_bcs,i don't know how to use it.who can u give me a example about it? thank u!
2007 Jul 12 5:07 AM
Try using the new object based mail sending - CL_BCS
See documentation under "Generic Business Tools for Application Developers (BC-SRV-GBT)" in SAP Help (Business Communication Services - Sending in SAP Applications as of Release 6.10 )
http://help.sap.com/saphelp_nw2004s/helpdata/en/2d/1c5d3aebba4c38e10000000a114084/frameset.htm
The CREATE_DOCUMENT and ADD_ATTACHMENT methods of CL_DOCUMENT_BCS that is used to create the message body both have language parameters that may solve your problem.
Andrew
2007 Jul 12 7:47 AM
I haven't use cl_bcs,i don't know how to use it.who can u give me a example about it? thank u!
2007 Jul 15 6:24 AM
Hi,
Pls. refer blog https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/789. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
It is excellent blog describing BCS..
BCS provides simplified interfaces for email related activities.. very easy to use..
Regards,
Abhijit
2007 Jul 12 8:11 AM
Try the following.
You may need to add language parameter to "CALL METHOD cl_document_bcs=>create_document", or perhaps replace it with a call to the ADD_ATTACHMENT method or some other method of this class - there are public methods for text, MIME, office documents.
==================
&----
*& Report ZLOCAL_EMAIL_TEST
*&
&----
*
Test of ECC Send email using class CL_BCS
*
&----
REPORT zlocal_email_test.
DATA:
l_obj TYPE REF TO cl_bcs,
l_recip TYPE REF TO if_recipient_bcs,
l_rec TYPE REF TO cl_cam_address_bcs,
sender TYPE REF TO if_sender_bcs,
note TYPE bcsy_text,
line TYPE soli,
l_address TYPE adr6-smtp_addr,
l_result TYPE os_boolean,
l_sub TYPE string,
text TYPE bcsy_text,
document TYPE REF TO cl_document_bcs.
parameters: p_email like ADR6-SMTP_ADDR visible length 70,
p_uname like sy-uname default sy-uname.
START-OF-SELECTION.
Create email instance
l_obj = cl_bcs=>create_persistent( ).
Build text of message
APPEND 'Hello World' TO text.
APPEND 'Hello World 2' TO text.
APPEND 'Hello World 3' TO text.
APPEND 'Hello World 4' TO text.
Create the email document
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'RAW'
i_subject = 'subject line'
I_LENGTH =
I_LANGUAGE = SPACE
I_IMPORTANCE =
I_SENSITIVITY =
i_text = text
I_HEX =
I_HEADER =
I_SENDER =
RECEIVING
result = document.
Add document to email object
CALL METHOD l_obj->set_document
EXPORTING
i_document = document.
Short form version
CALL METHOD l_obj->set_document( document ).
Build long subject line
CONCATENATE 'Long subject' sy-abcde 'with still more'
'Long subject' sy-abcde 'with still more'
'Long subject' sy-abcde 'with still more'
INTO l_sub SEPARATED BY space.
Add long subject to the email
CALL METHOD l_obj->set_message_subject
EXPORTING
ip_subject = l_sub.
Get recipient address in correct format
CALL METHOD cl_cam_address_bcs=>create_internet_address
EXPORTING
i_address_string = p_email
RECEIVING
result = l_rec.
Add recipient address to the email
CALL METHOD l_obj->add_recipient
EXPORTING
i_recipient = l_rec
i_express = 'X'.
Get Sender address in correct format
CALL METHOD cl_sapuser_bcs=>create
EXPORTING
i_user = p_uname
RECEIVING
result = sender.
Short form version of this method call
sender = cl_sapuser_bcs=>create( sy-uname ).
Add sender to the email
CALL METHOD l_obj->set_sender
EXPORTING
i_sender = sender.
Send the email
CALL METHOD l_obj->send
EXPORTING
I_WITH_ERROR_SCREEN = SPACE
RECEIVING
result = l_result.
Required commit work.
COMMIT WORK.
*
2007 Jul 14 11:36 AM
hi,i use the code that u gave me,and i can't receive that email.i don't know why.
2007 Jul 15 6:28 AM
Hi,
Have you maintained email address your for your user in SU01?.. You need to maintain this email which is used as sender's email... You can visit SCOT transaction and check pending emails and status messages for finding out exact error...
Alos, Have you maintained customizations in SCOT transaction?
Regards,
Abhijit
2007 Jul 15 4:27 AM
Hi,
I have tried the program in both ECC5 and ECC6 and it works fine. Not sure what to suggest. Does the message appear in SOST to be sent? (you may need to select additional options in SOST to see all messages - check the tabs on the header area of the screen). If you can find it there, then the trace details may give more information.
Andrew