‎2005 Dec 14 11:42 AM
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
‎2005 Dec 14 11:50 AM
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.
‎2005 Dec 14 11:44 AM
‎2005 Dec 14 11:46 AM
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
‎2005 Dec 14 11:50 AM
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.
‎2005 Dec 14 12:19 PM
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
‎2005 Dec 14 12:24 PM
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.
‎2005 Dec 14 12:35 PM
Hi Amit,
Problem should solve with this..
Thanks a lot..
Regards
Sagar
‎2005 Dec 14 12:38 PM
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
‎2005 Dec 14 11:50 AM
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
‎2005 Dec 14 12:18 PM
Hi Sagar,
Please reward points to helpful answers / solved
by clicking the STAR on the left of the answer.
Regards,
Amit M.
‎2005 Dec 14 12:19 PM
Hi Sagar,
Please reward points to helpful answers / solved
by clicking the STAR on the left of the answer.
Regards,
Amit M.