REPORT ZSAPeiros.
* Definição de tipos
TYPES:
BEGIN OF ty_graphic_table,
line(255) TYPE x,
END OF ty_graphic_table.
* Variáveis
DATA:
lv_graphic_size TYPE i,
lv_bytecount TYPE i,
lv_tdbtype LIKE stxbitmaps-tdbtype,
lv_call_mask(50) TYPE c,
lv_name_exp LIKE ibipparms-path,
lv_filename TYPE rlgrap-filename,
lt_content TYPE TABLE OF bapiconten,
lt_graphic_table TYPE TABLE OF ty_graphic_table.
* Parâmetros de tela
PARAMETERS:
p_name TYPE stxbitmaps-tdname DEFAULT 'ZSAPEIROS',
p_btype TYPE stxbitmaps-tdbtype DEFAULT 'BCOL'.
* Atribuir valor aos parâmetros
INITIALIZATION.
%_p_name_%_app_%-text = 'Logo (SE78)'.
%_p_btype_%_app_%-text = 'Cores ou P&B'.
* Executar
END-OF-SELECTION.
* Conteúdo da imagem
CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'
EXPORTING
i_object = 'GRAPHICS'
i_name = p_name
i_id = 'BMAP'
i_btype = p_btype
IMPORTING
e_bytecount = lv_bytecount
TABLES
content = lt_content
EXCEPTIONS
not_found = 1
bds_get_failed = 2
bds_no_content = 3
OTHERS = 4.
* Conversão da imagem
CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
EXPORTING
old_format = 'BDS'
new_format = 'BMP'
bitmap_file_bytecount_in = lv_bytecount
IMPORTING
bitmap_file_bytecount = lv_graphic_size
TABLES
bds_bitmap_file = lt_content
bitmap_file = lt_graphic_table
EXCEPTIONS
OTHERS = 1.
* Extenção do arquivo de saída
lv_call_mask = ',Bitmap (*.bmp),*.BMP'.
* Nome do arquivo original
lv_filename = p_name && '.bmp'.
* Popup para informar o local onde será gravado o arquivo
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = lv_filename
def_path = lv_name_exp
mask = lv_call_mask
mode = 'S'
IMPORTING
filename = lv_name_exp
EXCEPTIONS
inv_winsys = 04
no_batch = 08
selection_cancel = 12
selection_error = 16.
CHECK sy-subrc IS INITIAL.
* Nome do arquivo com o caminho informado
lv_filename = lv_name_exp.
* Download do arquivo
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
bin_filesize = lv_graphic_size
filename = lv_filename
filetype = 'BIN'
TABLES
data_tab = lt_graphic_table
EXCEPTIONS
invalid_filesize = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6.
IF sy-subrc IS INITIAL.
MESSAGE 'Download realizado com sucesso!' TYPE 'S'.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.