SAP smartform和ALV如何使用图片 如何下载SE78上传的图片到本地
原文链接1:https://mp.weixin.qq.com/s/gb3LCoDLNhZGnpplG68cyA
原文链接2:https://mp.weixin.qq.com/s/iFFhGwFEK93QiddR1biXyA
1.如何在SMARTFORM中打印图片
在使用SmartForms进行打印单据开发时候,经常需要将公司的LOGO、公司印章、管理人员签名等一并打印,而这些打印对象都是图片,需要将这些打印对象上传到SAP服务器中,才能在SmartForms中应用。如何上传和应用这类图片,下面是具体操作步骤介绍:
1 .执行SE78事务码,按如下图操作。
上传的图片一定要是BMP或DIB格式,选择上传图片的路径,填写名字和描述,然后一直执行下去就可以了,执行成功后显示如下。
2. 在SmartForms设计时,在想要加入LOGO的地方,点击右键:创建->图形,然后在名称:ZERPLOGO,即可才打印的Form中打印出公司的LOGO或其它图形、图片。
2.如何在ALV报表中显示图片
具体操作步骤:
1 . 执行OAER事务码,按如下图操作。
Class name:PICTURES
Class type : OT
Object key:ZALV_LOGO (ALV报表程序通过这识别)
2. 填写完成点击执行按钮(或F8)运行之后,打开标准文档类型->双击屏幕,上传本地图片文件至SAP(如下图)
然后一直执行下去就可以了,执行成功后显示如下。
3 . 上传完成后,可以在ALV报表中使用了,可以使用如下function使用图片
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = git_listheader
i_logo = 'ZALV_LOGO'. " 要大写
效果如下图
4 . 最后附上上图报表的完整程序供参考学习
*&-------------------------------------------*
*& Report ZALVLOGO
*&-------------------------------------------*
REPORT ZALVLOGO.
TYPE-POOLS: slis.
*&-------------------------------------------*
* Data Decalaration
*&-------------------------------------------*
DATA: git_spfli TYPE TABLE OF spfli.
DATA: g_repid TYPEsy-repid.
DATA: git_listheader TYPE slis_t_listheader,
gwa_listheader TYPE slis_listheader.
*&-------------------------------------------*
* START-OF-SELECTION
*&-------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
SELECT * FROM spfliINTO TABLE git_spfli.
PERFORM build_alv_header.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program =g_repid
i_callback_top_of_page = 'TOP_OF_PAGE'
i_structure_name = 'SPFLI'
TABLES
t_outtab = git_spfli.
*&-------------------------------------------*
*& Form BUILD_ALV_HEADER
*&-------------------------------------------*
FORM build_alv_header .
* Type H is used to display headers i.e. big font
gwa_listheader-typ = 'H'.
gwa_listheader-info ='Flight Details'.
APPEND gwa_listheader TOgit_listheader.
CLEAR gwa_listheader.
* Type S is used to display key and value pairs
gwa_listheader-typ = 'S'.
gwa_listheader-key = 'Date :' .
CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO gwa_listheader-info
SEPARATED BY '/'.
APPEND gwa_listheader TOgit_listheader.
CLEAR gwa_listheader.
* Type A is used to display italic font
gwa_listheader-typ = 'A'.
gwa_listheader-key = 'Date :' .
gwa_listheader-info ='SAP ALV Report'.
APPEND gwa_listheader TOgit_listheader.
CLEAR gwa_listheader.
ENDFORM. " BUILD_ALV_HEADER
*&-------------------------------------------*
*& Form top_of_page
*&-------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = git_listheader
i_logo = 'ZALV_LOGO'. "LOGO object key 大写
ENDFORM. "top_of_page
3 . 如何下载SE78上传的图片到本地
在使用Scripfrom或SmartForms工具开发凭证单据打印的时候,经常会遇到需要打印一些相关的图片到单据上的需求,比如:公司的LOGO,公司的印章、领导签名图片等。
在SAP系统单据打印开发中,我们还可能会遇到这样需求,比如:某些己开发的打印单据需要更换公司LOGO、领导签名图片等,我们可能需要下载原来图片进行修改,参考设计等
但SAP好像并没有标准的事务码可以方便下载已上传至SAP服务器上的图片,通常的解决方法写一个专门下载这类图片的简单程序来处理。
比如下面这个程序是网络上被转载较广的专门用于下载SE78上传图片的程序,操作界面如下:
输入图片名称和下载到电脑的本地路径,点击执行即可完成所需图片的下载。
源代码如下仅供参考:
REPORT Ydownload.
DATA : g_bytecount TYPE i,
g_content TYPE STANDARD TABLE OF
bapiconten INITIAL SIZE 0,
g_bitmap_file_bytecount TYPE i,
g_file_name TYPE string,
BEGIN OF g_bitmap_file OCCURS 0,
line(255) TYPE x,
END OF g_bitmap_file,
l_bitmaps TYPE TABLE OF stxbitmaps WITH HEADER LINE,
lit_scrfields TYPE TABLE OF dynpread WITH HEADER LINE.
PARAMETER: p_image LIKE stxbitmaps-tdname, "需要下载的图片名称
* DEFAULT 'ENJOY', "name of the image
p_file LIKE ibipparms-path. "下载到PC的路径
* DEFAULT 'H:\My Documents\enjoy.bmp'.
" Download File path
*F4 help to get file path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
*F4 help search for image files
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_image.
CALL FUNCTION 'SAPSCRIPT_SEARCH_GRAPHIC_BDS'
EXPORTING
selection_screen = 'X'
select_entry = 'X'
selection_show = 'X'
IMPORTING
e_name = p_image
TABLES
t_selections = l_bitmaps
EXCEPTIONS
nothing_found = 1
selection_canceled = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
START-OF-SELECTION.
MOVE p_file TO g_file_name.
*Get graphics to BDS
CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'
EXPORTING
i_object = 'GRAPHICS'
i_name = p_image
i_id = 'BMAP'
i_btype = 'BCOL'
IMPORTING
e_bytecount = g_bytecount
TABLES
content = g_content
EXCEPTIONS
not_found = 1
bds_get_failed = 2
bds_no_content = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE i208(00) WITH 'Image does not exists.'(000).
ENDIF.
IF NOT g_content[] IS INITIAL.
*Convert to BITMAP
CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
EXPORTING
old_format = 'BDS'
new_format = 'BMP'
bitmap_file_bytecount_in = g_bytecount
IMPORTING
bitmap_file_bytecount = g_bitmap_file_bytecount
TABLES
bds_bitmap_file = g_content
bitmap_file = g_bitmap_file
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*Download to PC
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = g_bitmap_file_bytecount
filename = g_file_name
filetype = 'BIN'
TABLES
data_tab = g_bitmap_file
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.