Arrays 从文件创建字节数组?

Arrays 从文件创建字节数组?,arrays,abap,Arrays,Abap,我的ABAP开发者正在通过一个函数向我发送文件。我试图找出是否可以在ABAP>中将文件转换为字节数组 如果这是可能的,有人有任何示例代码吗?类似的代码应该可以: data: w_line type xstring. data: t_file type table of xstring. data: w_filename type string falue 'myfile.txt'. data: w_len type i. open dataset w_filename for input in

我的ABAP开发者正在通过一个函数向我发送文件。我试图找出是否可以在ABAP>中将文件转换为字节数组


如果这是可能的,有人有任何示例代码吗?

类似的代码应该可以:

data: w_line type xstring.
data: t_file type table of xstring.
data: w_filename type string falue 'myfile.txt'.
data: w_len type i.

open dataset w_filename for input in binary mode.

read dataset w_filename into w_line length w_len.

while w_len > 0.
    append w_line to t_file.
    read dataset w_filename into w_line length w_len.
endwhile.

close dataset w_filename.

* t_file now holds the data in an internal table

有很多方法可以做到这一点,但我发现使用对象是最简单的

DATA byte_array TYPE TABLE OF raw256. "any type will work here
DATA my_file    TYPE string VALUE `C:\users\bob\file.bin`. "Absolute or relative works

CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD(
  EXPORTING
    filename = my_file
    filetype = 'BIN'
  CHANGING
    data_tab = byte_array ).
从我的经验来看,这门课非常健壮。有一系列可选参数和返回代码。SAP编写了一些很棒的文档