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.