04-12-2006 6:24 AM
hi ,i need to write a file at aapliationserver can any one help me in this topic.
Thanks
04-12-2006 6:31 AM
Vicky,
Look at the following statements.
OPEN DATASET
TRANSFER
CLOSE DATASET
Regards,
Ravi
Note : Please mark the helpful answers
04-12-2006 6:36 AM
Hi
Good
Use this line in your report as per your use.
Reading and Writing a text file from and to the application server
sy-subrc = 0 Record read from file
sy-subrc = 4 End of file reached
data: w_dataset1(27) value '/var/textfile.txt',
w_dataset2(27) value '/var/outfile.txt'.
data:begin of itab1 occurs 0, "Text file format
matnr(18), "MATERIAL NUMBER
bwkrs(4), "PLANT
end of itab1.
Thanks
mrutyunjaya Tripathy
04-12-2006 6:42 AM
Take a look at this example.
The following program shows how you can write internal tables into a file:
DATA FNAME(60) VALUE 'myfile'.
TYPES: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
TYPES ITAB TYPE LINE OCCURS 10.
DATA: LIN TYPE LINE,
TAB TYPE ITAB.
DO 5 TIMES.
LIN-COL1 = SY-INDEX.
LIN-COL2 = SY-INDEX ** 2.
APPEND LIN TO TAB.
ENDDO.
OPEN DATASET FNAME FOR OUTPUT.
LOOP AT TAB INTO LIN.
TRANSFER LIN TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT.
DO.
READ DATASET FNAME INTO LIN.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE: / LIN-COL1, LIN-COL2.
ENDDO.
CLOSE DATASET FNAME.
Regards,
Ravi
Note :Please mark the helpful answers
04-12-2006 11:49 AM
hi
1) OPEN
open dataset 'Filename' for { input / output / append } in { text / binary } mode
*------- for ur case
open dataset 'Filename' for input in text mode.
*----OS is different use Binary mode
2) WRITE
loop at itab.
Transfer itab to 'Filename'. " statement to transfer
endloop.
*----if all the fields are char it will work fine.
*----if some of the field is numeric then you have convet every thing into char then transfer
*----for that concatenate every field into in one field and the transfer.( Before concatenation convert everything into cahr).
*----Decide the separator when u concatenate every thing into one field .
3) CLOSE
Close dataset 'Filename'.
Mark helpfull answers
Regards
Manoj b Gupta
04-12-2006 12:05 PM
Hi,
To deal with files on application server there are 4 statements
OPEN DATASET
CLOSE DATASET
READ DATASET
TRANSFER
the following program part is creating a file in application server and then transfers data to it and read it back again at last.
data: file type string value 'empdb.dat'.
TYPES: begin of employee,
empid type zemp8-empid,
name type zemp8-name,
desig type zemp8-desig,
number type zemp8-number1,
status type zemp8-status,
end of employee.
data: employee_wa type employee,
employee_tab like standard table of employee_wa.
open dataset file for output in binary mode.
employee_wa-empid = '116942'.
employee_wa-name = 'Anand'.
employee_wa-desig = 'PA'.
employee_wa-number = 1000.
transfer employee_wa to file.
employee_wa-empid = '127896'.
employee_wa-name = 'Anubhuti'.
employee_wa-desig = 'A'.
employee_wa-number = 2000.
transfer employee_wa to file.
close dataset file.
clear employee_wa.
open dataset file for input in binary mode.
do.
read dataset file into employee_wa.
if sy-subrc = 0.
append employee_wa to employee_tab.
else.
exit.
endif.
enddo.
delete dataset file.
close dataset file.