如何通过abap从本地机器读取/写入文本文件?

时间:2013-12-02 14:28:55

标签: sap abap

report  try1.

class register definition.
  public section.
    methods: constructor.
class-data: read_data type pa0008-bet01,    "i tried string first, but i found this one
endclass.                                       "still doesnt work

class register implementation.
 method constructor.
  data sometext(100) value 'C:\Users\tgbtstj3\Desktop\ZzZzZz.txt'.
  open dataset sometext for input in text mode encoding default.
  do.
   read dataset sometext into read_data.
   if sy-subrc <> 0.
    exit.
   endif.
   close dataset sometext.
   write / read_data.
  enddo.
 endmethod.
endclass.

data reg type ref to register.
START-OF-SELECTION.
create object reg.

这是我的代码,我刚刚开始编程并希望制作一个小程序来学习...但我仍然坚持从我的本地机器读取txt文件而我无法继续... 错误说文件没有打开... 并且由cx_sy_file_open_mode

捕获异常

2 个答案:

答案 0 :(得分:1)

语句OPEN DATASET用于访问应用程序服务器上的文件。要访问前端,请使用类CL_GUI_FRONTEND_SERVICES的方法。例如,请查看报告GRAPHICS_IGS_ZIPPER_DEMO

答案 1 :(得分:-2)

data file(100) value '.\myfile'.
data num type string.
open dataset file for output in text mode encoding default.
close dataset file.

然后将read_data更改为:

class-data: num type string.

查找并将所有read_data更改为num。