Application Development and Automation 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: 
Read only

attach file

Former Member
0 Likes
888

hi i need to attach a file in a mail . i am able to send the mail with attachment but the attachment is empty. how should i attach a file i have a file name called c:/test.xsl. how can i attach dis file .

7 REPLIES 7
Read only

Former Member
0 Likes
834

Hi Kaushik,

Try 'SO_NEW_DOCUMENT_ATT_SEND_API1' function module..

Regards,

Santanu Mohapatra

Read only

0 Likes
834

i have tried all function module . can u tell me how do we attach the local file from c drive. is it possible

Read only

0 Likes
834

Hi Santanu,

               i have done that using customized fm. Now actually when i am opening the file last three columns are not displaying.. i have concatenated all the value in internal table.

Read only

Former Member
0 Likes
834

Hello.

I think that frist u need to upload the field from PC to SAP and then send it by email using SO_NEW_DOCUMENT_ATT_SEND_API1. Search about upload field.

Regards

Read only

FredericGirod
Active Contributor
0 Likes
834

Hi,

here a part of coding using the Oo to send mail

it_soli           TYPE soli_tab ,

          obj_mime_helper   TYPE REF TO cl_gbt_multirelated_service ,

          obj_bcs           TYPE REF TO cl_bcs ,

          obj_doc_bcs       TYPE REF TO cl_document_bcs ,

          obj_recipient     TYPE REF TO if_recipient_bcs ,

          obj_sender        TYPE REF TO if_sender_bcs .

 

* Creation objet pour mail.

    CREATE OBJECT obj_mime_helper.

 

* Création du mail

    TRY.

     obj_bcs = cl_bcs=>create_persistent( ).

   ENDTRY.

* HERE THE BODY OF THE MAIL IS IN THE VARIABLE W_HTML_TXT
* I PUT IT IN THE IT_SOLI TABLE

* Commence le mail.
* Converti en ligne.

   IF w_flag_fax IS INITIAL.
     w_offset = 0.
     w_len    = 255.
     WHILE w_offset < w_html_len.
       w_diff = w_html_len - w_offset.
       IF w_diff > w_len.
         is_soli-line = w_html_txt+w_offset(w_len).
       ELSE.
         is_soli-line = w_html_txt+w_offset(w_diff).
       ENDIF.
       APPEND is_soli TO it_soli.
       ADD w_len TO w_offset.
     ENDWHILE.
   ENDIF.

* Ajoute le corps.

    CALL METHOD obj_mime_helper->set_main_html

     EXPORTING

       content     = it_soli

       filename    = ''

       description = 'Bulletin d''analyse'.

  TRY.

     obj_doc_bcs = cl_document_bcs=>create_from_multirelated(

                     i_subject          = w_title

                     i_importance       = '9'                " 1 / 5 / 9

                     i_multirel_service = obj_mime_helper ).

   ENDTRY.

* HERE IS YOUR FILE ATTACHMENT 

     CALL METHOD obj_doc->add_attachment

       EXPORTING

         i_attachment_type    = is_doc_data-obj_type

         i_attachment_subject = w_file

         i_attachment_size    = w_obj_len

         i_att_content_hex    = it_contentx.


TRY.

       obj_recipient = cl_cam_address_bcs=>create_internet_address(

                         i_address_string = w_smtp ).

     ENDTRY.

     TRY.

       obj_bcs->add_recipient(

                  i_recipient = obj_recipient ).

     ENDTRY.

  TRY.

     obj_bcs->send( ).

   ENDTRY.

Fred

Read only

0 Likes
834

Hi Fred,

            But there is no class available in 4.6c. i have done that but when i am opening the attachment last three columns are missing. Do u ve ne idea bout that.

Read only

0 Likes
834

Hi Kaushik,

While concate the internal table data into the internal table that contains data while send.

  it_attachment   LIKE solisti1 OCCURS 0 WITH HEADER LINE,                

  gd_doc_data     LIKE sodocchgi1,

While concate use :

   LOOP AT itab_final1 INTO wa_final1.

CONCATENATE wa_final1-ebeln wa_final1-aedat wa_final1-txz01   INTO it_attachment SEPARATED BY
             cl_abap_char_utilities=>horizontal_tab." SEPARATED BY L_TAB.
CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO it_attachment.
APPEND it_attachment. CLEAR it_attachment.
ENDLOOP.

In the end before code to send mail .... use this code :

   **File Type
  ld_format = 'xls'. "XLS
**File Name
  ld_attfilename = 'test'.
* Fill the document data.
  gd_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject .
  gd_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
  CLEAR gd_doc_data.
* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  READ TABLE it_attachment INDEX w_cnt.
  gd_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_attachment ).
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.
* Describe the body of the message
  CLEAR it_packing_list.
  REFRESH it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  APPEND it_packing_list.
**Describe the attachment info
  it_packing_list-transf_bin = 'X'.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 1.
  it_packing_list-body_start = 1.
  DESCRIBE TABLE it_attachment LINES  it_packing_list-body_num.
  it_packing_list-doc_type = ld_format.
  it_packing_list-obj_name = ld_attfilename.
  it_packing_list-obj_descr = ld_attfilename.
  it_packing_list-doc_size = it_packing_list-body_num * 255.
  APPEND it_packing_list.

and then send mail.

Hope this works  else share your code for further help.

Regards,

RAvi Singh