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: 

how to upload .csv file into a custom table

Former Member
0 Kudos

Dear Friends,

I have a requirement where i have to upload data from the .csv file to my custom table could any one please give me the procedure , could any one give me a sample piece of code the upload data from .csv file to my custom table.

Regards

Madhuri.

3 REPLIES 3

Former Member
0 Kudos

hi,

please go through this thread, u have couple of sample prog:

regards,

madhu

ouhamoumustapha
Active Participant
0 Kudos

Hi,

Use the function module 'GUI_UPLOAD' to upload a .CSV into an internal table:

Simple code :

TABLES : kna1.

DATA : BEGIN OF t_data OCCURS 0,

kunnr LIKE kna1-kunnr,

name1 LIKE kna1-name1,

ort02 LIKE kna1-ort02,

END OF t_data.

DATA : w_fname TYPE string.

SELECT-OPTIONS : s_kunnr FOR kna1-kunnr.

PARAMETERS : p_name LIKE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

mask = ',Fichier .csv,csv*.'

static = 'X'

CHANGING

file_name = p_name.

w_fname = p_name.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = w_fname

filetype = 'ASC'

TABLES

data_tab = t_line.

LOOP AT t_data.

WRITE : / t_data-kunnr, t_data-name1, t_data-ort02.

ENDLOOP.

and after add to ur code

MODIFY dbtab FROM TABLE t_data.

Good luck

reward if its helpful

Mustapha

Former Member
0 Kudos

Really lazy way.


types: begin of this_type,
one,
two,
three,
four,
end of this_type.

data: itab type table of this_type,
      w_ar like line of itab.
data: line type table of string,
      w_line type string.
field-symbols <fs> type any.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = 'C:\archivito.txt'
  tables
    data_tab                      = line
 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 line into w_line.
do.
assign component sy-index of structure w_ar to <fs>.
if sy-subrc ne 0.
exit.
endif.
split w_line at ',' into <fs> w_line.
enddo.
append w_ar to itab.
clear w_ar.
endloop.

My csv file in case you want to try it


a,b,c,d
e,f,g,h