我的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在这里编写了一些很棒的文档。