日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

将客户端图片保存到数据库中的方法

發布時間:2025/3/20 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 将客户端图片保存到数据库中的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

核心內容:

(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.


總結

以上是生活随笔為你收集整理的将客户端图片保存到数据库中的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。