09-08-2009 7:48 AM
My requirement is that , i have one file already present in the AL11 server. Now i want to take this file so that I can read this file .
So will you please help me , how to read the file from AL11 server in our program ?
Thankx in advance
09-08-2009 7:50 AM
09-08-2009 7:50 AM
search the forum for open dataset , you will get many results which serve ur pupose.
09-08-2009 7:51 AM
Hi ,
You can use read dataset statement.
READ DATASET v_filepathname INTO t_file.
Go through Read dataset documentation for more details.
Regards,
Naveen
09-08-2009 7:55 AM
You can use
OPEN DATASET 'FileName'
to read the file
First makke sure the file exists using
cl_gui_frontend_services=>file_exist
then read it.
09-08-2009 7:58 AM
Hi,
OPEN DATASET lv_filename FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
READ DATASET lv_filename INTO lv_line.
CLOSE DATASET lv_filename.
Regards
Ansari
09-08-2009 9:31 AM
So this means , before close dataset & in the read dataset , i can read the text file ?
my file has a definite structure ( a well defined structure ) So now how can I access or read that text file after this ???
reply
09-08-2009 9:40 AM
Using the read dataset you can read into the structure
For Example
READ DATASET 'file' into Variable
if sy-subrc eq 0
"do the necessary action you want to perform on data
endif.
09-08-2009 9:45 AM
Hi..
I too agree to the above post .. SEARCH in SCN before posting..
DATA: lv_filename TYPE string, "File name
lv_line TYPE string. "One line entry in a file
lv_filename = iv_file_name.
IF iv_location = gc_application.
IF iv_record_count IS SUPPLIED.
Open file
IF gv_file IS INITIAL.
OPEN DATASET lv_filename FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF sy-subrc <> 0.
RAISE file_open_error.
ENDIF.
gv_file = gc_check.
ENDIF.
Read data
DO iv_record_count TIMES.
READ DATASET lv_filename INTO lv_line.
IF sy-subrc <> 0.
Close file
CLOSE DATASET lv_filename.
IF sy-subrc NE 0.
RAISE file_close_error.
ENDIF.
CLEAR gv_file.
Exit from the loop
EXIT.
ENDIF.
Regards
Ansari
09-08-2009 9:42 AM
09-08-2009 9:46 AM
Hi..
You can use the below way.
IF gv_file_name IS NOT INITIAL.
OPEN DATASET lv_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
DO.
READ DATASET lv_path INTO gw_record_input-rec.
IF sy-subrc EQ 0.
APPEND gw_record_input TO gi_record_input.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_path.
ENDIF.
ENDIF.
REFRESH : gi_record[].
CLEAR : gv_sr_no.
gv_sr_no = 001.
*Read all record of on file
LOOP AT gi_record_input INTO gw_record_input.
do the processing
APPEND gw_record TO gi_record.
gv_sr_no = gv_sr_no + 1.
CLEAR : gw_record.
ENDLOOP.
let me know if this was of any help to you.