08-28-2015 9:33 AM
Dear All,
I have to send PDF file which contains billing document number whose processing status not equal to 1. I am able to send mail with PDF attachment using class CL_BCS, but when I am trying to open PDF file in inbox it gives me an error as : Adobe reader could not open file ..... because it is either not a supported file or because the file is damaged.
below is the code:
global decalartion
DATA:
gt_alv_final_output TYPE string,
g_pdf_content TYPE solix_tab ,
g_pdf_size TYPE so_obj_len,
g_pdf_xstring TYPE xstring.
METHOD convert_to_pdf.
try.
CONSTANTS:
"Constant value for calculation of size of table
lc_255_size_cal TYPE i VALUE 255.
DATA:
l_lines TYPE i.
"Convert To Xstring
g_pdf_xstring = cl_bcs_convert=>string_to_xstring( gt_alv_final_output ).
"Convert to solix_tab
g_pdf_content = cl_bcs_convert=>Xstring_to_solix( g_pdf_xstring ).
"Size to multiplied by 2 for UNICODE enabled systems
* DESCRIBE TABLE g_pdf_content LINES l_lines.
catch cx_bcs.
endtry.
"Get Size of String
g_pdf_size = XSTRLEN( g_pdf_xstring ).
g_pdf_size = l_lines * 2 * lc_255_size_cal.
ENDMETHOD.
METHOD send_data.
CONSTANTS:
"Constant value XLS for file extension
lc_pdf_ext TYPE soodk-objtp VALUE 'PDF',
"Constant value RAW Type for Document Class
lc_raw_type TYPE so_obj_tp VALUE 'RAW'.
DATA:
"Variable for EMail send request
l_send_request TYPE REF TO cl_bcs,
"Variable for create document
l_document TYPE REF TO cl_document_bcs,
"Variable for recipients of distribution list
l_recipients TYPE REF TO if_recipient_bcs,
"Variable for Address of sender
l_sender TYPE REF TO if_sender_bcs,
"Variable for name of sender(sy-uname)
l_username TYPE salrtdrcpt,
"text for body content
l_text type bcsy_text.
TRY.
* create persistent send request
l_send_request = cl_bcs=>create_persistent( ).
* add document
append 'Hello!'(004) to l_text.
l_document = cl_document_bcs=>create_document(
i_type = lc_raw_type
i_text = l_text
i_subject = 'Check Archived Invocies'(003) ).
"Add Attachment to mail
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = lc_pdf_ext
i_attachment_size = g_pdf_size
i_attachment_subject = 'TEST_ZRD8'(002)
i_att_content_hex = g_pdf_content.
* "Add document to send request
CALL METHOD l_send_request->set_document( l_document ).
"Get Sender Object
l_username = sy-uname.
"Prepare the sender object
l_sender = cl_sapuser_bcs=>create( l_username ).
"Set the sender
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
"Get Recepient - Shared distribution list
l_recipients = cl_distributionlist_bcs=>getu_persistent(
i_dliname = lc_distribution_list
i_private = space ).
"Add recipient
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipients
i_express = 'U'.
"Set that you don't need a Return Status E-mail
CALL METHOD l_send_request->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail = 'E'.
"Trigger mail immediately
l_send_request->set_send_immediately( abap_true ).
"Send Mail
CALL METHOD l_send_request->send( ).
"Commit work
COMMIT WORK.
MESSAGE s001.
CATCH cx_document_bcs.
CATCH cx_send_req_bcs.
.
CATCH cx_address_bcs.
CATCH cx_bcs.
ENDTRY.
ENDMETHOD.
Screen shot for error.
Please give me solution for this.
Regards,
Mahadeo.
08-28-2015 9:52 AM
Hy Mahadeo,
do you call the convert_to_pdf method while you call send_data method? The code you posted doesn't include a method call for convert_to_pdf.
Is an exception raised within your methods?
I would try with CL_GUI_FRONTEND_SERVICES to download the pdf you created first. Cause when you are able to download the pdf file & it opens correctly then you are sure, that the file can be mailed as well.
Kind regards,
Michael
08-28-2015 10:03 AM
Hi Michael,
Thanx for you reply.
I first call convert_to_pdf file and then send_data method. In my code I am not able to find the bug. are you able to find it?
I executed BCS_EXAMPLE_6 program it worked properly.
regards,
Mahadeo.
08-28-2015 10:08 AM
I think the attachment size you are ending in the ADD_ATTACHMENT method is not right.
You can try this.
At the end of convert_to_pdf method
Yours one :
"Get Size of String
g_pdf_size = XSTRLEN( g_pdf_xstring ).
g_pdf_size = l_lines * 2 * lc_255_size_cal.
should be :
"Get Size of String
g_pdf_size = XSTRLEN( g_pdf_xstring ).
g_pdf_size = g_pdf_size * 2.
R
08-28-2015 10:07 AM
g_pdf_size = XSTRLEN( g_pdf_xstring ).
g_pdf_size = l_lines * 2 * lc_255_size_cal.
First is right, but second seems wrong. Delete/comment second line...
08-28-2015 10:08 AM
08-28-2015 12:50 PM
Hello all,
Please give suggestion on this problem. It is very urgent.
Now I stored data in table of type soli_tab and then converted it to type solix_tab but Same prob
data:
gt_alv_final_output TYPE soli_tab.
METHOD convert_to_pdf.
CONSTANTS:
"Constant value for calculation of size of table
lc_255_size_cal TYPE i VALUE 255.
DATA:
l_lines TYPE i.
try.
"Convert To Xstring
* g_pdf_xstring = cl_bcs_convert=>soli_to_xstring( gt_alv_final_output ).
* g_pdf_content = cl_bcs_convert=>xstring_to_solix( g_pdf_xstring ).
"Convert to solix_tab
g_pdf_content = cl_bcs_convert=>soli_to_solix( gt_alv_final_output ).
catch cx_bcs.
endtry.
"Get Size of String
* g_pdf_size = xstrlen( g_pdf_xstring ).
DESCRIBE TABLE gt_alv_final_output LINES L_LINES.
"Size to multiplied by 2 for UNICODE enabled systems
g_pdf_size = L_LINES * 2 * lc_255_size_cal.
ENDMETHOD.
08-28-2015 1:12 PM
Your code to get file size is wrong.
What if actuall file has lets say 123 bytes? Your code would return 1*2*255 = 500 bytes file!
What is "gt_alv_final_output"? In first post it is XSTRING, but in this last post it is probably type SOLI_TAB (beacuse of used method: cl_bcs_convert=>soli_to_solix)...
Where and how are you actually getting PDF binary data? Your method convert_to_pdf is only converting unknown data: gt_alv_final_output to binary SOLIX_TAB.
08-28-2015 1:31 PM
hello Tomas,
My gt_alv_final_output contains below data.
XXX invoices are checked, thereof XXX are archived correctly. “
2 invoices are archived incorrectly:
9xxxxxxx
9xxxxxxx
PDF_content contains actual PDF binary data. I think data is converted in wrong form.
I am trying various conversion methods to convert data to SOLIX_TAB format.
08-28-2015 2:25 PM
But what is the type of gt_alv_final_output variable?
It looks like you are converting simple text to binary data... If you name that file file.pdf it will still be text and not PDF format.
08-28-2015 2:40 PM
hello Tomas,
gt_alv_final_output is of TYPE soli_tab.
How to convert it into PDF format then? I checked example BCS_EXAMPLE_6 and BCS_EXAMPLE_8, they are converting it into OTF format first and then the imported value of table and size is passed to add attachment method.
08-28-2015 2:50 PM
Yes, these are good example programs.
You can create PDF by:
a) converting spool to PDF, like in BCS_EXAMPLE_8
b) calling "Adobe print form" (form is created in transaction SFP), like in BCS_EXAMPLE_6
These are probably most used methods.
08-28-2015 3:06 PM
hello Tomas,
But in my case I cant convert spool to PDF. I just have to pass selected billing number from table in PDF file. I am not getting the proper way to convert data into PDF format.