Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8808

Re: Sending Records as Attachment in email but Excel is loading in one Column

$
0
0

Hi Giri & Naheet,

 

Thanks for your quick Reply!

 

Kindly find teh below code :

 

 


* Declaration of Tab


Data :

      wa_message TYPE solisti1,        "Workarea for Mail Message
      wa_attach TYPE solisti1,         "Workarea for Mail Attach
      wa_packing_list TYPE sopcklsti1, "Workarea for Mail packing
      wa_contents TYPE solisti1,       "Workarea for Mail Contents
      wa_receivers TYPE somlreci1,     "Workarea for Mail Receivers
      wa_attachment TYPE solisti1,     "Workarea for Mail Attachment
      wa_object_header TYPE solisti1,  "Workarea for Mail Header
      c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

 

***Inserting the data into a table

 

LOOP AT gt_output_value.
*update ZTI_TRANS_LOG table
        IF gt_output_value-bukrs NE space AND gt_output_value-saknr NE space.
          CLEAR: wa_zti_trans_log, w_status, w_msgtyp.
          w_status = 'Success'.
          w_msgtyp = 'S'.
          PERFORM error_handling USING gt_output_value-bukrs
                                       gt_output_value-saknr.
        ENDIF.
        w_skbez = gt_output_value-skbez.
        w_salvm = gt_output_value-salvm.
        w_solbm = gt_output_value-solbm.
        w_habbm   = gt_output_value-habbm.
        w_salhb   = gt_output_value-salhb.

        CONCATENATE gt_output_value-bukrs
                    gt_output_value-saknr
                    w_skbez
                    w_salvm
                    w_solbm
                    w_habbm
                    w_salhb
                   INTO wa_attach SEPARATED BY c_tab.
*                    INTO wa_attach SEPARATED BY gc_comma.
        APPEND wa_attach TO t_attach.
        CLEAR wa_attach.
      ENDLOOP.
        PERFORM send_mail TABLES t_attach USING text-001 .
    ENDIF.

 

Subroutine :

FORM send_mail TABLES it_attach STRUCTURE wa_attach
                     USING  p_desc.
  DATA: p_desc1(100) TYPE c,
        w_seq(10),
        w_format TYPE  so_obj_tp  VALUE 'XLS',
        w_attdescription TYPE  so_obj_nam,
        w_attfilename    TYPE  so_obj_des VALUE 'filename',
        w_sender_address TYPE  soextreci1-receiver,
        w_sender_address_type TYPE  soextreci1-adr_typ,
        w_firstname TYPE adrp-name_first,
        w_lastname  TYPE adrp-name_last,
        w_name(75).

DESCRIBE TABLE T_attach lines gw_count.
      CONDENSE gw_count.
  REFRESH t_message.

*  w_attdescription      = space.
   w_attdescription      = 'Account TB'.
  w_sender_address      = space.
  w_sender_address_type = space.
***Get the First name and last name based on Personal  number
  SELECT b~name_first
         b~name_last
    INTO (w_firstname, w_lastname)
    FROM usr21 AS a INNER JOIN adrp AS b
    ON a~persnumber = b~persnumber
    WHERE a~bname = sy-uname.
  ENDSELECT.
***Fill the body of the Mail
  CLEAR wa_message.
  wa_message-line = text-227.
  APPEND wa_message TO t_message.
  CLEAR wa_message.

 

* Fill the document data.
  w_doc_data-doc_size = 1.

* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE t_attach INTO wa_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + strlen( wa_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = c_obj_name.

  CONCATENATE p_desc sy-sysid INTO p_desc1 SEPARATED BY space.
  w_doc_data-obj_descr  = p_desc1.
  w_doc_data-sensitivty = c_sensitivty.

  REFRESH t_attachment.
  t_attachment[] = t_attach[].


* Add the recipients email address from ZTEMAIL
  CLEAR wa_receivers.
  REFRESH t_receivers.
  SELECT * FROM ZTEMAIL
           INTO TABLE t_ztbidl
           WHERE intid =  gc_interfaceID "
           AND  obj_name = gc_Objname.   "

IF sy-subrc = 0.
    LOOP AT t_ztbidl INTO w_ztbidl.
      wa_receivers-receiver = w_ztbidl-email.
      wa_receivers-rec_type = c_rec_type.
      wa_receivers-com_type = c_com_type.
      wa_receivers-notif_del = c_x.
      wa_receivers-notif_ndel = c_x.
      APPEND wa_receivers TO t_receivers.
      CLEAR wa_receivers.
    ENDLOOP.
  ENDIF.
****Call FM to send  mail
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
      EXPORTING
        document_data              = w_doc_data
        put_in_outbox              = c_x
        sender_address             = w_sender_address
        sender_address_type        = w_sender_address_type
        commit_work                = c_x
      IMPORTING
        sent_to_all                = w_sent_all
      TABLES
        packing_list               = t_packing_list
        contents_bin               = t_attachment
        contents_txt               = t_message
        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.

ENDFORM.                    "send_mail

 

 

 

 

 

Best Regards,

KC

 

 



Viewing all articles
Browse latest Browse all 8808

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>