I created this program. The email with PDF is coming in SAP Business Workplace(SAP Inbox) (Tcode-SWBP), but the pdf contains junk characters.
Can someone help. I took this program from the discussion from SAP Forum
REPORT ZTESTM1.
TYPE-POOLS:slis.
DATA: lv_buffer TYPE string,
lt_mess_att TYPETABLEOF solisti1 ,
ls_mess_att TYPE solisti1.
CONSTANTS c_container TYPEc LENGTH 30VALUE'CC'.
CONSTANTS c_col1 TYPEc LENGTH 2VALUE' ~'.
CONSTANTS c_col2 TYPEc LENGTH 2VALUE'~ '.
CONSTANTS c_255 TYPEiVALUE255.
data p_recpnt TYPE sy-uname .
p_recpnt = sy-uname.
DATA : l_ref_bcs TYPEREFTO cl_bcs,
l_ref_document TYPEREFTO cl_document_bcs,
l_ref_recipient TYPEREFTO if_recipient_bcs,
l_ref_bcs_exception TYPEREFTO cx_bcs,
lv_sent_to_all TYPE os_boolean,
lv_filesize TYPE so_obj_len,
lv_doclines TYPEi,
lv_last_line TYPEi,
lv_text TYPE so_obj_des,
lv_data TYPE bcsy_text,
lv_size TYPEi,
gt_fcat TYPE lvc_t_fcat.
TYPES: ty_t_pdf TYPESTANDARDTABLEOF tline.
DATA: lt_pdf_output TYPE ty_t_pdf,
ls_pdf_output TYPE tline.
DATA:i_t001 TYPE t001 OCCURS0,
g_spool TYPE tsp01-rqident,
g_program TYPE sy-repid VALUE sy-repid.
DATA: w_print TYPE slis_print_alv,
w_print_ctrl TYPE alv_s_pctl.
START-OF-SELECTION.
SELECT * FROM t001 INTOTABLE i_t001 UPTO100ROWS.
CALLFUNCTION'SET_PRINT_PARAMETERS'
EXPORTING
destination = 'LOCL'" Printer
layout = 'X_65_512/2'"Format
line_count = '65'"Line Count
line_size = '1024'. "Line Size
w_print-print = 'X'.
CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_program
i_structure_name = 'T001'
is_print = w_print
TABLES
t_outtab = i_t001.
IF sy-subrc <> 0.
MESSAGEID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
data: GET_SIZE_FROM_FORMAT VALUE'X'.
g_spool = sy-spono.
CALLFUNCTION'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool "Spool Number
no_dialog = space
dst_device = 'LOCL'"Printer Name
GET_SIZE_FROM_FORMAT = GET_SIZE_FROM_FORMAT
importing
pdf_bytecount = lv_size "Output Size
tables
pdf = lt_pdf_output "Spool data in PDF Format
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.
IF sy-subrc EQ0.
LOOPAT lt_pdf_output INTO ls_pdf_output.
TRANSLATE ls_pdf_output USING c_col1.
CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer.
CLEAR ls_pdf_output.
ENDLOOP.
TRANSLATE lv_buffer USING c_col2.
DO.
ls_mess_att = lv_buffer.
APPEND ls_mess_att TO lt_mess_att.
SHIFT lv_buffer LEFTBY c_255 PLACES.
IF lv_buffer ISINITIAL.
EXIT.
ENDIF.
CLEAR ls_mess_att.
ENDDO.
ENDIF.
*--create reference object
TRY.
l_ref_bcs = cl_bcs=>create_persistent( ).
lv_text = 'Mail Subject' .
APPEND'Mail Content'TO lv_data.
l_ref_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lv_data
i_subject = lv_text ).
* *--create document reference
lv_filesize = lv_size.
CALLMETHOD l_ref_document->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_size = lv_filesize
i_attachment_subject = lv_text
i_att_content_text = lt_mess_att[].
* set the document
l_ref_bcs->set_document( l_ref_document ).
* create recipient
* p_recpnt = sap INBOX user ID to WHICH the ATTACHMENT is SENT.
l_ref_recipient = cl_sapuser_bcs=>create( p_recpnt ).
*adding recipient in to section
l_ref_bcs->add_recipient( l_ref_recipient ).
* send mail
CALLMETHOD l_ref_bcs->send(
EXPORTING i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
IF lv_sent_to_all = 'X'.
ENDIF.
CATCH cx_bcs INTO l_ref_bcs_exception.
IF l_ref_bcs_exception ISNOTINITIAL.
CLEAR l_ref_bcs_exception.
ENDIF.
ENDTRY.
COMMITWORK.
endif.