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: 

Related to CSV file .

Former Member
0 Kudos
169

Hi,

How do we read a CSV file using OOPS concept? And at the same time how can we upload it is there any special functions to do that?please reply, urgent.

Thanks,

Sindhu.

5 REPLIES 5

andreas_mann3
Active Contributor
0 Kudos
70

hi,

use class CL_GUI_FRONTEND_SERVICES

methods: GUI_DOWNLOAD and GUI_UPLOAD

A.

Former Member
0 Kudos
70

Call the method

CL_GUI_FRONTEND_SERVICES->GUI_UPLOAD

This will upload the file into an internal table

You would then need to split at comma to get it into your required internal table format.

0 Kudos
70

Short sample here.



report zrich_0001.



types: begin of ttab,
       fld1(20) type c,
       fld2(20) type c,
       fld3(20) type c,
       end of ttab.
data: itab type table of ttab.
data: wa type ttab.

data: iup type table of string.
data: xup type string.

call method cl_gui_frontend_services=>gui_upload
  exporting
    filename                = 'C:test.csv'
  changing
    data_tab                = iup.

loop at iup into xup.
  split xup at ',' into wa-fld1
                        wa-fld2
                        wa-fld3.
  append wa to itab.
endloop.


loop at itab into wa.
  write:/ wa-fld1, wa-fld2, wa-fld3.
endloop.

Regards,

Rich Heilman

Former Member
0 Kudos
70

Hi Sindhu,

GUI_DOWNLOAD and GUI_UPLOAD are most easy ones to use.........

0 Kudos
70

Here is a slightly more dynamic approach.



report zrich_0001.


types: begin of ttab,
       fld1(20) type c,
       fld2(20) type c,
       fld3(20) type c,
       end of ttab.
data: itab type table of ttab.
data: wa type ttab.

data: iup type table of string.
data: xup type string.

data: isplit type table of string with header line.
field-symbols: <fs>.

call method cl_gui_frontend_services=>gui_upload
  exporting
    filename                = 'C:test.csv'
  changing
    data_tab                = iup.

<b>loop at iup into xup.

  clear wa.

  clear isplit.  refresh isplit.
  split xup at ',' into table isplit.

  loop at isplit.
    assign component sy-tabix of structure wa to <fs>.
    if sy-subrc <> 0.
      exit.
    endif.
    <fs> = isplit.
  endloop.

  append wa to itab.
endloop.</b>


loop at itab into wa.
  write:/ wa-fld1, wa-fld2, wa-fld3.
endloop.

Regards,

Rich Heilman