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: 

CSV Download

Former Member
0 Kudos
107

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.

6 REPLIES 6

Former Member
0 Kudos
77

use gui_download function module.

regards,

srinivas

<b>*reward for useful answers*</b>

0 Kudos
77

please use FM GUI_DOWNLOAD.

Former Member
0 Kudos
77

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.

Former Member
0 Kudos
77

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

Former Member
0 Kudos
77

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

former_member404244
Active Contributor
0 Kudos
77

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