下面通过一段代码介绍如何在选择画面中显示图片。
1, SMW0上载图片
Tcode:SMW0,选择Binary的选项
<img class="alignnone size-full wp-image-5025" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxNy0wNy0xMF8xNC0zNi0yOS5wbmc=.jpg" width="472" height="187" />
由于是测试,选择$TMP本地package,然后运行进入下一屏幕,
<img class="alignnone size-full wp-image-5026" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxNy0wNy0xMF8xNC0zOC01Ny5wbmc=.jpg" width="473" height="199" />
上载图片,命名为ZPIC,程序中会用来标识图片的。
<img class="alignnone size-full wp-image-5030" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxNy0wNy0xMF8xNC00OS0yNS0xLnBuZw==.jpg" width="1147" height="557" srcset="http://www.baidusap.com/wp-content/uploads/2017-07-10_14-49-25-1.png 1147w, http://www.baidusap.com/wp-content/uploads/2017-07-10_14-49-25-1-740x359.png 740w, http://www.baidusap.com/wp-content/uploads/2017-07-10_14-49-25-1-768x373.png 768w, http://www.baidusap.com/wp-content/uploads/2017-07-10_14-49-25-1-1024x497.png 1024w" sizes="(max-width: 1147px) 100vw, 1147px" />
2, 例子代码
REPORT ztest_pic_sel_screen. TYPE-POOLS cndp. *&---------------------------------------------------------------------* *& Data Declaration. *&---------------------------------------------------------------------* DATA: go_docking TYPE REF TO cl_gui_docking_container, go_htmlviewer TYPE REF TO cl_gui_html_viewer, go_picture TYPE REF TO cl_gui_picture. DATA g_url TYPE cndp_url. *&---------------------------------------------------------------------* *& SELECTION SCREEN. *&---------------------------------------------------------------------* PARAMETERS: s_matnr TYPE mara-matnr. *&---------------------------------------------------------------------* *& AT SELECTION-SCREEN OUTPUT. *&---------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. CALL FUNCTION ‘DP_PUBLISH_WWW_URL‘ EXPORTING objid = ‘ZPIC‘ lifetime = cndp_lifetime_transaction IMPORTING url = g_url EXCEPTIONS OTHERS = 1. * Load the go_picture. IF sy-subrc = 0. PERFORM frm_build_htmlviewer. CALL METHOD go_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal. CALL METHOD go_picture->load_picture_from_url_async EXPORTING url = g_url. ENDIF. *&---------------------------------------------------------------------* *& Form build_htmlviewer *&---------------------------------------------------------------------* FORM frm_build_htmlviewer . DATA: repid LIKE sy-repid. repid = sy-repid. IF go_docking IS INITIAL. CREATE OBJECT go_docking EXPORTING repid = repid dynnr = sy-dynnr side = cl_gui_docking_container=>dock_at_top extension = 80 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF go_htmlviewer IS INITIAL . CREATE OBJECT go_picture EXPORTING parent = go_docking. ENDIF . ENDIF . ENDFORM.
3, 测试运行
<img class="alignnone size-full wp-image-5032" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxNy0wNy0xMV8xMC00Ny0xMi5wbmc=.jpg" width="536" height="313" />
以上。
原文地址:https://www.cnblogs.com/datie/p/11433812.html