我很好
分类:
2009-02-03 14:28:44
核心内容:
(1)使用到两个函数模块(FM):SCMS_BINARY_TO_XSTRING 和 SCMS_XSTRING_TO_BINARY;
(2)数据库保存图片的字段设为 RAWSTRING类型(对应于ABAP数据类型XSTRING)。
一、假设场景及前提
(1)将客户端C盘下的“PIC.JPG”文件保存到表ZTPIC中;
(2)ZTPIC表中包含一个名为PICDATA,类型为RAWSTRING的字段用于保存图片内容;
(3)当需要显示的时候,将此字段的图片在Picture控件中显示出来。
以下是实现的代码:
(1)全局变量定义
types: begin of ty_pic,
pic_data(1024) type x,
end of ty_pic.
data pic_tab type table of ty_pic.
data wa_pic type ztpic.
data: c_pic type ref to cl_gui_custom_container,
pic type ref to cl_gui_picture.
data:len type i,url(256),
resu type i value 123,
path_string type string.
(2)保存(代码实现)
path_string = 'C:\PIC.jpg'.
data lv_content type xstring.
call function 'GUI_UPLOAD'
exporting
filename = path_string
filetype = 'BIN'
importing
filelength = len
tables
data_tab = pic_tab[].
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = len
importing
buffer = lv_content
tables
binary_tab = pic_tab[]
exceptions
failed = 1
others = 2.
*wa_pic其他组件的赋值略!
wa_pic-picdata = lv_content.
insert into ztpic values wa_pic.
(3)显示(代码实现)
clear pic_tab.
select single * from ztpic into wa_pic. “简单起见,假设只有一条记录
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = wa_pic-picdata
tables
binary_tab = pic_tab.
call function 'DP_CREATE_URL'
exporting
type = 'IMAGE'
subtype = 'JPG'
tables
data = pic_tab
changing
url = url.
create object c_pic
exporting
container_name = 'C_PIC'.
create object pic
exporting
parent = c_pic.
call method pic->load_picture_from_url
exporting
url = url
importing
result = resu.