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: 

upload csv file

Former Member
0 Kudos

hey

when i try to compile below GUI_UPLOAD method, i get below error

"ITAB IS NOT TYPE-COMPATIBLE WITH FORMAL PARAMETER DATA_TAB."

i declared internal table as below.

DATA: BEGIN OF ITAB OCCURS 0,

TRKORRNUM LIKE ZMW0001-TRKORRNUM,

CLIENT LIKE ZMW0001-CLIENT,

IMPORTDAY TYPE STRING,

CONVERTFILENAME LIKE ZMW0001-CONVERTFILENAME,

TRANSNO LIKE ZMW0001-TRANSNO,

EXETIMING LIKE ZMW0001-EXETIMING,

PRETRKORRNUM LIKE ZMW0001-PRETRKORRNUM,

MEMO LIKE ZMW0001-MEMO,

END OF ITAB.

CALL METHOD TEST->GUI_UPLOAD

EXPORTING

filename = Sourcepath

FILETYPE = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

CHANGING

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.

  • SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *

IF sy-subrc <> 0.

MESSAGE E001.

ENDIF.

could you please tell why.

ambichan.

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You can not directly upload the file into your internal table. My suggestion is to upload into a flat structured internal table. Then loop at that internal table and parse out the string into your fields of the other internal table. You are getting that error message because you must define you internal table to be compatiable with the DATA_TAB parameter of the method.

Regards,

Rich Heilman

0 Kudos

hey

i cant use FM GUI_UPLOAD to upload in flat file.

do u have any seperate method to upload in flat file?

pls let me know.

ambichan

0 Kudos

Why not?

Here is a sample.

report zrich_0004.

types: begin of tdata_tab,

rec(500) type c,

end of tdata_tab.

data: data_tab type table of tdata_tab.

data: filename type string.

parameters: p_file type localfile default

'C:\test.txt'.

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.

filename = p_file.

call method cl_gui_frontend_services=>gui_upload

exporting

filename = filename

changing

data_tab = data_tab

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.

check sy-subrc = 0.

Regards,

Rich Heilman

Former Member
0 Kudos

Does the file have to be csv, because if you convert it to tab delimeted I belive your original code will work. see http://www.sapdevelopment.co.uk/file/file_uptabpc.htm

Mart

0 Kudos

hey

thanks for your code.

but i want to confirm onething.

problem here is..i cant use GUI_UPLOAD FM to upload data

as because my code should support enterprise and other versions.

well.Now i am following below steps.

1-using Method GUI_UPLOAD.

2-i confirmed sy-subrc =0 after this method exec

3-whats the next step.?

do we have sample code for parsing by records

from upload flat table?

why using method is so tedious then FM..was what we doing

is the only way to upload data..

using GUI_UPLOAD FM makes so simpled to upload..but here

looks so many steps...anyway pls guide me

ambichan

0 Kudos

Now just loop through your data_tab. Use the split keyword to split the string into fields of your new itab.

Data: begin of new_itab occurs 0,

field1 type c,

field2 type c,

field3 type c,

end of new_itab.

loop at data_tab.

split data_tab at ',' into new_itab-field1

new_itab-field2

new_itab-field3.

append new_itab.

endloop.

Regards,

Rich Heilman

0 Kudos

types: begin of flat_itab,

rec(500) type c,

end of flat_itab.

Data: begin of new_itab occurs 0,

field1(10) type c,

field2(20) type c,

field3(10) type c,

field4(10) type c,

field5(10) type c,

field6(10) type c,

field7(10) type c,

field8(100) type c,

end of new_itab.

data: data_tab type table of flat_itab.

data: fname type string.

fname = 'C:\sun\rs3text.csv'.

call method cl_gui_frontend_services=>gui_upload

exporting

filename = fname

changing

data_tab = data_tab

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.

write sy-subrc.

loop at data_tab.

split data_itab at ',' into new_itab-field1

new_itab-field2

new_itab-field3

new_itab-field4

new_itab-field5

new_itab-field6

new_itab-field7

new_itab-field8.

append new_itab.

endloop.

actually my file is CSV tab delimited file..how to proceed. when i compile this i get compile error saying

"data_tab contains no header." INTO WA.....

why