‎2014 Feb 18 9:11 PM
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.
‎2014 Feb 19 4:07 AM
Hi Zero,
loop at lt_output into lw_output.
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.
right now im not connected
at every loop you are appending a break line, do it at the end of line
try this changes and make it better(i cant right now)
loop at lt_output into lw_output.
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 ','.
concatenate lv_row cl_abap_char_utilities=>cr_lf into lv_row
append lv_row to i_objbin.
clear: lv_new_amt, lv_row.
endloop.
what is text-002???
Regards,
MC
Message was edited by: Marco Cristobal I just tried your code (:
‎2014 Feb 19 1:32 AM
Could you attach the content of that csv file?
EDIT: What is value of text-002, and why is delimiter not used while adding it to attachment content?
‎2014 Feb 19 1:58 AM
Thanks for your input Manish. I've tried but I'm unable to upload CSV file here.
‎2014 Feb 19 2:44 AM
Actually I've just noticed that all the columns are coming but here is the issue. I've to squeeze first column so much to view the details. I've provided the code above. Can anybody please see what is my mistake and how to rectify it?
‎2014 Feb 19 2:53 AM
You can change extension to .txt and try. Otherwise paste the contents of renamed txt file here.
‎2014 Feb 19 2:57 AM
‎2014 Feb 19 4:07 AM
Hi Zero,
loop at lt_output into lw_output.
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.
right now im not connected
at every loop you are appending a break line, do it at the end of line
try this changes and make it better(i cant right now)
loop at lt_output into lw_output.
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 ','.
concatenate lv_row cl_abap_char_utilities=>cr_lf into lv_row
append lv_row to i_objbin.
clear: lv_new_amt, lv_row.
endloop.
what is text-002???
Regards,
MC
Message was edited by: Marco Cristobal I just tried your code (:
‎2014 Feb 19 4:08 PM
Thanks for your help Marco. I've removed text-002 as it was redundant. Here is the fresh code.
----------------------------------------------------------------------------------------------
data: lv_bname like usr21-bname,
lv_persnum like usr21-persnumber,
lv_addrnum like usr21-addrnumber,
lv_email like adr6-smtp_addr,
lv_string type string,
lv_row type string,
lv_rerate type char12,
lv_new_amt type char10.
data: i_packing like sopcklsti1 occurs 0 with header line,
i_objbin like solisti1 occurs 0 with header line,
"i_objbin like line of contents_txt,
* i_objbin type solix_tab,
* size type so_obj_len,
i_reclist like somlreci1 occurs 0 with header line,
doc_chng like sodocchgi1,
l_tabix like sy-tabix,
l_lines type i.
if pemail1 is not initial.
i_reclist-receiver = pemail1.
i_reclist-rec_type = 'U'.
append i_reclist.
endif.
* 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.
clear: lv_row, lv_rerate.
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.
lv_rerate = lw_output-zrerate.
CONDENSE lw_output-zrerate NO-GAPS.
concatenate lv_rerate "'|'
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 ','.
CONDENSE lv_row NO-GAPS.
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, lv_rerate.
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.
-----------------------------------------------------------------------------------------------
I know you've said I should try to use contents_txt instead of contents_bin I tried but had errors in data definition. Can you please give any example or change my code accordingly.
Also I've converted CSV into txt and it's attached (the attached file of the email).
‎2014 Feb 19 4:25 PM
hi,
please
use this
in the header
********************************************
* 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.
concatenate lv_string cl_abap_char_utilities=>cr_lf into lv_row.
append lv_row to i_objbin
***********************************************
in the detail
****************************************************
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.
lv_rerate = lw_output-zrerate.
CONDENSE lw_output-zrerate NO-GAPS.
concatenate lv_rerate "'|'
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 ','.
CONDENSE lv_row NO-GAPS.
concatenate lv_row cl_abap_char_utilities=>cr_lf into lv_row.
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, lv_rerate.
endloop.
************************************************************
note that you must set the break line at the end of the line
try it please, i think its ok, didnt have the time to do it
Regards
MC
‎2014 Feb 19 4:45 PM
You have been spending lot of time on similar requirements.
Here are some tips for you.
Coming to your specific issue, attached file when opened in notepad reveals that line 1 has 256 characters, other lines of 509 characters each, having first 254 characters blank. All this is happening because of direct append to i_objbin.
Instead of appending lv_row, you should concatenate to lv_final_data (type string) to build complete output data. Once the final string is ready, you can pass it to class CL_BCS_CONVERT method STRING_TO_SOLI, which will return internal table compatible with i_objbin type. There are function modules also to do it, but i am not mentioning them as in long run, one line statement like this would seem simpler to you.
data lv_final_data type string.
*startloop
lv_row = actual line or cr_lf
concatenate lv_final_data lv_row into lv_final_data.
*endloop
condense lv_final_data.
i_objbin[] = cl_bcs_convert=>string_to_soli( lv_final_data ).
‎2014 Feb 19 8:02 PM
Thanks a lot Manish your advise has resolved my issue and I've learned something new .