Skip to Content
0
Former Member
Mar 09, 2009 at 10:05 PM

Problem to send text file to mail from ALV report

43 Views

Hi Friends,

I have a problem in my ALV report with text file. As per the requirment, when we execute the program then text attachment should go to the particual email.

When i am using file type as XLS i am getting attachment with all 4 recoreds( input for 4 records) in mail. But all 4 records are coming in SAME ROW. It should come 4 records in 4 rows. when I use file type as TXT and separated by pipe symble in code, it is showing only one recored for same above input.

When i use file type as XLS and click the attachment in email, it will triggire one popul with three options like SAVE, OPEN, CANCEL.

But when i click on text file attachment, it is directly showing ony one recored.

Please correct me on this.

my code is

PERFORM send_file_as_email_attachment

tables i_message

i_attach

using v_email

'User last log on details'

'XLS'

'User log on list'

' '

' '

' '

changing v_error

v_reciever.

FORM send_file_as_email_attachment tables pi_message

pi_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

DATA: l_error TYPE sy-subrc,

l_reciever TYPE sy-subrc,

l_mtitle LIKE sodocchgi1-obj_descr,

l_email LIKE somlreci1-receiver,

l_format TYPE so_obj_tp ,

l_attdescription TYPE so_obj_nam ,

l_attfilename TYPE so_obj_des ,

l_sender_address LIKE soextreci1-receiver,

l_sender_address_type LIKE soextreci1-adr_typ,

l_receiver LIKE sy-subrc.

l_email = p_email.

l_mtitle = p_mtitle.

l_format = p_format.

l_attdescription = p_attdescription.

l_attfilename = p_filename.

l_sender_address = p_sender_address.

l_sender_address_type = p_sender_addres_type.

  • Fill the document data.

v_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

v_doc_data-obj_langu = sy-langu.

v_doc_data-obj_name = 'SAPRPT'.

v_doc_data-obj_descr = l_mtitle .

v_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR v_doc_data.

READ TABLE i_attach INDEX v_cnt.

v_doc_data-doc_size =

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

v_doc_data-obj_langu = sy-langu.

v_doc_data-obj_name = 'SAPRPT'.

v_doc_data-obj_descr = l_mtitle.

v_doc_data-sensitivty = 'F'.

CLEAR i_attachment.

REFRESH i_attachment.

i_attachment[] = pi_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.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = v_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 = v_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.