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

Save to text file

Former Member
0 Likes
1,573

Hi Experts,

Im trying to read first a text file and I wanted to replace the contents of the said file, How can I save the changes that I did on the text file? do you know what FM I can use? Thanks

BR,

Chris

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,539

Hi,

First read the text file into internal table using FM shown below.

  • FM call to upload file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file_name

filetype = lv_filetype

has_field_separator = lv_gui_sep

TABLES

data_tab = gi_zhralcon_file.

Then after the reqd changes use the FM as shown.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = binfile

filename = 'D:\MYFILE.txt' //give the address where u want output.

FILETYPE = 'BIN'

tables

data_tab = pdftab

Hope it helps.

Regards

Rajesh Kumar

Hi Experts,

Im trying to read first a text file and I wanted to replace the contents of the said file, How can I save the changes that I did on the text file? do you know what FM I can use? Thanks

BR,

Chris

13 REPLIES 13
Read only

Former Member
0 Likes
1,539

HI,

Use FM

GUI_UPLOAD

and

GUI_DOWNLOAD

Regards,

Vijay

Read only

Former Member
0 Likes
1,540

Hi,

First read the text file into internal table using FM shown below.

  • FM call to upload file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file_name

filetype = lv_filetype

has_field_separator = lv_gui_sep

TABLES

data_tab = gi_zhralcon_file.

Then after the reqd changes use the FM as shown.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = binfile

filename = 'D:\MYFILE.txt' //give the address where u want output.

FILETYPE = 'BIN'

tables

data_tab = pdftab

Hope it helps.

Regards

Rajesh Kumar

Read only

0 Likes
1,539

Hi,

What if the contents of my file doesn't contain any field separator, only a TAB, can I indicate there that I wanted to replace the TAB with a comma? Thanks

BR,

Chris

Read only

0 Likes
1,539

Hi Chrish again,

Yes you can upload and download file with Tab Separator.

In FM

GUI_UPLOAD

pass paramenter as

HAS_FIELD_SEPARATOR = 'X'.

Regards,

Vijay

Read only

0 Likes
1,539

No, you can not as ther is no such parameter.

This is just to download in tab delimited text file.

Regds,

Anil

Read only

0 Likes
1,539

Hi,

Yes you can idicate there that you want to replace TAB with COMMA.

Regards,

Pavan.

Read only

0 Likes
1,539

Hi Pavan,

Is there a parameter to indicate that, or do I need to code it manually? Thanks

BR,

Chris

Read only

0 Likes
1,539

Hi LeBron,

I dont think there will be some parameter for that. As per my knowledge is concerned you need to code it manually. thanks.

Regards,

Pavan.

Read only

0 Likes
1,539

Thanks everything is clear now, I will code it manually 😃

BR,

LBJ23

Read only

0 Likes
1,539

Hi,

Check WRITE_FIELD_SEPARATOR parameter documentation of GUI_DOWNLOAD in se37.

Hope it helps.

Regards,

Rajesh Kumar

Read only

0 Likes
1,539

You need to set 'X' value to the import parameter HAS_FIELD_SEPARATOR

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME =

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ' X'

Value 'X' means: Fields are separated by tabs.

Read only

0 Likes
1,539

Thanks again for the help everyone =),

BR,

LBJ23

Read only

Former Member
0 Likes
1,539

Hi,

You can try the following

1) Upload the text file to a internal table using GUI_UPLOAD.

2) Make the necessary changes to the internal table fields.

3) Pass this internal table to GUI_DOWNLOAD mentioning the same path and file name.

By this the text file will be replaced with the downloaded file with replaced contents.