Skip to Content
0
Former Member
Nov 29, 2005 at 07:52 PM

Sending email attachment as pdf file.

253 Views

Hi,

I changed 'SO_DOCUMENT_SEND_API1' to 'SO_NEW_DOCUMENT_ATT_SEND_API1'. With 'SO_DOCUMENT_SEND_API1' it was sending email with XLS attachment. Now after changing the function it is not sending email. Before I wrote the code for XLS file, now I want to change it to PDF file. Where should I change it. Any suggestions on how to do it. please look at my code.

Thanks

Veni.

 

FORM EMAIL_DATA.

  • Populate details for .xls file

PERFORM build_xls_data_table.

  • Populate message body

PERFORM populate_email_message_body.

  • Send file by email as .xls speadsheet

PERFORM send_file_as_email_attachment

TABLES i_message

i_attach

USING p_email

'Commercial Invoice'

'XLS'

'COMMERCIAL_INVOICE'

' '

' '

' '

CHANGING g_error

g_reciever.

  • Instructs mail send program for SAPCONNECT to send email(rsconn01)

PERFORM initiate_mail_execute_program.

ENDFORM. " EMAIL_DATA

&----


*& Form build_xls_data_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_xls_data_table .

  • CONSTANTS:

  • con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

  • con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

i_attach-line = 'AMERICA, INC.'.

APPEND i_attach.

i_attach-line = 'Commercial Invoice Details., INC.'.

APPEND i_attach.

i_attach-line = 'Details of Commercial Invoice:'.

APPEND i_attach.

LOOP AT FTAB.

i_attach-line = FTAB-VBELN.

APPEND i_attach.

CONCATENATE 'MATERIAL' 'NET PRICE' INTO i_attach

SEPARATED BY space.

  • CONCATENATE con_cret i_attach INTO i_attach.

APPEND i_attach.

LOOP AT ITAB_VBRP INTO wa_data.

CONCATENATE wa_data-MATNR

wa_data-NETWR INTO i_attach

SEPARATED BY space. "con_tab.

  • CONCATENATE con_cret i_attach INTO i_attach.

APPEND i_attach.

ENDLOOP.

ENDLOOP.

ENDFORM. " build_xls_data_table

&----


*& Form populate_email_message_body

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM populate_email_message_body .

DATA: l_buffer(250).

REFRESH i_message.

l_buffer = 'COMMERCIAL INVOICE DATA DOWNLOAD. '.

SKIP 2.

CONCATENATE l_buffer 'You will find an attachment in this message.'

INTO l_buffer.

i_message = l_buffer.

APPEND i_message.

ENDFORM. " populate_email_message_body

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


FORM send_file_as_email_attachment TABLES p_i_message

p_i_attach

USING p_email1

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

CHANGING p_error

p_receiver.

DATA: l_error TYPE sy-subrc,

l_receiver TYPE sy-subrc,

l_email LIKE somlreci1-receiver,

l_mtitle LIKE sodocchgi1-obj_descr,

l_format TYPE so_obj_tp,

l_attfilename TYPE so_obj_des ,

l_attdescription TYPE so_obj_nam ,

l_sender_address LIKE soextreci1-receiver,

l_sender_address_type LIKE soextreci1-adr_typ.

l_email = p_email1.

l_mtitle = p_mtitle.

l_format = p_format.

l_attfilename = p_filename.

l_attdescription = p_attdescription.

l_sender_address = p_sender_address.

l_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = l_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE i_attach INDEX w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + STRLEN( i_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = l_mtitle.

w_doc_data-sensitivty = 'F'.

CLEAR i_attachment.

REFRESH i_attachment.

i_attachment[] = p_i_attach[].

  • Describe the body of the message

CLEAR i_packing_list.

REFRESH i_packing_list.

i_packing_list-transf_bin = space.

i_packing_list-head_start = 1.

i_packing_list-head_num = 0.

i_packing_list-body_start = 1.

DESCRIBE TABLE i_message LINES i_packing_list-body_num.

i_packing_list-doc_type = 'RAW'.

APPEND i_packing_list.

  • Create attachment notification

i_packing_list-transf_bin = 'X'.

i_packing_list-head_start = 1.

i_packing_list-head_num = 1.

i_packing_list-body_start = 1.

DESCRIBE TABLE i_attachment LINES i_packing_list-body_num.

i_packing_list-doc_type = l_format.

i_packing_list-obj_descr = l_attdescription.

i_packing_list-obj_name = l_attfilename.

i_packing_list-doc_size = i_packing_list-body_num * 255.

APPEND i_packing_list.

  • Add the recipients email address

CLEAR i_receivers.

REFRESH i_receivers.

i_receivers-receiver = l_email.

i_receivers-rec_type = 'U'.

i_receivers-com_type = 'INT'.

i_receivers-notif_del = 'X'.

i_receivers-notif_ndel = 'X'.

APPEND i_receivers.

  • i_receivers-receiver = l_email.

  • i_receivers-rec_type = 'B'.

  • i_receivers-com_type = ''.

  • i_receivers-notif_del = 'X'.

  • i_receivers-notif_ndel = 'X'.

  • APPEND i_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = w_doc_data

PUT_IN_OUTBOX = 'X'

  • IMPORTING

SENT_TO_ALL = w_sent_all

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = i_packing_list

  • OBJECT_HEADER =

CONTENTS_BIN = i_attachment

CONTENTS_TXT = i_message

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = i_receivers

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.

  • CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

  • EXPORTING

  • document_data = w_doc_data

  • put_in_outbox = 'X'

  • sender_address = l_sender_address

  • sender_address_type = l_sender_address_type

  • commit_work = 'X'

  • IMPORTING

  • sent_to_all = w_sent_all

  • TABLES

  • packing_list = i_packing_list

  • contents_bin = i_attachment

  • contents_txt = i_message

  • receivers = i_receivers

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

  • Populate zerror return code

l_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT i_receivers.

l_receiver = i_receivers-retrn_code.

ENDLOOP.

ENDFORM. "send_file_as_email_attachment

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


FORM initiate_mail_execute_program.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = ''

AND RETURN.

ENDFORM. "