Application Development and Automation 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: 
Read only

upload csv file

Former Member
0 Likes
896

hi all

i need to upload a csv file.

plz suggest an appropriate fm or class for the same

regards

Navjot

6 REPLIES 6
Read only

Former Member
0 Likes
834

Hi,

You can use GUI_UPLOAD or KCD_EXCEL_OLE_TO_INT_CONVERT.

Reward if helpful.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
834

Here is an example program.



report zrich_0001.

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.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
834

You can use FM <b>TEXT_CONVERT_TEX_TO_SAP</b> and pass separator comma as import parameter....

Regards

Prax

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
834

Hi,

first upload the csv file into internal table by using GUI_UPLOAD of internal table of one variable of type char(255) or greater.

split itab1 at ',' into itab-fld1 itab-fld2 itab-fld3.

Now ur internal table contains all the field names and values..

Cheers,

Simha.

Read only

Former Member
0 Likes
834

hi,

use the FM-

ws_upload or gui_upload. to know more about the FM's u can refer the site www.se37.com.

regards,

srinivas

<b>*reward points if helpful*</b>

Read only

Former Member
0 Likes
834

You can also use... Fm <b>KCD_CSV_FILE_TO_INTERN_CONVERT</b> in the following way..

type-pools: KCDE.


data:  itab1 type KCDE_INTERN.


CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT'
  EXPORTING
    i_filename            = 'U:tempsheet1_20070519_054301.csv'
    i_separator           = ','
  tables
    e_intern              = itab1
 EXCEPTIONS
   UPLOAD_CSV            = 1
   UPLOAD_FILETYPE       = 2
   OTHERS                = 3
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

itab1 contains all the rows and columns of CSV file...

Regards

Prax