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

Abap help

Former Member
0 Likes
1,883

hi folks,

I am uploading a .csv file into the internal table. The FM is working and the issue is the flat file has 33 fields of which many are blank (they have no data from the input file)and only 7 fields get populated.

Hence I have declared the internal table with those fields only.

The file format is in such a way that the there are two fields with data, then third fourth and fifth are blank again the sixth field is filled with data and the next few fields are blank.It is following that way.

obviously, the data is not sitting in the appropriate fields in the internal table.

How can I rectify that?

I am using the UPLOAD FM module. This is the code...

data: begin of rec occurs 1,

pernr(8) type c, "Employee Number

zzpaycode(4) type c, " Pay code

stdaz(5) type p decimals 2, " No of hours

bwgrl(9) type p decimals 4, " Currency

zzshift(1) type n, " zzshift

begda(8) type c, "Pay period end date

exbel(8) type c, " Dst Account

flag(1) type c,

end of rec.

call function 'UPLOAD'

exporting

filename = 'C:\Testdata\PRTRCSV53.csv'

filetype = 'ASC'

importing

cancel = answer

act_filename = filename

tables

data_tab = rec

exceptions

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

others = 6.

Thanks in advance.

Vinu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,817

First, do not use obsolete function modules like UPLOAD. Use GUI_UPLOAD instead.

Next, you cannot have your internal table defined in one way and the file coming in another way(in terms of the number of columns). Your spreadsheet columns should match your internal table columns.

16 REPLIES 16
Read only

Former Member
0 Likes
1,818

First, do not use obsolete function modules like UPLOAD. Use GUI_UPLOAD instead.

Next, you cannot have your internal table defined in one way and the file coming in another way(in terms of the number of columns). Your spreadsheet columns should match your internal table columns.

Read only

0 Likes
1,817

Why do advise him to use an obsolete FM module instead of an obsolete FM? Both FM are absolete!

Read only

0 Likes
1,817

As of which version, GUI_UPLOAD is obsolete Rainer Hubenthal?

Read only

0 Likes
1,817

I think Rainer got it mixed up with WS_UPLOAD.. I dont think GUI_UPLOAD is OBSOLETE as yet.. at least not on 47..

Vinu,

after changing the function call to GUI_UPLOAD, you should upload the file in to another itab..loop at that & transfer the relevant fields to your REC table..

Regards,

Suresh Datti

Read only

Former Member
0 Likes
1,817

Hi Vinu,

Why dont you use FM GUI_UPLOAD instead of UPLOAD.

Read only

0 Likes
1,817

I tried this it did not work....

call function 'GUI_UPLOAD'

exporting

filename = 'C:\Testdata\PRTRCSV53.csv'

filetype = 'ASC'

importing

cancel = answer

act_filename = filename

tables

data_tab = rec

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 .

Thanks

Vinu

Read only

0 Likes
1,817

No Vinu, GUI_UPLOAD will not solve your problem, look at my second point of the initial response.

I suggested using GUI_UPLOAD only because the other one is obsolete.

Read only

0 Likes
1,817

The version ECC5.0 and it is an exisiting program where the FM GUI_UPLOAD part of the code was commented and the FM 'UPLOAD' was used. I reversed that and it did nto work.

Thanks

Vinu.

Read only

0 Likes
1,817

Hi Vinu,

Your internal table should have the same amount of fields as your file as Srinivas said.

Read only

0 Likes
1,817

I work on ECC5.0 too...But checking the UPLOAD FM Code...They're using WS_UPLOAD, so UPLOAD should be obsolet too...

Greetings,

Blag.

Read only

0 Likes
1,817

I think you are gettin mixed up. Forget about what all of us are saying about UPLOAD function module.

To your problem, there are very few options. One is to define your internal table to have exact number of fields as you have values(blank or otherwise) in your csv file.

Another option as Suresh mentioned, is to define an internal table with just one field of length(maximum length needed) x. Upload the file into this internal table. You will then loop at this internal table and load your other table as follows.

loop at itab.
  split itab-record at ',' into final_itab-field1
                                some_junk_field
                                final_itab-field2
                                some_junk_field
                                some_junk_field
                                final_itab-field3.
  append final_itab.
  clear final_itab.
endloop.

Here some_junk_field is some variable whose value you don't care about.

Read only

Former Member
0 Likes
1,817

Hello

it's quite the same if you use UPLOAD or GUI_UPLOAD, the problem is that these FM's will not splitt the .csv lines into your table fields. You 'll have to do that in your program.

DATA: begin of rec occurs 1 ,

contents(100), " just long enough

end of rec,

begin of rec_a occurs 1,

.... (your fields)

end of rec_a.

Call function 'UPLOAD'

....

data_tab = rec

...

loop at rec.

clear rec_a.

splitt rec at ';' into rec_a-(your first field)

...

append rec_a.

endloop.

Regards Wolfgang

Read only

0 Likes
1,817

How about if I use 'READ DATASET... to read the .csv input file and using the 'split' command TO split the values into the appropriate fields in the internal table instead using the GUI_UPLOAD FM.

Thanks

Vinu

Read only

0 Likes
1,817

READ DATASET will work fine with your application server files, but I have never used it with desktop files.

Read only

0 Likes
1,817

I got your point.I shall go ahead with it.

Thanks

Vinu

Read only

0 Likes
1,817

It would make no difference, it won't splitt your input into your table fields. Use the splitt-command.