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

Edit a text file

former_member194099
Active Participant
0 Likes
2,134

Hello,

Is there a way in ABAP to open a text file kept on presentation server and then programatically edit it?

There are two functions GUI_UPLOAD and GUI_DOWNLOAD, but they fetch the data from file in form of table!!

Regards

Sagar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,569

Hi Sagar,

1 Try this Code (Just copy paste)

( This will work fantastic for TXT files)

REPORT abc.

DATA : fn TYPE STRING.

DATA : BEGIN OF itab OCCURS 0,

ln(100) TYPE c,

END OF itab.

START-OF-SELECTION.

fn = 'D:\abc.txt'.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = fn

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

.

EDITOR-CALL FOR itab.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = FN

tables

data_tab = ITAB

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

BREAK-POINT.

Regards,

Amit M.

10 REPLIES 10
Read only

Former Member
0 Likes
1,569

Hi

What do you want to do?

Max

Read only

Former Member
0 Likes
1,569

Hi Sagar,

after you have loaded you file in the internal table, if I understood your problem, you can write on screen (write command) each record enabling the input mode.

In this way you could modify the text.

In other word you can build an interactive report, where you write only the file in the internal table.

I hope it can help you.

By

enzo

Read only

Former Member
0 Likes
1,570

Hi Sagar,

1 Try this Code (Just copy paste)

( This will work fantastic for TXT files)

REPORT abc.

DATA : fn TYPE STRING.

DATA : BEGIN OF itab OCCURS 0,

ln(100) TYPE c,

END OF itab.

START-OF-SELECTION.

fn = 'D:\abc.txt'.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = fn

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

.

EDITOR-CALL FOR itab.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = FN

tables

data_tab = ITAB

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

BREAK-POINT.

Regards,

Amit M.

Read only

0 Likes
1,569

Hi Amit,

Your program partly solves the problem!!

After I upload a file to internal table(itab), I need to edit it programatically and not through a manual editor.

I have to replace certain words in the text file actually.

So after I execute my report I should get an updated text file.

So instead of EDITOR-CALL can I go and replace some text in itab??

Thanks lot for your help.

With Regards

Sagar

Read only

0 Likes
1,569

Hi again,

1. yes.

Loop at the internal table.

use keyword

REPLACE (just see F1 help)

and accordingly modify the internal table.

Then finally use GUI_DOWNLOAD.

This will solve ur requirement.

regards,

amit m.

Read only

0 Likes
1,569

Hi Amit,

Problem should solve with this..

Thanks a lot..

Regards

Sagar

Read only

0 Likes
1,569

Hi

You need to manage the string you've loaded in an internal table:

CALL FUNCTION 'GUI_UPLOAD'

............

TABLES

DATA_TAB = T_FILE.

LOOP AT T_FILE.

REPLACE 'HELLO' WITH 'BYE BYE' INTO T_FILE.

MODIFY T_FILE.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

............

TABLES

DATA_TAB = T_FILE.

Max

Read only

Former Member
0 Likes
1,569

hi,

1) upload that file to sap internal table using GUI_UPLOAD

2) modify this internal table how you want

3) download the same internal table to presentation server using GUI_DOWNLOAD

thanks

srikanth

Read only

Former Member
0 Likes
1,569

Hi Sagar,

Please reward points to helpful answers / solved

by clicking the STAR on the left of the answer.

Regards,

Amit M.

Read only

Former Member
0 Likes
1,569

Hi Sagar,

Please reward points to helpful answers / solved

by clicking the STAR on the left of the answer.

Regards,

Amit M.