open dataset abap 01

DATA: MESS(60),
      FNAME(10) VALUE '/tmp'.

OPEN DATASET FNAME FOR OUTPUT MESSAGE MESS.

IF SY-SUBRC <> 0.
  WRITE: 'SY-SUBRC:', SY-SUBRC,
       / 'System Message:', MESS.
ENDIF.

If the R/3 System is ruining under UNIX, the output looks like this:

This graphic is explained in the accompanying text

The system cannot open the file, since the name you specified is that of a directory.

Example

The following program shows how the system sets the position when you open a file for writing. However, it is better programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File ).

DATA FNAME(60) VALUE 'myfile'.
DATA NUM TYPE I.

OPEN DATASET FNAME FOR OUTPUT.

DO 10 TIMES.
  NUM = NUM + 1.
  TRANSFER NUM TO FNAME.
ENDDO.

PERFORM INPUT.

OPEN DATASET FNAME FOR OUTPUT.

NUM = 0.
DO 5 TIMES.
  NUM = NUM + 10.
  TRANSFER NUM TO FNAME.
ENDDO.

PERFORM INPUT.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR OUTPUT.

NUM = 0.
DO 5 TIMES.
  NUM = NUM + 20.
  TRANSFER NUM TO FNAME.
ENDDO.

PERFORM INPUT.

FORM INPUT.
  SKIP.
  OPEN DATASET FNAME FOR INPUT.
  DO.
    READ DATASET FNAME INTO NUM.
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
    WRITE / NUM.
  ENDDO.
ENDFORM.

The output appears as follows:

1
2
3
4
5
6
7
8
9
10

10
20
30
40
50
6
7
8
9
10

20
40
60
80
100

This example performs the following steps using the file "myfile":

    • It is opened for writing
    • It is filled with 10 integers (for information about the TRANSFER statement, refer to
    Writing Data to Files )
    • It is then opened for reading. The position is reset accordingly to the beginning of the file.
    • It is read into the field NUM. For information about the READ DATASET statement, refer to
    Reading Data from Files . The values of NUM are displayed on the screen.
    • It is reopened for writing The position is reset to the beginning of the file.
    • It is filled with five integers, which overwrite the previous contents of the file.
    • It is then reopened for reading. The position is reset to the beginning of the file.
    • The file is read into the field NUM. The values of NUM are displayed on the screen.
    • It is closed (for information about the CLOSE DATASET statement, refer to
    Closing a File ).
    • It is then reopened for writing. The system deletes the existing contents of the file.
    • It is filled with 5 integers.
    • It is then opened for reading. The position is reset to the beginning of the file.
    • The file is read into the field NUM. The values of NUM are displayed on the screen
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值