Hello Experts,
I've a requirement where I need to attach an excel sheet in email and send it to user. I'm able to do it and when user click on the 'Preview file' button in the email then file look good as shown below.
However, when user double click on the file to open and view then view the file then first column is blank (Rerate Num column is blank) as shown below.
Here is my code for reference.
-----------------------------------------------------------------------------------------------------------------------------------------------------
* Email header info
doc_chng-obj_name = c_subject.
doc_chng-obj_descr = c_subject.
* Create the message packing data
clear i_packing-transf_bin.
i_packing-head_start = 1.
i_packing-head_num = 0.
i_packing-body_start = 1.
i_packing-body_num = 0.
i_packing-doc_type = 'RAW'.
append i_packing.
* Report Summary header
"concatenate text-001 sy-uname into lv_string separated by space.
lv_string = text-001.
append lv_string to i_objbin.
"append text-002 to i_objbin.
append cl_abap_char_utilities=>cr_lf to i_objbin.
clear: lv_row.
lv_row = text-003.
append lv_row to i_objbin.
clear: lv_row.
loop at lt_output into lw_output.
append cl_abap_char_utilities=>cr_lf to i_objbin.
lv_new_amt = lw_output-new_amt.
condense lv_new_amt no-gaps.
concatenate lw_output-zrerate "'|'
lw_output-kunrg "'|'
lw_output-name1 "'|'
lw_output-auart "'|'
lw_output-initiator "'|'
lv_new_amt "'|'
lw_output-erdat "'|'
lw_output-idocnum "'|'
lw_output-idocerror
into lv_row SEPARATED BY ','.
append lv_row to i_objbin.
clear: lv_new_amt, lv_row.
lv_row = text-002.
append lv_row to i_objbin.
clear: lv_row.
endloop.
"append text-002 to i_objbin.
append cl_abap_char_utilities=>cr_lf to i_objbin.
append cl_abap_char_utilities=>cr_lf to i_objbin.
describe table i_objbin lines l_lines.
* create the message packing data
i_packing-transf_bin = 'X '.
i_packing-head_start = 1.
i_packing-head_num = 1.
i_packing-body_start = 1.
i_packing-body_num = l_lines.
i_packing-doc_type = 'CSV'."'RAW'.
i_packing-obj_name = 'EMAIL'.
i_packing-obj_descr = 'Re-rating Rebill order update summary'. "'Z_CRAETE_RERATE_DOC_order_creation_summary'.
i_packing-doc_size = l_lines * 255.
append i_packing.
* send email
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = doc_chng
put_in_outbox = ''
commit_work = 'X'
tables
packing_list = i_packing "Start of change 141.
contents_bin = i_objbin "End of change 141.
receivers = i_reclist
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 e188(zcpc) with 'Error sending email'.
endif.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Can somebody see what is the problem with my code and how to rectify it, please.
Many thanks in advance.