1, 简介
整理了一段代码,实现上载本地图片到SAP的数据库表中,并且显示在屏幕上。
其中用到了一下函数:
1, GUI_UPLOAD:上载图片文件
2, SCMS_BINARY_TO_XSTRING:将图片文件转换成xstring
3, SCMS_XSTRING_TO_BINARY:将图片xstring转换成binary格式保存到内表中
4, DP_CREATE_URL:创建得到图片的URL
5, go_pic->load_picture_from_url:根据图片URL导入
6, go_pic->set_display_mode:显示图片
2, 完整代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
REPORT ztest_upload_pic. **数据定义部分 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 zpictable. **zpictable为自定义table,设置一个主键字段,再设置一个或者多个RAWSTRING类型的字段存储图片数据 DATA: c_pic TYPE REF TO cl_gui_custom_container, go_pic TYPE REF TO cl_gui_picture. DATA: len TYPE i, url(256), resu TYPE i VALUE 123, path_string TYPE string. PARAMETERS: p_file LIKE ibipparms-path OBLIGATORY. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM select_file USING p_file. START-OF-SELECTION. PERFORM upload_pic. PERFORM show_pic. CALL SCREEN 100. FORM select_file USING p_file. CALL FUNCTION 'F4_FILENAME' IMPORTING file_name = p_file. ENDFORM. FORM upload_pic. path_string = p_file. DATA lv_content TYPE xstring. * 上载PIC文件 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-key1 = '主键字段'. wa_pic-field1 = lv_content. MODIFY zpictable FROM wa_pic. IF sy-subrc = 0 . MESSAGE '图片已经保存至数据库表' TYPE 'S'. ELSE. ENDIF. ENDFORM. FORM show_pic. CLEAR pic_tab. SELECT SINGLE * INTO wa_pic FROM zpictable WHERE key1 = '关键字段'. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = wa_pic-field1 TABLES binary_tab = pic_tab. * 创建图片URL 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 go_pic EXPORTING parent = c_pic. CALL METHOD go_pic->load_picture_from_url EXPORTING url = url IMPORTING result = resu. * 3,居中显示 CALL METHOD go_pic->set_display_mode EXPORTING display_mode = 3. ENDFORM. MODULE status_0100 OUTPUT. SET PF-STATUS '100'. ENDMODULE. MODULE user_command_0100 INPUT. CASE sy-ucomm. WHEN 'BACK'. CALL METHOD c_pic->free. * (必须释放对象,否则会出现同一屏幕上操作图片无法刷新的情况) LEAVE TO SCREEN 0. WHEN OTHERS. ENDCASE. ENDMODULE. |
屏幕100:
1 2 3 4 5 |
PROCESS BEFORE OUTPUT. MODULE status_0100. * PROCESS AFTER INPUT. MODULE user_command_0100. |
在屏幕上创建一个自定义的container:C_PIC
状态status 100,简单的就设置个BACK按钮
SE11 创建一个数据库表ZPICTABLE用来保存上载的图片文件,其中field1就是用来保存图片rawstring的字段。
3, 程序运行
选择画面输入图片文件路径,然后运行即可
然后美女就出现了。。。
以上。
但是截图的格式就无法显示,请问怎么解决这个问题啊 ?
2018-10-15 3:07 上午