将客户端图片保存到数据库中的方法
核心內容:
(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.
總結
以上是生活随笔為你收集整理的将客户端图片保存到数据库中的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 子屏幕selection-screen
- 下一篇: 关于oracle数据库的操作的命令