Skip to Content

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

Samrtform sending to mail as pdf attachment Issue

Hi all,

Please see my code for sending mail attachment of samrtform converted to PDF format using CONVERT_OTF function module .

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

pdf_delete_otftab = ' '

IMPORTING

bin_filesize = v_binsize

  • BIN_FILE =

TABLES

otf = it_otf[]

lines = it_line[]

  • 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.

*Send converted pdf to email as attachment .

DATA :wa_buffer TYPE string, "To convert from 132 to 255

i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,

i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

v_lines_txt TYPE i,

v_lines_bin TYPE i,

wa_doc_chng TYPE sodocchgi1,

w_data TYPE sodocchgi1,

wa_objhead TYPE soli_tab,

I_objbin type table of solix with header line.

data:objbin type table of solix with header line.

REFRESH: i_reclist,

i_objtxt,

i_objbin,

i_objpack.

CLEAR wa_objhead.

i_objbin[] = objbin[].

  • Create Message Body Title and Description

i_objtxt = 'test with pdf-Attachment!'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

READ TABLE i_objtxt INDEX v_lines_txt.

wa_doc_chng-obj_name = 'smartform'.

  • wa_doc_chng-expiry_dat = sy-datum + 10.

wa_doc_chng-obj_descr = 'smartform'.

wa_doc_chng-sensitivty = 'F'.

wa_doc_chng-doc_size = v_lines_txt * 255.

  • Main Text

CLEAR i_objpack-transf_bin.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

i_objpack-body_num = v_lines_txt.

i_objpack-doc_type = 'RAW'.

APPEND i_objpack.

  • Attachment (pdf-Attachment)

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

DESCRIBE TABLE i_objbin LINES v_lines_bin.

READ TABLE i_objbin INDEX v_lines_bin.

i_objpack-doc_size = v_lines_bin * 255 .

i_objpack-body_num = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'smart'.

i_objpack-obj_descr = 'test'.

APPEND i_objpack.

CLEAR i_reclist.

i_reclist-receiver = 'shishupal.reddy@gmail.com'.

i_reclist-rec_type = 'U'.

APPEND i_reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = i_objpack

object_header = wa_objhead

  • contents_bin = i_objbin

contents_txt = i_objtxt

contents_hex = i_objbin

receivers = i_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.

WRITE:/ 'Error When Sending the File', sy-subrc.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

<b>I am getting sy-subrc = 3 and document could nto be send .</b>

Please provide me the correct place where iam commiting mistake in the above code .

Regards,

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