Google Search - Blog...........

ABAP - Uploading CSV Files Into Internal Table Using FM GUI_UPLOAD.

REPORT zupload_csv_file.

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.


ALSO READ:

- Creating A Directory On Presentation Server Using FM GUI_CREATE_DIRECTORY.

- Removing A Directory From Presentation Server Using FM GUI_REMOVE_DIRECTORY.

- Removing A File From Presentation Server Using FM GUI_DELETE_FILE.

- ZIP Files In Application Server Using FM SCMS_XSTRING_TO_BINARY.

- Saving Files To Presentation Server Using Methods.


RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.


4 comments:

  1. Hello,

    Is it possible to re-use this program to store a csv file to a sap application server. If yes, how to di it?

    Thanks.

    ReplyDelete
  2. Hi...

    i already testing using your code, that is working for my job.

    i have one question,
    how to delete sign # from idat ?.
    i already using many handle before append idat, eg : if itab <> '#' or '05' or '09' ext..but always unsuccessfull...


    thanks for your advice.

    ReplyDelete
  3. This won't work when the CSV file has fields enclosed by quotes, such as
    "Watkins Glen, NY",10996,etc.,etc.

    ReplyDelete
  4. Jolly

    Did you find a solution for getting rid of the #?

    ReplyDelete