本文主要是介绍【SAP ABAP学习资料】通过RFC接口上传图片至SAP 图片格式转换 图片大小调整,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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_16using p_filename type rlgrap-filenamep_name type stxbitmaps-tdnamep_object type stxbitmaps-tdobjectp_id type stxbitmaps-tdidp_btype type stxbitmaps-tdbtypep_format type cp_title like bds_descriptionp_resident type stxbitmaps-residentp_autoheight type stxbitmaps-autoheightp_bmcomp type stxbitmaps-bmcompp_bytecount type ip_bitmap "图片的16进制数据changing p_docid type stxbitmaps-docidp_resolution type stxbitmaps-resolutionp_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 conversioncall function 'SAPSCRIPT_CONVERT_BITMAP_BDS'exportingcolor = l_colorformat = p_formatresident = p_residentbitmap_bytecount = l_bytecountcompress_bitmap = p_bmcompimportingwidth_tw = l_width_twheight_tw = l_height_twwidth_pix = l_width_pixheight_pix = l_height_pixdpi = p_resolutionbds_bytecount = l_bds_bytecounttablesbitmap_file = l_bitmapbitmap_file_bds = l_bds_contentexceptionsformat_not_supported = 1no_bmp_file = 2bmperr_invalid_format = 3bmperr_no_colortable = 4bmperr_unsup_compression = 5bmperr_corrupt_rle_data = 6others = 7.if sy-subrc <> 0.perform dequeue_graphic using p_objectp_namep_idp_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 BDScreate 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 newwa_bds_signature-doc_count = '1'.append wa_bds_signature to l_bds_signature.call method l_bds_object->create_with_tableexportingclassname = c_bds_classnameclasstype = c_bds_classtypecomponents = l_bds_componentscontent = l_bds_contentchangingsignature = l_bds_signatureobject_key = l_object_keyexceptionsothers = 1.if sy-subrc <> 0.perform dequeue_graphic using p_objectp_namep_idp_btype.
* message e285 with p_name 'BDS'.p_type = 'E'.endif.read table l_bds_signature index 1 into wa_bds_signaturetransporting doc_id.if sy-subrc = 0.p_docid = wa_bds_signature-doc_id.else.perform dequeue_graphic using p_objectp_namep_idp_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_stxbitmapswhere tdobject = p_objectand tdid = p_idand tdname = p_nameand tdbtype = p_btype.select single tabname from bds_locl into l_tabwhere classname = c_bds_classnameand classtype = c_bds_classtype.if sy-subrc = 0.select single object_key from (l_tab) into l_object_keywhere loio_id = wa_stxbitmaps-docid+10(32)and classname = c_bds_classnameand classtype = c_bds_classtype.endif.
******** read object_key end ********************call method l_bds_object->update_with_tableexportingclassname = c_bds_classnameclasstype = c_bds_classtypeobject_key = l_object_keydoc_id = p_dociddoc_ver_no = '1'doc_var_id = '1'changingcomponents = l_bds_componentscontent = l_bds_contentexceptionsnothing_found = 1others = 2.if sy-subrc = 1. " inconsistency STXBITMAPS - BDS; repeat check inwa_bds_signature-doc_count = '1'.append wa_bds_signature to l_bds_signature.call method l_bds_object->create_with_tableexportingclassname = c_bds_classnameclasstype = c_bds_classtypecomponents = l_bds_componentscontent = l_bds_contentchangingsignature = l_bds_signatureobject_key = l_object_keyexceptionsothers = 1.if sy-subrc <> 0.perform dequeue_graphic using p_objectp_namep_idp_btype.
* message e285 with p_name 'BDS'.p_type = 'E'.endif.read table l_bds_signature index 1 into wa_bds_signaturetransporting doc_id.if sy-subrc = 0.p_docid = wa_bds_signature-doc_id.else.perform dequeue_graphic using p_objectp_namep_idp_btype.
* message e285 with p_name 'BDS'.p_type = 'E'.endif.elseif sy-subrc = 2.perform dequeue_graphic using p_objectp_namep_idp_btype.
* message e285 with p_name 'BDS'.p_type = 'E'.endif.endif.* Save bitmap header in STXBITPMAPSwa_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 attributeswa_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_propertiesexportingclassname = c_bds_classnameclasstype = c_bds_classtypeobject_key = l_object_keydoc_id = p_dociddoc_ver_no = '1'doc_var_id = '1'changingproperties = l_bds_propertiesexceptionsothers = 1.perform dequeue_graphic using p_objectp_namep_idp_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'EXPORTINGINPUT = IN_MATNRIMPORTINGOUTPUT = 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*100CALL METHOD GO_IMAGE_PROCESSOR->GET_INFOEXPORTINGIV_HANDLE = G_HANDLEIMPORTINGEV_MIMETYPE = L_TYPEEV_XRES = L_XRESEV_YRES = L_YRESEV_XDPI = L_XDPIEV_YDPI = L_YDPIEV_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->RESIZEEXPORTINGIV_HANDLE = G_HANDLEIV_XRES = L_YRESIV_YRES = L_YRES."转为BMP格式CALL METHOD GO_IMAGE_PROCESSOR->CONVERTEXPORTINGIV_HANDLE = G_HANDLEIV_FORMAT = 'image/x-ms-bmp'."取压缩后的图片CALL METHOD GO_IMAGE_PROCESSOR->GET_IMAGEEXPORTINGIV_HANDLE = G_HANDLERECEIVINGRV_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'EXPORTINGBUFFER = G_BUFFER_NEW
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =TABLESBINARY_TAB = P_BITMAP.PERFORM IMPORT_BITMAP_BDS_16 IN PROGRAM SAPLSTXBITMAPSUSING 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_BYTECOUNTP_BITMAP[] "图片16进制数据CHANGING P_DOCID "文档IDP_RESOLUTIONE_TYPE. "分辨率IF E_TYPE = 'E'.E_MESSAGE = '图片上传失败!'.ELSE.E_TYPE = 'S'.E_MESSAGE = '成功!'.ENDIF.
3.调用RFC接口,上传图片
完成上面两步后,产品库只需要将图片转成16进制,调用SAP 发布的RFC接口就可以将图片上传同步至SAP。
SAP samrtforms打印图片 可看文章开头链接地址
这篇关于【SAP ABAP学习资料】通过RFC接口上传图片至SAP 图片格式转换 图片大小调整的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!