Application Development 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: 

How to read the text file present in the Al11 server through our program?

Former Member
0 Kudos

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

10 REPLIES 10

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You need to use open dataset statement.

Former Member
0 Kudos

search the forum for open dataset , you will get many results which serve ur pupose.

Former Member
0 Kudos

Hi ,

You can use read dataset statement.

READ DATASET v_filepathname INTO t_file.

Go through Read dataset documentation for more details.

Regards,

Naveen

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

Please SEARCH in SCN before posting

Former Member
0 Kudos

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.