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

Writing File into Application Server

Former Member
0 Likes
1,023

Hello,

In one scenario i ve to upload a text file into the Application Server.

I know to upload the file through tcode CG3Z, but i have to upload the file through the code.

How to do that?

Please reply.

Regards,

Rahul

8 REPLIES 8
Read only

Former Member
0 Likes
891
Read only

Former Member
0 Likes
891

Firs Load the FIle to Intenal table using the Function GUI_UPLOAD.

Second :

Using

open the app file for writing using

OPEN DATASET

Now Loop the internal table

and transfer each record

Now close the File using the Close dataset.

Read only

0 Likes
891

Hi,

Open dataset, transfer file to dataset and close dataset statements will solve your purpose.

Raghav

Read only

Former Member
0 Likes
891

if you have the data in an internal table itab, do as follows

open dataset <filename> for output in text mode.

if sy-subrc = 0.
loop at itab.
concatenate itab-field1 itab-field2 itab-field3...into v_text.
tranfer v_text to <filename>.
endloop.
close dataset <filename>.
endif.

Read only

Former Member
0 Likes
891

Hi Rahul,

Save the excel file as Tab delimited, and use the FM: GUI_UPLOAD.

DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.

DATA: begin of it_datatab occurs 0,

row(500) type c,

end of it_datatab.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = i_file

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = it_datatab "ITBL_IN_RECORD[]

EXCEPTIONS

file_open_error = 1

OTHERS = 2.

Hope this helps you.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
891

hi check this..

DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.

open dataset e_file for output in text mode.

lOOP AT it_datatab......

transfer it_datatab to e_file.

ENDLOOP.

close dataset e_file.

Read only

Former Member
0 Likes
891

Hi Rahul.

I would like to suggest a few,

UPLOAD_FILES.

This function module is usefull for both Application server as well as Presentation server.

Hope that's usefull.

Good Luck & Regards.

Harsh Dave

Read only

Former Member
0 Likes
891

Thanks