Application Development 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: 

SO_NEW_DOCUMENT_ATT_SEND_API1 pdf attachment sending thru mail ecc 6.0

Former Member
0 Kudos

Hi All,

I'm using ECC 6.0 version, I'm trying to attach a pdf file to a mail using the function module SO_NEW_DOCUMENT_ATT_SEND_API1. But gtting error as "wasn't decoded correctly", but the same coding is working fine in 4.6 version. What changes i should do while using this function module in ECC 6.0 to get it corrected.

Thanks & Regards,

Sabu.

14 REPLIES 14

Former Member
0 Kudos

Hi,

Refer below link.

Regards

Md.MahaboobKhan

Former Member
0 Kudos

Hi,

Are you getting the error when trying to open the attachment ?

Have you passed

OBJPACK-DOC_TYPE   = 'PDF'

for your attachment ?

Please paste your code..

Regards

0 Kudos

Hi

Thanks for your reply.

Yes, I'm getting error while trying to open attachment, the above suggestion that i've already done, still getting error " wasn't decoded correctly" or " File is damaged could not be repaired" . But I'm able to open this file in 4.6 version .

Thanks & Regards,

Sabu.

0 Kudos

Hi Sabu,

Go to TCODE SBWP in your new system and click on new message. Try attaching a PDF file here and send the same to your id.

Check if PDF is sent correctly. This is just to check if your code requires some changes or any settings are to be made at system level.

Also can you paste your code here.

Regards

0 Kudos

Hi ,

I tried with SBWP, I'm able to see the pdf file attached while sending from SBWP.

Please see the below coding

----


  • FORM make_the_message *

----


FORM make_the_message.

  • Create Message Body

  • Title and Description

CLEAR : docdata,

objtxt[],

objpack[],

objbin[].

docdata-obj_name = sy-repid.

docdata-obj_descr = p_subj.

  • Main Text

LOOP AT gt_text INTO objtxt.

APPEND objtxt.

ENDLOOP.

  • Write Packing List (Main)

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

    • Sabu

objpack-doc_type = 'RAW'.

  • objpack-doc_type = 'PDF'.

        • End Sabu

APPEND objpack.

*Start of Upgrade ECC 6.0

Data: l_mi_bytecount TYPE i.

*End of Upgrade ECC 6.0

  • Create Message Attachment (As read earlier from frontend)

  • Write Packing List (Attachment)

  • Handle the attached file.

objbin[] = gt_pdffile[].

att_type = 'PDF'.

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

*****Sabu 8496

  • objpack-head_num = 0.

objpack-head_num = 1.

        • End Sabu

objpack-body_start = 1.

objpack-body_num = tab_lines.

*Start of Upgrade ECC 6.0

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT.pdf'.

objpack-obj_descr = 'Attached Document'.

*End of Upgrade ECC 6.0

APPEND objpack.

  • Create receiver list

  • Generate ALV list for either Customers/Vendors/Contact persons etc.

ENDFORM. "make_the_message

----


  • FORM fill_the_distribution_list *

----


FORM fill_the_distribution_list USING i_test

i_fax

i_faxcntry

i_email.

  • Just as a test...

CLEAR: reclist, reclist[].

IF i_test EQ 'X'.

CASE 'X'.

WHEN p_sndfax.

  • By Fax

rec_fax-rec_fax = i_fax.

rec_fax-rec_state = i_faxcntry.

  • Start of Changes 07/09/2008

  • reclist-receiver = rec_fax.

ASSIGN reclist-receiver TO <fs_reclist> CASTING.

<fs_reclist> = rec_fax.

  • rec_fax = <fs_reclist>.

  • End of Changes 07/09/2008

reclist-rec_type = 'F'.

APPEND reclist.

WHEN p_sndint.

  • By Email

reclist-receiver = i_email.

reclist-rec_type = 'U'.

reclist-BLIND_COPY = 'X'.

APPEND reclist.

ENDCASE.

ELSE.

  • This is not a test....

LOOP AT gt_detail INTO gs_detail.

CHECK gs_detail-flag EQ icon_green_light.

CASE 'X'.

WHEN p_sndfax.

  • By Fax

rec_fax-rec_fax = gs_detail-faxnr.

rec_fax-rec_state = gs_detail-land1.

  • Start of Changes 07/09/2008

ASSIGN reclist-receiver TO <fs_reclist> CASTING.

<fs_reclist> = rec_fax.

rec_fax = <fs_reclist>.

  • reclist-receiver = rec_fax

  • End of Changes 07/09/2008

reclist-rec_type = 'F'.

APPEND reclist.

WHEN p_sndint.

  • By Email

reclist-receiver = gs_detail-email.

reclist-rec_type = 'U'.

reclist-BLIND_COPY = 'X'.

APPEND reclist.

ENDCASE.

ENDLOOP.

ENDIF.

ENDFORM. "fill_the_distribution_list

----


  • FORM send_the_messages *

----


FORM send_the_messages.

  • Send Message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID 'SO'

TYPE 'S'

NUMBER '023'

WITH docdata-obj_name.

ELSE.

PERFORM popup.

ENDIF.

ENDFORM. "send_the_messages

Thanks & Regards,

Sabu

Former Member
0 Kudos

Dear ,

Please check the below blog.

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

You need to use class objects while converting the data format.

Thanks and Regards,

Former Member
0 Kudos

Hi All ,

thanks for your reply, as per notes 190669 and 843133 i used the fun mod SO_DOCUMENT_SEND_API1 insted of SO_NEW_DOCUMENT_ATT_SEND_API1 and changed the program accordingly , issue resolved.

Thanks ,

Sabu

0 Kudos

hello sabu sebastian,

I am using FM: SO_NEW_DOCUMENT_ATT_SEND_API1 for sending PDF file but getting same error ' file broken ' unable to open PDF file. could you please helpme out.

0 Kudos

Hi,

Please go thru the above notes and try to use the function module SO_DOCUMENT_SEND_API1 insted of SO_NEW_DOCUMENT_ATT_SEND_API1. Chnage the program accordingly means no need to calculate the size.

Thanks & Regrads,

Sabu.

0 Kudos

hello Sabu Sebastian ,

Could you please provide me one test program for send RAW and PDF file using FM: SO_DOCUMENT_SEND_API1 , becuase still iam getting same error ( sy-subrc = 6. internal error ) .

regards

srinivas

0 Kudos

Hello sabu,

I am still facing the problem even after using the SO_DOCUMENT_SEND_API1 FM also.

Could you please paste the logic here.

Thanks.

0 Kudos

paste this code b 4 calling the FM so_document sendapi

as per your defined value.

DESCRIBE TABLE i_objbin LINES bin_filesize.

CLEAR i_objpack.

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 1.

i_objpack-body_start = 1.

i_objpack-body_num = bin_filesize.

i_objpack-obj_name = 'Employee Payslip'.

i_objpack-obj_descr = 'Employee Payslip'.

i_objpack-doc_size = bin_filesize * 255 .

i_objpack-doc_type = 'PDF'.

APPEND i_objpack.

0 Kudos

... or use the alternative ([Sending an Email along with PDF as an attachment|http://wiki.sdn.sap.com/wiki/display/Snippets/Sending+attachmentusingcl_bcsclasses]), adapt to your needs.

method ONACTIONSUBMIT .
TYPE-POOLS: ixml.
DATA: w_pdf_source TYPE xstring,
w_dob TYPE char10.
 
* Get a reference to the form Processing class
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_pdf_source LIKE ls_context-pdf_source.
 
DATA t_att_content_hex type SOLIX_TAB.
 
DATA lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
DATA: lt_message_body TYPE bcsy_text VALUE IS INITIAL,
lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
 
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
 
* get element via lead selection
lo_el_context = wd_context->get_element(  ).
 
* get single attribute
lo_el_context->get_attribute(
EXPORTING
name =  `PDF_SOURCE`
IMPORTING
value = lv_pdf_source ).
 
 
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER                = lv_pdf_source
TABLES
BINARY_TAB            = t_att_content_hex .
 
 
CLASS cl_bcs DEFINITION LOAD.
 
lo_send_request = cl_bcs=>create_persistent( ).
 
* Message body and subject
 
APPEND 'Dear,' TO lt_message_body.
append ' ' to lt_message_body.
APPEND 'Please find the attached form.'
TO lt_message_body.
APPEND ' ' 
TO lt_message_body.
APPEND 'Thank You,' 
TO lt_message_body.  
 
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body
i_subject = 'Mail Attachment Sample Example' 
).
 
 
TRY.
 
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = 'Example Application for mail attachment'
i_att_content_hex = t_att_content_hex ).
 
CATCH cx_document_bcs INTO lx_document_bcs.
 
ENDTRY.
 
* Add attachment
* Pass the document to send request
lo_send_request->set_document( lo_document ).
 
* Create sender
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
 
* Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
 
* Create recipient
DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
 
* Set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X'           ).
 
 
* Send email
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
 
COMMIT WORK.
endmethod.

Regards

Clemens

0 Kudos

Thank you for the code Clemens, I used it for my reference.

Helped me.