04-01-2008 7:33 AM
Hi
am using the simple program below.But am getting the output as FILE NOT READ.I hav a file with the same name in the 'C' drive.Please help.
REPORT ZBDC_3A.
DATA : FNAME(30) VALUE 'C:\ZFCHR1.TXT'.
DATA : STR(255).
OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
DO.
READ DATASET FNAME INTO STR.
IF SY-SUBRC = 0.
WRITE : / STR.
ELSE.
EXIT.
ENDIF.
ENDDO.
ELSE.
WRITE : 'FILE NOT FOUND TO READ'.
ENDIF.
CLOSE DATASET FNAME.
With Regards
Vijay
04-01-2008 7:39 AM
Are you trying to read a file from your PC?
Files stored on your PC are presentation server files and should be read using the FM WS_UPLOAD or GUI_UPLOAD.
Unix files or Application server files are read using OPEN DATASET statement. These files can be seen in transaction AL11.
04-01-2008 7:44 AM
Hi,
Use this FM GUI_DOWNLOAD.
Declare an interna table same as your File in the program.
Sample code is given below:-
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filepath
* FILETYPE = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = i_tab
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
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
Sandipan
Edited by: Sandipan Ghosh on Apr 1, 2008 12:15 PM
04-01-2008 8:01 AM
Hi,
Use Upload or download FM instead of Open dataset.
Hope this will help u
Regards,
Vijay K
04-01-2008 8:27 AM
Hi Vijay,
As the previous guys mentioned, we can use OPEN DATASET for the files on the Application server only.
But instead of changing the entire code, u can put the same file in the application server & use the same code.....
Use the transaction CG3Z for uploading the files in presentation server to Application server.
But specify a filepath (in which u want to upload the file in AL11 transaction) in the same transaction CG3Z.Then in that path, the file will be stored. Then u assign that filepath to FNAME in ur program. This will surely works.
Try this & let me know in case of any issues.
Dont forget to reward points if helpful.
Pavan.