Skip to Content

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

MAiling Urgent

Hi all,

I want to send a gif image with the document.Can anyone help me in this.Uding GUI_upload i get the gif image in the binary form .Now i want this to be attached with my document.

the code for my program is

FORM send_file_as_email_attachment TABLES pit_message

pit_attach

USING p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

CHANGING p_error

p_reciever.

CONSTANTS:

con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam ,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

ld_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc,

w_doc_data LIKE sodocchgi1.

      • Added By AHasan on 4/4/2006 Start

DATA: send_request TYPE REF TO cl_bcs.

DATA: text TYPE bcsy_text.

data: binary_content type solix_tab.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

DATA: bcs_exception type ref to cx_bcs.

data: sent_to_all type os_boolean.

      • Added By AHasan on 4/4/2006 End

DATA v_sent TYPE sonv-flag.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_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 = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

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

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'P'.

CLEAR it_message.

REFRESH it_message.

it_message[] = pit_attach[].

  • Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

CLEAR t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'ATTA'.

APPEND t_packing_list.

  • Create attachment notification

REFRESH it_message.

it_message[] = it_html[].

t_packing_list-transf_bin = ' '.

t_packing_list-head_start = 1.

t_packing_list-head_num = 4.

t_packing_list-body_start = 1.

CLEAR v_num.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

v_num = t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = 'TCS Scenario'.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Second attachment

REFRESH it_message1.

CONCATENATE 'Product'

'Description'

'Plant'

'SNP Planner'

'Product Class'

'Mode'

'Curr. TCS Value'

'Proposed TCS Value'

'New TCS Value'

INTO it_message1-line SEPARATED BY con_tab.

APPEND it_message1.

LOOP AT t_scr_upload INTO s_scr_upload.

v_cat102 = s_scr_upload-cat102.

v_pat102 = s_scr_upload-pat102.

v_nat102 = s_scr_upload-nat102.

CONCATENATE s_scr_upload-matnr

s_scr_upload-maktx

s_scr_upload-locno

s_scr_upload-planner_snp

s_scr_upload-at103

s_scr_upload-dmode

v_cat102

v_pat102

v_nat102

INTO it_message1-line SEPARATED BY con_tab.

APPEND it_message1.

ENDLOOP.

APPEND LINES OF it_message1 TO it_message.

v_num = v_num + 1.

t_packing_list-transf_bin = ' '.

t_packing_list-head_start = 1.

t_packing_list-head_num = 4.

t_packing_list-body_start = v_num.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'XLS'.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = 'TCS UPload'.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

***Added By Ahasan On 4/4/2006 start

***Getting the Gif image

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\TCS04_04_2006\S_COMPLE.gif'

FILETYPE = 'BIN'

TABLES

data_tab = binary_content

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

  • ***Added By Ahasan On 4/4/2006 start

t_packing_list-doc_type = 'GIF'.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = 'TCS UPload'.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

SELECT SINGLE email FROM zdrp_tcsmail INTO v_email WHERE vkorg = p_vkorg.

SPLIT v_email AT ',' INTO TABLE itab_temp_email.

LOOP AT itab_temp_email.

t_receivers-receiver = itab_temp_email-emailid.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = v_sent

  • NEW_OBJECT_ID =

TABLES

packing_list = t_packing_list

  • OBJECT_HEADER =

  • CONTENTS_BIN =

contents_txt = it_message

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

  • Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

ENDFORM. "send_file_as_email_attachment

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