1.建表ZTEST_PHOTO,表结构如下:
MANDT MANDT CLNT 3 0 Client
PERNR PERSNO NUMC 8 0 Personnel number
PHOTO XSTRINGVAL RAWSTRING 0 0 XString
2.程序
*&---------------------------------------------------------------------*
*& Report ZPICTURE_Display
* create a screen 100 with a container PICTURE_CONTAINER
* GuiTitle T_100
* GuiStatus S_100
*&---------------------------------------------------------------------*
REPORT zpicture_Display.
DATA : wa_ztest_photo TYPE ztest_photo,
it_ztest_photo TYPE TABLE OF ztest_photo.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_pernr FOR wa_ztest_photo-pernr NO INTERVALS .
PARAMETERS : p_disp TYPE char1 RADIOBUTTON GROUP rda1 DEFAULT 'X'
USER-COMMAND com,
p_upload TYPE char1 RADIOBUTTON GROUP rda1.
SELECTION-SCREEN END OF BLOCK b1.
IF p_disp IS NOT INITIAL.
CALL SCREEN 100.
ELSE.
DATA: lr_mime_rep TYPE REF TO if_mr_api.
DATA: lv_filename TYPE string.
DATA: lv_path TYPE string.
DATA: lv_fullpath TYPE string.
DATA: lv_content TYPE xstring.
DATA: lv_length TYPE i.
DATA: lv_rc TYPE sy-subrc.
DATA: lt_file TYPE filetable.
DATA: ls_file LIKE LINE OF lt_file.
DATA: lt_data TYPE STANDARD TABLE OF x255.
cl_gui_frontend_services=>file_open_dialog(
CHANGING
file_table = lt_file " Table Holding Selected Files
rc = lv_rc ). " Return Code, Number of Files or -1 If Error Occurred
READ TABLE lt_file INTO ls_file INDEX 1.
IF sy-subrc = 0.
lv_filename = ls_file-filename.
ENDIF.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_filename " Name of file
filetype = 'BIN'
IMPORTING
filelength = lv_length " File length
CHANGING
data_tab = lt_data " Transfer table for file contents
EXCEPTIONS
OTHERS = 19 ).
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_length
* first_line = 0
* last_line = 0
IMPORTING
buffer = lv_content
TABLES
binary_tab = lt_data
EXCEPTIONS
failed = 1
OTHERS = 2.
wa_ztest_photo-pernr = s_pernr-low.
wa_ztest_photo-photo = lv_content.
MODIFY ztest_photo FROM wa_ztest_photo .
IF sy-subrc = 0.
MESSAGE 'Successfully Uploaded' TYPE 'I' DISPLAY LIKE 'S'.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'S_100'.
SET TITLEBAR 'T_100'.
DATA: w_lines TYPE i.
TYPES pict_line(256) TYPE c.
DATA :
container TYPE REF TO cl_gui_custom_container,
editor TYPE REF TO cl_gui_textedit,
picture TYPE REF TO cl_gui_picture,
pict_tab TYPE TABLE OF pict_line,
url(255) TYPE c.
DATA: graphic_url(255).
DATA: BEGIN OF graphic_table OCCURS 0,
line(255) TYPE x,
END OF graphic_table.
DATA: l_graphic_conv TYPE i.
DATA: l_graphic_offs TYPE i.
DATA: graphic_size TYPE i.
DATA: l_graphic_xstr TYPE xstring.
.
CALL METHOD cl_gui_cfw=>flush.
CREATE OBJECT:
container EXPORTING container_name = 'PICTURE_CONTAINER',
picture EXPORTING parent = container.
* selecting the data from the table..
SELECT pernr photo FROM ztest_photo INTO CORRESPONDING FIELDS OF TABLE it_ztest_photo
WHERE pernr IN s_pernr .
READ TABLE it_ztest_photo INTO wa_ztest_photo INDEX 1.
IF sy-subrc = 0.
l_graphic_xstr = wa_ztest_photo-photo.
ENDIF.
graphic_size = XSTRLEN( l_graphic_xstr ).
l_graphic_conv = graphic_size.
l_graphic_offs = 0.
WHILE l_graphic_conv > 255.
graphic_table-line = l_graphic_xstr+l_graphic_offs(255).
APPEND graphic_table.
l_graphic_offs = l_graphic_offs + 255.
l_graphic_conv = l_graphic_conv - 255.
ENDWHILE.
graphic_table-line = l_graphic_xstr+l_graphic_offs(l_graphic_conv).
APPEND graphic_table.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE'
subtype = 'X-UNKNOWN'
size = graphic_size
lifetime = 'T'
TABLES
data = graphic_table
CHANGING
url = url.
CALL METHOD picture->load_picture_from_url
EXPORTING
url = url.
CALL METHOD picture->set_display_mode
EXPORTING
display_mode = picture->display_mode_fit_center.
ENDMODULE. " STATUS_0100 OUTPUT
阅读(745) | 评论(0) | 转发(0) |