2007 Sep 28 8:20 AM
Hi Gurus
I have to send output of report as pdf attachment of the email.
I have used Fm CONVERT_ABAPSPOOLJOB_2_PDF to convet spool request to pdf format.
and SO_DOCUMENT_SEND_API1 Fm to send email. Its working Fine.
But Now i need to send email by using Methods,My code is as below
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
DATA: it_pdf_output2 type SOLIX_TAB occurs 0.
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
DATA:
*it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att_wa TYPE solisti1,
gti_documents TYPE zsti_email_documents,
g_documents_wa TYPE LINE OF zsti_email_documents,
gti_recipients TYPE zsti_email_recipients,
g_recipients_wa TYPE LINE OF zsti_email_recipients,
gti_contents_hex TYPE solix_tab,
gti_contents_text TYPE soli_tab.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
<b>it_pdf_output is to be converted into gti_contents_hex.</b>
LOOP AT it_pdf_output INTO mess_att_wa.
MOVE mess_att_wa-line TO contents_hex_wa-line.
APPEND contents_hex_wa TO gti_contents_hex.
ENDLOOP.
g_documents_wa-type = 'RAW'.
g_documents_wa-subject = 'KUMAR TEST '.
g_documents_wa-content_hex = xcontent_hex.
APPEND g_documents_wa TO gti_documents.
DATA:email TYPE so_name.
email = 'kumar@gmail.com'.
g_recipients_wa-uname = 'KUMAR'.
g_recipients_wa-c_address = email.
APPEND g_recipients_wa TO gti_recipients.
TRY.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
APPEND 'hello world' TO text.
APPEND '20/09/2007' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = 'subject' ).
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = gd_subject
<b>i_att_content_hex = gti_contents_hex.</b>
add document to send request
CALL METHOD send_request->set_document( document ).
--------- set sender -------------------------------------------
note: this is necessary only if you want to set the sender
different from actual user (SY-UNAME). Otherwise sender is
set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
--------- add recipient (e-mail address) -----------------------
create recipient - please replace e-mail address !!!
recipient = cl_cam_address_bcs=>create_internet_address( email ).
add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
set send immediately flag
send_request->set_send_immediately( 'X' ).
---------- send document ----------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
-----------------------------------------------------------
exception handling
CATCH cx_bcs INTO bcs_exception.
WRITE: bcs_exception->error_type.
EXIT.
ENDTRY.
MY problem is:
Iam receiving 'hello world' and '20/09/2007' as a pdf file in mail.But the actual data
from CONVERT_ABAPSPOOLJOB_2_PDF (it_pdf_output) is not getting in the pdf file.
Iam receiving the email properly with pdf attached, but no data in pdf.
Can any one please help me,its very ugrent
The Bold line above is the problem here ,the data from Fm it_pdf_output is of type tline and the method takes data as HEX. How to convert ?
2007 Sep 28 10:34 AM
Sudheer,
Refer to this link... https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/smartformtoMailasPDF+attachment&