Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SO_NEW_DOCUMENT_ATT_SEND_API1

Hello all,

I have used SO_NEW_DOCUMENT_ATT_SEND_API1 to send a PDF attachment.

It is sent successfully but when i try to open the PDF attachment, it says 'There is an error opening the attachment. The file may be damaged and could not be repaired'.

The attachment is basically output of a Smartform.

Can you please let me know where the error can be ? I am also sending the code.

  • Covert smartform to PDF format

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 255

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

  • PDF_DELETE_OTFTAB = ' '

IMPORTING

bin_filesize = lf_wrk_size

  • BIN_FILE =

TABLES

otf = gs_sform_out-otfdata

lines = gt_lines

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

OTHERS = 5

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = gt_lines

t_target_tab = gt_objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Get receiver list

  • SHIFT vbdka-adrnr LEFT DELETING LEADING '0'.

IF NOT vbdka-adrnr IS INITIAL.

SELECT SINGLE smtp_addr

FROM adr6

INTO gs_reclist-receiver

WHERE addrnumber = vbdka-adrnr.

ENDIF.

gs_reclist-com_type = 'INT'.

gs_reclist-rec_type = 'U'.

APPEND gs_reclist TO gt_reclist.

  • Details needed for email function

  • build body text

CLEAR gs_objtxt.

gs_objtxt = 'Sir/Madam,'.

APPEND gs_objtxt TO gt_objtxt.

CLEAR gs_objtxt.

gs_objtxt = ''.

APPEND gs_objtxt TO gt_objtxt.

CLEAR gs_objtxt.

CONCATENATE text-t01 text-t02 vbdka-vbeln INTO gs_objtxt.

APPEND gs_objtxt TO gt_objtxt.

CLEAR gs_objtxt.

gs_objtxt = ''.

APPEND gs_objtxt TO gt_objtxt.

CLEAR gs_objtxt.

gs_objtxt = 'Thanks & Regards'.

APPEND gs_objtxt TO gt_objtxt.

CLEAR gs_objtxt.

gs_objtxt = ''.

APPEND gs_objtxt TO gt_objtxt.

  • Build subject line

gs_docu_data-obj_name = 'Output'.

gs_docu_data-obj_descr = 'Customer Order acknowledgement'.

DESCRIBE TABLE gt_objbin LINES lf_lines.

gs_docu_data-doc_size = ( lf_lines - 1 ) * 255 + STRLEN( gs_objtxt ).

  • Build control information

CLEAR gs_packing_list.

CLEAR gs_packing_list-transf_bin.

gs_packing_list-head_start = 1.

gs_packing_list-head_num = 0.

gs_packing_list-body_start = 1.

gs_packing_list-body_num = lf_lines.

gs_packing_list-doc_type = 'RAW'.

APPEND gs_packing_list TO gt_packing_list.

CLEAR gs_packing_list.

gs_packing_list-transf_bin = 'X'.

gs_packing_list-head_start = 1.

gs_packing_list-head_num = 1.

gs_packing_list-body_start = 1.

  • DESCRIBE TABLE gt_objtxt LINES lf_lines.

DESCRIBE TABLE gt_objbin LINES lf_lines.

gs_packing_list-body_num = lf_lines.

gs_packing_list-doc_type = 'PDF'.

gs_packing_list-obj_name = 'Order'.

gs_packing_list-obj_descr = 'Customer Order'.

gs_packing_list-doc_size = lf_lines * 255.

gs_packing_list-doc_size = gs_packing_list-doc_size + 100.

APPEND gs_packing_list TO gt_packing_list.

gs_objhead = 'Customer order.PDF'.

APPEND gs_objhead TO gt_objhead.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gs_docu_data

put_in_outbox = ' '

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = gt_packing_list

object_header = gt_objhead

contents_bin = gt_objbin

contents_txt = gt_objtxt

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = gt_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 SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question