gcl_picture TYPE REF TO cl_gui_picture.
DATA: g_pic_index TYPE sy-tabix.
FORM adicionar_imagem.
DATA: BEGIN OF lt_hextab OCCURS 1000,
line(33) TYPE x,
END OF lt_hextab.
DATA: lt_file TYPE filetable,
lt_res TYPE match_result_tab.
DATA: lw_file TYPE file_table,
lw_res TYPE match_result,
lw_wm23 TYPE ztwm_0023.
DATA: l_rc TYPE i,
l_low TYPE tvarvc-low,
l_size TYPE i,
l_len TYPE i,
l_file TYPE rlgrap-filename,
l_filename TYPE rlgrap-filename,
l_title TYPE string,
l_text TYPE c LENGTH 100.
SELECT SINGLE low
INTO l_low
FROM tvarvc
WHERE name EQ 'Z_WM_DIRETORIO_PAPELETA'.
IF sy-subrc <> 0 OR l_low IS INITIAL.
MESSAGE i000 WITH text-m06
'Z_WM_DIRETORIO_PAPELETA'.
EXIT.
ENDIF.
l_title = text-006.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = l_title
initial_directory = 'C:\'
default_extension = '*.jpg'
file_filter = '(*.jpg)|*.jpg|(*.jpeg)|*.jpeg|'
multiselection = 'X'
CHANGING
file_table = lt_file
rc = l_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3.
CHECK sy-subrc = 0 AND lt_file[] IS NOT INITIAL.
LOOP AT lt_file INTO lw_file.
l_file = lw_file.
FIND ALL OCCURRENCES OF '\' IN l_file RESULTS lt_res.
CHECK lt_res[] IS NOT INITIAL.
READ TABLE lt_res INTO lw_res
INDEX lines( lt_res ).
l_len = strlen( l_file ) - lw_res-offset.
l_filename = l_file+lw_res-offset(l_len).
lw_wm23-filename = l_filename.
SELECT COUNT( * )
FROM ztwm_0023
WHERE nuoco EQ fw_alv-nuoco
AND filename EQ lw_wm23-filename.
IF sy-subrc = 0.
MESSAGE i289 WITH l_filename fw_alv-nuoco.
EXIT.
ENDIF.
CONCATENATE text-m08 l_filename INTO l_text.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 100
text = l_text.
CLEAR lt_hextab[].
CALL FUNCTION 'WS_UPLOAD' "#EC *
EXPORTING
codepage = '8400'
filetype = 'BIN'
filename = l_file
IMPORTING
filelength = l_size
TABLES
data_tab = lt_hextab
EXCEPTIONS
OTHERS = 7.
l_file = l_low.
CONCATENATE l_file l_filename INTO l_file.
OPEN DATASET l_file FOR OUTPUT IN BINARY MODE.
IF sy-subrc <> 0.
MESSAGE i288 WITH l_file.
EXIT.
ENDIF.
LOOP AT lt_hextab.
TRANSFER lt_hextab TO l_file.
ENDLOOP.
CLOSE DATASET l_file.
CLEAR ztwm_0023.
ztwm_0023-nuoco = fw_alv-nuoco.
ztwm_0023-filefull = l_file.
ztwm_0023-filename = l_filename.
INSERT ztwm_0023.
ENDLOOP.
COMMIT WORK.
MESSAGE i290 WITH l_file.
ENDFORM. " ADIC
*&---------------------------------------------------------------------*
*& Module STATUS_9200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9200 OUTPUT.
SET PF-STATUS '9200'.
SET TITLEBAR '9200' WITH gw_alv-nuoco.
IF gcl_cont_photo IS INITIAL.
PERFORM carrega_imagens.
ENDIF.
ENDMODULE. " STATUS_9200 OUTPUT
*&---------------------------------------------------------------------*
*& Form CARREGA_IMAGENS
*&---------------------------------------------------------------------*
FORM carrega_imagens .
* Create controls
CREATE OBJECT gcl_cont_photo
EXPORTING
container_name = 'CC_PHOTO'.
CREATE OBJECT gcl_picture
EXPORTING
parent = gcl_cont_photo.
* Load the picture for the handling unit
CALL METHOD gcl_picture->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_fit.
CALL METHOD cl_gui_cfw=>flush.
PERFORM load_picture USING g_pic_index.
ENDFORM. " CARREGA_IMAGENS
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9200 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'ANT_PIC'.
CHECK g_pic_index > 1.
SUBTRACT 1 FROM g_pic_index.
PERFORM load_picture USING g_pic_index.
WHEN 'PRO_PIC'.
CHECK g_pic_index < lines( gt_wm23 ).
ADD 1 TO g_pic_index.
PERFORM load_picture USING g_pic_index.
ENDCASE.
ENDMODULE. " USER_COMMAND_9200 INPUT
*&---------------------------------------------------------------------*
*& Form LOAD_PICTURE
*&---------------------------------------------------------------------*
FORM load_picture USING f_index.
DATA: lt_data TYPE STANDARD TABLE OF x255.
DATA: l_url TYPE char255.
DATA: l_content TYPE xstring.
DATA: l_repid TYPE sy-repid,
l_pic_size TYPE i.
CHECK gcl_picture IS NOT INITIAL.
CHECK f_index > 0.
READ TABLE gt_wm23 INDEX f_index INTO gw_wm23.
* Read it from application server
OPEN DATASET gw_wm23-filefull FOR INPUT IN BINARY MODE.
IF sy-subrc <> 0.
MESSAGE i288 WITH gw_wm23-filefull.
CALL METHOD gcl_picture->clear_picture.
EXIT.
ENDIF.
READ DATASET gw_wm23-filefull INTO l_content .
CLOSE DATASET gw_wm23-filefull.
* Convert
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_content
IMPORTING
output_length = l_pic_size
TABLES
binary_tab = lt_data.
* CReate URL
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE'
subtype = 'JPG'
size = l_pic_size
lifetime = cndp_lifetime_transaction
TABLES
data = lt_data
CHANGING
url = l_url.
* Load picture from URL
gcl_picture->load_picture_from_url_async( l_url ).
ENDFORM. " LOAD_PICTURE