SAP图片相关:
链接: 【SAP ABAP学习资料】图片上传SAP
链接: 【SAP ABAP学习资料】屏幕图片预览
链接: 【SAP ABAP学习资料】smartforms打印图片,动态打印图片
需求:
SAP上传图片只能本地电脑选择图片通过SE78或PERFORM IMPORT_BITMAP_BDS上传,现产品有专门的产品库系统管理,产品信息全部在产品库维护,要求用户上传在产品库的图片能同步至SAP,SAP打印合同能带出来图片信息。
解决方案
研究SAP图片上传发现,SAP系统图片保存数据为16进制数据,IMPORT_BITMAP_BDS方法先将本地链接地址的图片信息转成16进制数据,再保存到SAP数据表。
我们可以跳过转换步骤,直接上传16进制数据保存至SAP数据库,这样产品库图片可以直接调用RFC接口上传图片
功能实现
1.重写import_bitmap_bds方法
(包含文件LSTXBITMAPSF05)
可以将import_bitmap_bds复制出来重写,我这里是直接在包含文件下创建了隐式增强
form import_bitmap_bds_16
using p_filename type rlgrap-filename
p_name type stxbitmaps-tdname
p_object type stxbitmaps-tdobject
p_id type stxbitmaps-tdid
p_btype type stxbitmaps-tdbtype
p_format type c
p_title like bds_description
p_resident type stxbitmaps-resident
p_autoheight type stxbitmaps-autoheight
p_bmcomp type stxbitmaps-bmcomp
p_bytecount type i
p_bitmap "图片的16进制数据
changing p_docid type stxbitmaps-docid
p_resolution type stxbitmaps-resolution
p_type type sy-msgty.
data: l_object_key type sbdst_object_key.
data: l_tab type ddobjname.
data: begin of l_bitmap occurs 0,
l(64) type x,
end of l_bitmap.
data: l_filename type string,
l_bytecount type i,
l_bds_bytecount type i.
data: l_color(1) type c,
l_width_tw type stxbitmaps-widthtw,
l_height_tw type stxbitmaps-heighttw,
l_width_pix type stxbitmaps-widthpix,
l_height_pix type stxbitmaps-heightpix.
data: l_bds_object type ref to cl_bds_document_set,
l_bds_content type sbdst_content,
l_bds_components type sbdst_components,
wa_bds_components type line of sbdst_components,
l_bds_signature type sbdst_signature,
wa_bds_signature type line of sbdst_signature,
l_bds_properties type sbdst_properties,
wa_bds_properties type line of sbdst_properties.
data wa_stxbitmaps type stxbitmaps.
MOVE-CORRESPONDING p_bitmap to l_bitmap[].
l_bytecount = p_bytecount.
if p_btype = c_bmon.
l_color = c_false.
else.
l_color = c_true.
endif.
* Bitmap conversion
call function 'SAPSCRIPT_CONVERT_BITMAP_BDS'
exporting
color = l_color
format = p_format
resident = p_resident
bitmap_bytecount = l_bytecount
compress_bitmap = p_bmcomp
importing
width_tw = l_width_tw
height_tw = l_height_tw
width_pix = l_width_pix
height_pix = l_height_pix
dpi = p_resolution
bds_bytecount = l_bds_bytecount
tables
bitmap_file = l_bitmap
bitmap_file_bds = l_bds_content
exceptions
format_not_supported = 1
no_bmp_file = 2
bmperr_invalid_format = 3
bmperr_no_colortable = 4
bmperr_unsup_compression = 5
bmperr_corrupt_rle_data = 6
others = 7.
if sy-subrc <> 0.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
* raising conversion_failed.
p_type = 'E'.
endif.
* Save bitmap in BDS
create object l_bds_object.
wa_bds_components-doc_count = '1'.
wa_bds_components-comp_count = '1'.
wa_bds_components-mimetype = c_bds_mimetype.
wa_bds_components-comp_size = l_bds_bytecount.
append wa_bds_components to l_bds_components.
if p_docid is initial. " graphic is new
wa_bds_signature-doc_count = '1'.
append wa_bds_signature to l_bds_signature.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
if sy-subrc <> 0.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
* message e285 with p_name 'BDS'.
p_type = 'E'.
endif.
read table l_bds_signature index 1 into wa_bds_signature
transporting doc_id.
if sy-subrc = 0.
p_docid = wa_bds_signature-doc_id.
else.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
* message e285 with p_name 'BDS'.
p_type = 'E'.
endif.
else. " graphic already exists
********* read object_key for faster access *****
clear l_object_key.
select single * from stxbitmaps into wa_stxbitmaps
where tdobject = p_object
and tdid = p_id
and tdname = p_name
and tdbtype = p_btype.
select single tabname from bds_locl into l_tab
where classname = c_bds_classname
and classtype = c_bds_classtype.
if sy-subrc = 0.
select single object_key from (l_tab) into l_object_key
where loio_id = wa_stxbitmaps-docid+10(32)
and classname = c_bds_classname
and classtype = c_bds_classtype.
endif.
******** read object_key end ********************
call method l_bds_object->update_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = p_docid
doc_ver_no = '1'
doc_var_id = '1'
changing
components = l_bds_components
content = l_bds_content
exceptions
nothing_found = 1
others = 2.
if sy-subrc = 1. " inconsistency STXBITMAPS - BDS; repeat check in
wa_bds_signature-doc_count = '1'.
append wa_bds_signature to l_bds_signature.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
if sy-subrc <> 0.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
* message e285 with p_name 'BDS'.
p_type = 'E'.
endif.
read table l_bds_signature index 1 into wa_bds_signature
transporting doc_id.
if sy-subrc = 0.
p_docid = wa_bds_signature-doc_id.
else.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
* message e285 with p_name 'BDS'.
p_type = 'E'.
endif.
elseif sy-subrc = 2.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
* message e285 with p_name 'BDS'.
p_type = 'E'.
endif.
endif.
* Save bitmap header in STXBITPMAPS
wa_stxbitmaps-tdname = p_name.
wa_stxbitmaps-tdobject = p_object.
wa_stxbitmaps-tdid = p_id.
wa_stxbitmaps-tdbtype = p_btype.
wa_stxbitmaps-docid = p_docid.
wa_stxbitmaps-widthpix = l_width_pix.
wa_stxbitmaps-heightpix = l_height_pix.
wa_stxbitmaps-widthtw = l_width_tw.
wa_stxbitmaps-heighttw = l_height_tw.
wa_stxbitmaps-resolution = p_resolution.
wa_stxbitmaps-resident = p_resident.
wa_stxbitmaps-autoheight = p_autoheight.
wa_stxbitmaps-bmcomp = p_bmcomp.
insert into stxbitmaps values wa_stxbitmaps.
if sy-subrc <> 0.
update stxbitmaps from wa_stxbitmaps.
if sy-subrc <> 0.
* message e285 with p_name 'STXBITMAPS'.
p_type = 'E'.
endif.
endif.
* Set description in BDS attributes
wa_bds_properties-prop_name = 'DESCRIPTION'.
wa_bds_properties-prop_value = p_title.
append wa_bds_properties to l_bds_properties.
call method l_bds_object->change_properties
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = p_docid
doc_ver_no = '1'
doc_var_id = '1'
changing
properties = l_bds_properties
exceptions
others = 1.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endform.
2.创建RFC函数
SAP只支持BMP格式图片上传,而且smartforms图片打印不支持自适应大小,所以需要在接口里面转换上传的图片格式,裁剪图片大小后再上传至SAP
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IN_MATNR) TYPE MATNR OPTIONAL
*" VALUE(IN_PICTURE) TYPE STRING OPTIONAL
*" EXPORTING
*" VALUE(E_TYPE) TYPE SY-MSGTY
*" VALUE(E_MESSAGE) TYPE STRING
*"----------------------------------------------------------------------
IF IN_MATNR IS INITIAL OR IN_PICTURE IS INITIAL.
E_TYPE = 'E'.
E_MESSAGE = '参数不完整,图片上传失败!'.
RETURN.
ENDIF.
IN_PICTURE = TO_UPPER( IN_PICTURE ).
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = IN_MATNR
IMPORTING
OUTPUT = IN_MATNR.
DATA: GO_IMAGE_PROCESSOR TYPE REF TO CL_FXS_IMAGE_PROCESSOR,
G_HANDLE TYPE I.
DATA:G_BUFFER_OLD TYPE XSTRING,
G_BUFFER_NEW TYPE XSTRING.
DATA: L_TYPE TYPE STRING,
L_XRES TYPE I,
L_YRES TYPE I,
L_XDPI TYPE I,
L_YDPI TYPE I,
L_BITDEPTH TYPE I.
G_BUFFER_OLD = IN_PICTURE.
CREATE OBJECT GO_IMAGE_PROCESSOR.
"添加到IMAGE_PROCESSOR中
G_HANDLE = GO_IMAGE_PROCESSOR->ADD_IMAGE( IV_DATA = G_BUFFER_OLD IV_IMAGE_NAME = '456' ).
"尺寸缩小至100*100
CALL METHOD GO_IMAGE_PROCESSOR->GET_INFO
EXPORTING
IV_HANDLE = G_HANDLE
IMPORTING
EV_MIMETYPE = L_TYPE
EV_XRES = L_XRES
EV_YRES = L_YRES
EV_XDPI = L_XDPI
EV_YDPI = L_YDPI
EV_BITDEPTH = L_BITDEPTH.
IF L_XRES > L_YRES.
L_YRES = L_YRES / L_XRES / 100.
L_XRES = 100.
ELSE.
L_XRES = L_XRES / L_YRES / 100.
L_YRES = 100.
ENDIF.
"压缩图片
CALL METHOD GO_IMAGE_PROCESSOR->RESIZE
EXPORTING
IV_HANDLE = G_HANDLE
IV_XRES = L_YRES
IV_YRES = L_YRES.
"转为BMP格式
CALL METHOD GO_IMAGE_PROCESSOR->CONVERT
EXPORTING
IV_HANDLE = G_HANDLE
IV_FORMAT = 'image/x-ms-bmp'.
"取压缩后的图片
CALL METHOD GO_IMAGE_PROCESSOR->GET_IMAGE
EXPORTING
IV_HANDLE = G_HANDLE
RECEIVING
RV_XSTRING = G_BUFFER_NEW.
DATA: BEGIN OF P_BITMAP OCCURS 0,
l(64) TYPE X,
END OF P_BITMAP.
DATA: P_FILENAME TYPE RLGRAP-FILENAME,
P_NAME TYPE STXBITMAPS-TDNAME,
P_TITLE LIKE BAPISIGNAT-PROP_VALUE,
P_DOCID TYPE STXBITMAPS-DOCID,
P_RESOLUTION TYPE STXBITMAPS-RESOLUTION,
P_BYTECOUNT TYPE I.
"上传bmp图片
CLEAR:P_FILENAME,P_NAME,P_DOCID,P_RESOLUTION.
P_FILENAME = ''.
P_NAME = IN_MATNR.
P_TITLE = IN_MATNR.
P_BYTECOUNT = XSTRLEN( G_BUFFER_NEW ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = G_BUFFER_NEW
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =
TABLES
BINARY_TAB = P_BITMAP.
PERFORM IMPORT_BITMAP_BDS_16 IN PROGRAM SAPLSTXBITMAPS
USING P_FILENAME "文件路径
P_NAME "p_name "名字
'GRAPHICS'"p_object "对象 固定为 GRAPHIC
'BMAP'"p_id "ID 固定为 BMAP
'BCOL'"'BMON'"p_btype "颜色模式 BMON黑白 BCOL彩色
'BMP'"p_format "BMP 格式
P_TITLE"description "描述
''"p_resident "依照打印请求驻留在打印机内存中 X 驻留
'X'"p_autoheight "自动高度
''"p_bmcomp "是否压缩
P_BYTECOUNT
P_BITMAP[] "图片16进制数据
CHANGING P_DOCID "文档ID
P_RESOLUTION
E_TYPE. "分辨率
IF E_TYPE = 'E'.
E_MESSAGE = '图片上传失败!'.
ELSE.
E_TYPE = 'S'.
E_MESSAGE = '成功!'.
ENDIF.
3.调用RFC接口,上传图片
完成上面两步后,产品库只需要将图片转成16进制,调用SAP 发布的RFC接口就可以将图片上传同步至SAP。
SAP samrtforms打印图片 可看文章开头链接地址