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: 

Transfer file

Former Member
0 Kudos
120

Hi All,

I have two clarificatios.

1.How to open a file which is in .csv format from application server and transfer the contents to internal table and also how to transfer a file from presentation server in .csv format to internal table.I have tried fm "WS_UPLOAD" & "GUI_UPLOAD".But neither works.

2.one of the column in file is supposed to be like this "Attribute,Not proper" but it becomes attributes in one cell and "not proper" to next cell.I want "Attribute,Not proper" to transfer to a same field in int.table.

Could anybody help.

Thanks,

Ponraj.s.

ponraj_rec@yahoo.com

1 ACCEPTED SOLUTION

Former Member
0 Kudos
80

Ponraj,

1. What is the error when you try to use the below functions...I think it should be able to upload the file and use the split function to separate the fields.

2. It is difficult to resolve the particular issue unless you use a diffent separator. Since it is a CSV the particular data would get interpreted as two coln. The only option is to manipulate the data once it is in the internal table.

Regards

Anurag

Message was edited by: Anurag Bankley

10 REPLIES 10

Former Member
0 Kudos
80

1) appliction to internal table.

report zkish
no standard page heading.


parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.csv'.

data: begin of itab occurs 0,
fld1(20) type c,
fld2(20) type c,
fld3(20) type c,
end of itab.
data: wa(2000) type c.


start-of-selection.

open dataset d1 for input in text mode.
if sy-subrc = 0.
do.
read dataset d1 into wa.
if sy-subrc <> 0.
exit.
endif.
split wa at ',' into itab-fld1 itab-fld2 itab-fld3.
append itab.
enddo.
endif.
close dataset d1.

<b>pc to internal table..</b>

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.

Former Member
0 Kudos
81

Ponraj,

1. What is the error when you try to use the below functions...I think it should be able to upload the file and use the split function to separate the fields.

2. It is difficult to resolve the particular issue unless you use a diffent separator. Since it is a CSV the particular data would get interpreted as two coln. The only option is to manipulate the data once it is in the internal table.

Regards

Anurag

Message was edited by: Anurag Bankley

0 Kudos
80

Hi Anurag,

Now the first one is working fine using fm "gui_upload".

but for my second clarification is there any other option ,sice its hard to manipulate in internal table.

0 Kudos
80

It would be helpful to understand what would be the data in the particular field. Can you cut-paste few different data scenario ??, it would easier to formulate the logic.

But I can suggest couple of solutions :

1. It needs to be at the source where you can use a different delimiter or replace the comma from Attribute,Not proper in some way.

2. Second, is when you have the data in an internal table after GUI_UPLOAD.Before the SPLIT command use the REPLACE the particular string "Attribute,Not Proper" to "Attribute-Not Proper". But that depends whether is it the only possible situation or there can be more such cases.

Regards

Anurag

Message was edited by: Anurag Bankley

0 Kudos
80

Hi Anurag & All,

Thanks for your info.

Anurag,

you have asked the scenario in my file,I have given an example.can anybody help.

My csv file would be like this.If idoc status is 53 I will get message sucsess in prev cell and material number in next cell.If it is 51 I will get corresponding error message such as "novalue","attribute,notproper".

since there is an comma bw attribute & not proper everything is moved to next cell in the row.So how do i transfer it to int table field "ATTRIBUTE,NOTPROPER "

22/7/2006 SUCCESS 53 75008845

22/7/2006 SUCCESS 53 75008846

23/7/2006 ATTRIBUTE NOTPROPER 51 75005000

23/7/2006 NOVALUE 51 75008837

0 Kudos
80

is the input file seperator can be changed to any other like ; or : or tab etc.. sothat splitting will be easy.

can you with the user & revert.

regards

srikanth

0 Kudos
80

I feel the best solution is ---

call function 'gui_upload'

exporting....

tables

data_tab = itab.

loop at itab.

replace 'ATTRIBUTE,NOTPROPER' with 'ATTRIBUTE-NOTPROPER'.

split itab at ',' into iout.

append iout.

endloop.

Regards

Anurag

Former Member
0 Kudos
80

For a CSV file problem number 2 cannot be solved, instead you have to change the format from CSV to say '#' or Tab separated.

Former Member
0 Kudos
80

Hi,

Concatenate the two fields and assign it to field in Internal table

Former Member
0 Kudos
80

<b>for your 1st Q:

from application server:</b>

data : v_string type string.

transfer v_file into V_STRING.

SPLIT V_STRING AT ','

INTO ITAB-FIELD1

ITAB-FIELD2.

APPEND ITAB.

here your ITAB will populated accordingly from the V_STRING.

<b> from presentation server</b>

USE GUI_UPLOAD function module

give filename = 'c:\abc.csv'.

filetype = 'asc'

has_field_seperator = 'X'.

if you pass these 3 fields to the function module ,automatically values will be populated to your internal table.

no extra coding is required, i believe.