2007 Jul 23 11:31 AM
Hi Guys,
please give me a code to convert an internal table into csv format and attach it to mail and send.
Thanks n Regards,
Santosh Kotra.
2007 Jul 23 11:33 AM
use gui_download function module.
regards,
srinivas
<b>*reward for useful answers*</b>
2007 Jul 23 11:36 AM
2007 Jul 23 11:35 AM
Hi,
Check the followin code,
types: begin of ttab,
rec(1000) type c,
end of ttab.
types: begin of tdat,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of tdat.
data: itab type table of ttab with header line.
data: idat type table of tdat with header line.
data: file_str type string.
parameters: p_file type localfile.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
file_str = p_file.
call function 'GUI_UPLOAD'
exporting
filename = file_str
tables
data_tab = itab
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
loop at itab.
clear idat.
split itab-rec at ',' into idat-fld1
idat-fld2
idat-fld3.
append idat.
endloop.
loop at idat.
write:/ idat-fld1, idat-fld2, idat-fld3.
endloop.
Reward if helpful.
2007 Jul 23 11:39 AM
Hi
Download it to a file type .CSV using GUI_DOWNLOAD and send it as attache ment to a mail
see the sample code
Mailing with Attachment by ABAP Coding
Refer this link:
FORM send_list_to_basis .
DATA: w_path LIKE rlgrap OCCURS 0 WITH HEADER LINE,
lt_index TYPE sy-tabix,
doc_type(3) TYPE c,
descr LIKE it_objpack_basis-obj_descr,
temp_data LIKE w_path,
temp1 TYPE string,
tab_lines TYPE i,
langu(15) TYPE c,
expirydate TYPE so_obj_edt,
L_FILE1(100).
CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.
W_PATH-FILENAME = L_FILE1.
APPEND w_path.
CLEAR w_path.
wa_doc_chng-obj_descr = 'User List not logged on for 180 days'.
wa_doc_chng-obj_langu = 'E'.
wa_doc_chng-obj_expdat = sy-datum.
CLEAR w_subject.
CONCATENATE 'Please find attached document with list of users'
'not logged on for 180 days for client' sy-mandt
INTO w_subject SEPARATED BY space.
it_objtxt_basis-line = w_subject.
APPEND it_objtxt_basis.
CLEAR it_objtxt_basis.
it_objtxt_basis-line = text-004.
APPEND it_objtxt_basis.
CLEAR it_objtxt_basis.
CLEAR w_tab_line.
DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.
READ TABLE it_objtxt_basis INDEX w_tab_line INTO l_cline.
wa_doc_chng-doc_size =
( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).
CLEAR it_objpack_basis-transf_bin.
it_objpack_basis-head_start = 1.
it_objpack_basis-head_num = 0.
it_objpack_basis-body_start = 1.
it_objpack_basis-body_num = w_tab_line.
it_objpack_basis-doc_type = 'RAW'.
APPEND it_objpack_basis.
CLEAR it_objpack_basis.
LOOP AT w_path.
temp1 = w_path.
descr = w_path.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = descr
lang = 'E'
IMPORTING
rstring = descr.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
delimiter = '\'
string = descr
IMPORTING
head = descr
tail = temp_data.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = descr
lang = 'E'
IMPORTING
rstring = descr.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
delimiter = '.'
string = descr
IMPORTING
head = temp_data
tail = doc_type.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = temp1
filetype = 'BIN'
header_length = 0
read_by_line = 'X'
replacement = '#'
TABLES
data_tab = it_upload.
DESCRIBE TABLE it_upload LINES tab_lines.
DESCRIBE TABLE it_objbin_basis LINES lt_index.
lt_index = lt_index + 1.
LOOP AT it_upload.
wa_objbin_basis-line = it_upload-line.
APPEND wa_objbin_basis TO it_objbin_basis.
CLEAR wa_objbin_basis.
ENDLOOP.
it_objpack_basis-transf_bin = 'X'.
it_objpack_basis-head_start = 0.
it_objpack_basis-head_num = 0.
it_objpack_basis-body_start = lt_index.
it_objpack_basis-body_num = tab_lines.
it_objpack_basis-doc_type = doc_type.
it_objpack_basis-obj_descr = descr.
it_objpack_basis-doc_size = tab_lines * 255.
APPEND it_objpack_basis.
CLEAR it_objpack_basis.
ENDLOOP.
it_reclist_basis-receiver = 'XXX@.com'.
it_reclist_basis-rec_type = 'U'.
APPEND it_reclist_basis.
CLEAR it_reclist_basis.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack_basis
contents_txt = it_objtxt_basis
contents_bin = it_objbin_basis
receivers = it_reclist_basis
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc EQ 0.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.
ENDFORM. " send_list_to_basis
<b>Reward points for useful Answers</b>
Regards
Anji
2007 Jul 23 11:39 AM
Sathosh,
I am giving the sample code here.
data : begin of text occurs 0,
field(90) type c.
end of text.
Loop at itab.
concatenate itab-field1 ',' itab-field2 ',' itab-field3 into text.
append text.
endloop.
Now Download it using FM GUI_DOWNLOAD.
and use the FM 'SO_DOCUMENT_SEND_API1' to e-mail this excel sheet.
Hope this helps.
Regards,
Sujatha
2007 Jul 23 11:43 AM
Hi,
use the FM SAP_CONVERT_TO_CSV_FORMAT to convert CSV fornat and
use the FM 'SO_DOCUMENT_SEND_API1' to e-mail this excel sheet.
Regards,
nagaraj