Application Development 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: 

Simple code to send ALV display as XLS attachment to SAP inbox

Former Member
0 Kudos
47

Hi All,

Simple code to send ALV display as XLS attachment to SAP inbox.

Also i need to send only 200 records per attachement. So in this case i need send multiple attachment per mail

Thanks,

Lokesh

2 REPLIES 2

former_member184119
Active Contributor
0 Kudos
13

THis is bad....You could have pickup the data before it display in ALV......

For sending to SAP-Inbox you can check bcs* examples....

Sas

Former Member
0 Kudos
13

The following code is used to send the internal table which u pass fo the ALV display to be send as excel sheet attachment

Internal table is it_attach[]



 ld_email               = po_email.
  ld_mtitle              = 'Email From Z377_EMAIL_XLS'.
  ld_format              = 'XLS'.
  ld_attdescription      = 'filename'.
  ld_attfilename         = 'Allot'.
  ld_sender_address      = ' '.
  ld_sender_address_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 = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_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 = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE li_content LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.

* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.

  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  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.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
  EXPORTING
  document_data              = w_doc_data
  put_in_outbox              = 'X'
  sender_address             = ld_sender_address
  sender_address_type        = ld_sender_address_type
  commit_work                = 'X'
*IMPORTING
*sent_to_all                = w_sent_all
  TABLES
  packing_list               = t_packing_list
  contents_bin               = t_attachment
  contents_txt               = li_content
  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.