10-08-2008 11:29 AM
Hello,
I don't know how to pass the PDF to binary, in order to be able to pass the parameter to the method add_attachment.
Exist any FM? How to make compatible this new binary file with the parameter of the method?
document->add_attachment(
i_attachment_type = 'PDF'
i_attachment_subject = 'attachment'
i_att_content_hex = ???? ).
Thank you,
Manel
10-21-2008 9:38 AM
Follow FORM prepare_attachment
ENDFORM.
You will get your answer. revert back if still doubt
10-08-2008 11:44 AM
10-08-2008 12:16 PM
I already had read the forum but it is not helpfull.
I dont know how to converto to bin the pdf before to use add_attachment method.
10-08-2008 2:38 PM
10-08-2008 2:55 PM
Hi,
You can also use the Function Module 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
Best Regards,
10-08-2008 3:03 PM
No, i cant use this FM because i need a subject bigger than 50.
I will try passing the OTF to PDF directly with the FM CONVERT_OTF_2_PDF instead to covert to binary the PDF that i already have.
Thanks all
10-08-2008 1:24 PM
Hi,
Use this code.
DATA: wa_buffer TYPE string.
To pass PDF data as Bin data to email function module
LOOP AT lt_lines INTO wa_lines.
TRANSLATE wa_lines USING '~'.
CONCATENATE wa_buffer wa_lines INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
i_record = wa_buffer.
APPEND i_record.
SHIFT wa_buffer LEFT BY 255 PLACES.
IF wa_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
10-21-2008 9:34 AM
Hi,
Follow example here.
DATA: l_doland1 TYPE char255,
l_doland2 TYPE char255.
Preparing body of the Mail
MOVE 'Please Find the Attached Packlist' TO l_text.
APPEND l_text TO i_content.
Preparing contents of attachment with Change Log
PERFORM prepare_attachment.
Creates persistent send request
TRY.
l_send_request = cl_bcs=>create_persistent( ).
Creating Mail Subject
CONCATENATE '(' 'DO#' vbpla-vbeln INTO l_doland1.
CONCATENATE vbpla-land1 ')' '-' 'Packlist' INTO l_doland2.
CONCATENATE 'PreAlert from ATSG' l_doland1 'TO' l_doland2
INTO l_subject separated by space.
MOVE l_subject TO i_subjec.
Creating Document
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = i_subjec ).
Size of PDF Document
l_size = l_byte_count.
Adding Attachment
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = c_ext
i_attachment_size = l_size
i_attachment_subject = 'Packing List'
i_att_content_hex = i_attachx[].
Add document to send request
CALL METHOD l_send_request->set_document( l_document ).
Get Sender Object
l_uname = sy-uname.
l_sender = cl_sapuser_bcs=>create( l_uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
SELECT * FROM zsdshpalertlist INTO TABLE email_list
WHERE kunnr = vbpla-kunwe.
LOOP AT email_list.
CHECK NOT email_list-email IS INITIAL.
ld_email = email_list-email.
l_recipient = cl_cam_address_bcs=>create_internet_address( ld_email ).
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'U'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
ENDLOOP.
*Trigger E-Mail immediately
l_send_request->set_send_immediately( 'X' ).
CALL METHOD l_send_request->send( ).
COMMIT WORK.
CATCH cx_document_bcs INTO l_bcs_exception.
CATCH cx_send_req_bcs INTO l_send_exception.
CATCH cx_address_bcs INTO l_addr_exception.
ENDTRY.
**********************************************
FORM prepare_attachment .
DATA: wa_pdf TYPE tline,
wa_attachx TYPE solix,
l_pdf_len TYPE i,
l_con_len TYPE i,
l_pdf_pos TYPE i,
l_con_pos TYPE i,
l_spool_size TYPE sood-objlen.
FIELD-SYMBOLS: <fs_con> TYPE x.
l_con_pos = 0.
DESCRIBE FIELD wa_pdf LENGTH l_pdf_len IN BYTE MODE.
DESCRIBE FIELD wa_attachx LENGTH l_con_len IN BYTE MODE.
LOOP AT i_pdf INTO wa_pdf.
ASSIGN wa_pdf TO <fs_con> CASTING.
CHECK sy-subrc EQ 0.
DO l_pdf_len TIMES.
l_pdf_pos = sy-index - 1.
IF l_con_pos = l_con_len.
APPEND wa_attachx TO i_attachx.
FREE wa_attachx.
l_con_pos = 0.
ENDIF.
MOVE <fs_con>l_pdf_pos(1) TO wa_attachx-linel_con_pos(1).
ADD 1 TO l_con_pos.
ENDDO.
ENDLOOP.
IF l_con_pos > 0.
APPEND wa_attachx TO i_attachx.
ENDIF.
ENDFORM.
10-21-2008 9:38 AM
Follow FORM prepare_attachment
ENDFORM.
You will get your answer. revert back if still doubt