Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem for attaching PDF while using CL_BCS

Former Member
0 Likes
1,827

Hi Gurus,

I have to send PDF as attachment and I am using CL_BCS for sending mail and attachments

I have tried following example code:

DATA pdf_content TYPE solix_tab.

DATA lp_pdf_size TYPE so_obj_len.

DATA pdf TYPE xstring.

DATA w_document TYPE REF TO cl_document_bcs,

pdf = 'TEST LINE'.

pdf_content = cl_document_bcs=>xstring_to_solix(

ip_xstring = pdf ).

lp_pdf_size = XSTRLEN( pdf ).

->The following method call is to create document for HTML format

w_document = cl_document_bcs=>create_document(

i_type = 'HTM'

i_text = OBJTXT[]

i_length = w_length

i_subject = us_subject ).

-> Now I am trying to attach PDF

CALL METHOD W_DOCUMENT->ADD_ATTACHMENT

EXPORTING

I_ATTACHMENT_TYPE = 'PDF'

I_ATTACHMENT_SUBJECT = 'TEST.PDF'

I_ATTACHMENT_SIZE = lp_pdf_size

I_ATT_CONTENT_HEX = pdf_content[].

After trying the above piece of code I was able to send email (used all required methods of class for sending email) but when I open PDF it is giving following error...

File does not begin with '%PDF-"

Please let me know what all setting I am missing.

Thanks !!!

Naveen

2 REPLIES 2
Read only

Former Member
0 Likes
927

check page26 of this document https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e0bba346-cb84-2910-2aa9-ba1f8a1c...

code reference from above document

document = cl_document_bcs=>create_document(
i_type = 'RAW'  " <--------------------------
i_text = l_mailtext
i_length = textlength
i_subject = l_subject ).


attdoctype = 'pdf'.
atttitle = 'CreateFlight'.  "<------------- no extn .pdf specified
attsize = xstrlen( pdf ).
pdftab = cl_document_bcs=>xstring_to_solix(
ip_xstring = pdf ).
document->add_attachment( exporting I_ATTACHMENT_TYPE = attdoctype
I_ATTACHMENT_SUBJECT = atttitle
I_ATTACHMENT_SIZE = attsize
I_ATTACHMENT_LANGUAGE = sy-langu
I_ATT_CONTENT_HEX = pdftab ).

кu03B1ятu03B9к

Edited by: kartik tarla on Feb 8, 2009 2:03 PM

Read only

Former Member
0 Likes
927

I got a very good idea with the document.

Thanks Kartik,