DATA FNAME(60) VALUE 'myfile'.
DATA NUM TYPE I.
OPEN DATASET FNAME FOR OUTPUT.
DO 5 TIMES.
NUM = NUM + 1.
TRANSFER NUM TO FNAME.
ENDDO.
OPEN DATASET FNAME FOR INPUT.
OPEN DATASET FNAME FOR APPENDING.
NUM = 0.
DO 5 TIMES.
NUM = NUM + 10.
TRANSFER NUM TO FNAME.
ENDDO.
OPEN DATASET FNAME FOR INPUT.
DO.
READ DATASET FNAME INTO NUM.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE / NUM.
ENDDO.
The output appears as follows:
1
2
3
4
5
10
20
30
40
50
This example opens the file "myfile" for write access and fills it with the five integers 1-5 (for further information about the TRANSFER statement, refer to Writing Data to Files ). The next OPEN DATASET statement resets the position to the beginning of the file. Then, the file is opened for appending data (the position is set to the end of the file). Five integers between 10 and 50 are written into the file. Finally, the program reads the contents of the file, and displays them on the screen.
本文介绍了一个文件操作的例子,包括打开文件进行写入、追加数据,以及读取并显示文件内容的过程。通过这个例子,读者可以了解到如何使用TRANSFER语句进行数据的写入。
550

被折叠的 条评论
为什么被折叠?



