2006 Apr 18 9:55 AM
hi
Could anyone tell me how to read a file from application server.
following is my code,
PARAMETERS : p_server LIKE /sapdmc/lsofis-filename.
note: no FM is used to read file name.
open dataset p_server for input in text MODE.
if sy-subrc <> 0.
message e303(z03_sd) with text-013.
message e300 with text-013.
endif.
clear itb_buffer.
DO.
Read dataset p_server into itb_buffer .
if sy-subrc <> 0.
Message e302 with text-012.
message e300 with text-012.
else.
Append itb_buffer to itb_temp.
endif.
enddo.
close dataset p_server.
endif.
error is dataset_cant_open.
please can solve this problem as early as possible.
thanx
raj
hi
Could anyone tell me how to read a file from application server.
following is my code,
PARAMETERS : p_server LIKE /sapdmc/lsofis-filename.
note: no FM is used to read file name.
open dataset p_server for input in text MODE.
if sy-subrc <> 0.
message e303(z03_sd) with text-013.
message e300 with text-013.
endif.
clear itb_buffer.
DO.
Read dataset p_server into itb_buffer .
if sy-subrc <> 0.
Message e302 with text-012.
message e300 with text-012.
else.
Append itb_buffer to itb_temp.
endif.
enddo.
close dataset p_server.
endif.
error is dataset_cant_open.
please can solve this problem as early as possible.
thanx
raj
2006 Apr 18 9:58 AM
Raj,
Are you sure of the directory path and the file name? The error points towards the path / file name.
Regards,
Ravi
2006 Apr 18 9:59 AM
Hi raj,
1. File names, along with the full path, are CASE SENSITIVE
(in unix Os)
2. change this.
PARAMETERS : p_server LIKE /sapdmc/lsofis-filename <b>lower case.</b>
3. U can check in tcode AL11,
to get the full path.
regards,
amit m.
2006 Apr 18 10:01 AM
You have already read the file successfully. The problem is an unnecessary error message triggered at end of file.
Suppress the following line after read dataset.
message e300 with text-012.
You can replace that section with...
data w_lines type i.
describe table itb_temp lines w_lines.
write 😕 'No of lines read', w_lines.
exit.
Use the exit statement as above to break out of the DO enddo loop.
2006 Apr 18 10:02 AM
The file path should be in lower case as already specified.
If You can see the directory in the AL11, check if you have authority to access the same.(Permissions).
Regards,
Ravi
2006 Apr 18 10:10 AM
Hi,
1) Open file in application server by statement:
OPEN DATASET file_name FOR INPUT IN TEXT MODE.
2)Checking the file is opened sucessfully by
SY-SUBRC = 0
3) After checking, you can read data from file by statement:
READ DATASET file_name INTO itab.
Note: This statement should be in DO statement
4)Append data to internal table
5) Close file by statement:
CLOSE DATASET file_nameExample
DATA: BEGIN OF i_tab OCCURS 0,
text(100),
END OF i_tab,
gv_dataset1(30) VALUE /temp/testfile.txt.
OPEN DATASET gv_dataset1 FOR INPUT IN TEXT MODE.
DO.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
READ DATASET gv_dataset1 INTO i_tab.
APPEND i_tab.
CLEAR i_tab.
ENDDO.
CLOSE DATASET gv_dataset1.
Thanks
Sudheer
2006 Apr 18 10:16 AM
2006 Apr 18 10:18 AM
Hi!
May be the following code helpful to you.....
whenever u want to open a file for Reading (Input) or use the statement
Open Dataset <Datasetname> for [input or output] in [Textmode or Binary Mode] encoding Default.
for example u declare as this
Data : File_09(20) type c.
File_09 is a Dataset in other terms its a Temporary buffer in which ur file is stored in application server ...
u assign some file to this ... say
File_09 = 'C:\DATA_01.TXT'.
this file path is just an example the file however is created in Appl. Server ok...
then u open that dataset which points to the file C:\DATA_01.TXT
open Dataset File_09 for ouput in text mode encoding default .
this says that u want to open a file pointed out by or referneced by file_09 for writing something into that file in text mode. ok.
suppose u have declared a internal table itab which u want to write to the file, then use ...
loop at itab.
Transfer itab to file_09.
endloop.
then u need to close the dataset using
close dataset file_09.
suppose u want to read the file u created now use following ....
open Dataset File_09 for INPUT in text mode encoding default .
Here u r inoutting into the itab data stored in the file so input in tecxt mode mode...
to read use
do.
Read Dataset file_09 into itab2.
check sy-subrc <> 0.
exit.
enddo.
here the check condiiton is necessary to avoid infinte loop.
use sy-subrc value which is set to 4 or 8 (i dont reember exactly) when End of file which u r reading from is reached ).
here itab2 is similar to itab..
close datset file_09.
Regards,
Sangeeta.
2006 Apr 18 3:24 PM
Hi Raj,
Try the following code.
REPORT application_server.
DATA : t_data TYPE STANDARD TABLE OF tedata,
wa_data TYPE tedata.
DATA : w_message(100) TYPE c.
PARAMETERS : p_server TYPE /sapdmc/lsofis-filename LOWER CASE OBLIGATORY.
OPEN DATASET p_server FOR INPUT
IN TEXT MODE
ENCODING DEFAULT
MESSAGE w_message.
IF sy-subrc EQ 0.
DO.
READ DATASET p_server INTO wa_data-data.
IF sy-subrc EQ 0.
APPEND wa_data TO t_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_server.
ELSE.
SET CURSOR FIELD 'p_server'.
MESSAGE w_message TYPE 'E'.
ENDIF.
Regards Arun.