Extract and Download BMAP Graphics in SAP with ABAP Sample Code

tree 200795 1280 e1478961039674

Extract BMAP Graphics from SE78 to Local : This is the ABAP program to extract SAP Graphics and save them in local.

Extract BMAP Graphics from SAP to Local Algorithm

In order to extract BMAP Graphics from SAP to local, step-by-step guide will be:

  • Get binary data from SAP BDS for specific graphics image
  • Convert graphics in BDS file format to BMP bitmap image format
  • Downlaod the file

ABAP Program to extract SAP Graphics to local

Download SapScript Graphis: Selection Screen

The first part is the selection selection:

SELECTION-SCREEN: BEGIN OF BLOCK sel WITH FRAME TITLE text-000.

PARAMETERS: pa_image LIKE rstxt-tdname.

" Select 
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 30.
PARAMETERS: bw RADIOBUTTON GROUP icol DEFAULT 'X'.
SELECTION-SCREEN COMMENT 35(30) text-001.
SELECTION-SCREEN END OF LINE.

" Select Color / Gray
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 30.
PARAMETERS: color RADIOBUTTON GROUP icol.
SELECTION-SCREEN COMMENT 35(30) text-002.
SELECTION-SCREEN END OF LINE.

" End of the selection block 
SELECTION-SCREEN: END OF BLOCK sel.

Extrand and Download SAP Graphics Processing

CHECK pa_image IS NOT INITIAL.

DATA :
 lv_bytecount TYPE i,
 lv_tdbtype LIKE stxbitmaps-tdbtype,
 lv_content TYPE STANDARD TABLE OF bapiconten INITIAL SIZE 0.

DATA: graphic_size TYPE i.

DATA:
BEGIN OF graphic_table OCCURS 0,
 line(255) TYPE x,
END OF graphic_table.

DATA: lv_export_file_name TYPE RLGRAP-FILENAME.

CONCATENATE 'u:\' pa_image '.bmp' INTO lv_export_file_name.


IF bw EQ 'X'.
 lv_tdbtype = 'BMON'. " Black and White Bitmap Image
ELSE.
 lv_tdbtype = 'BCOL'. " Color Bitmap Image
ENDIF.


*** get binary data from SAP BDS for specific graphics image
CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'
 EXPORTING
  i_object = 'GRAPHICS' " STXBITMAPS-TDOBJECT
  i_name = pa_image " STXBITMAPS-TDNAME
  i_id = 'BMAP' " STXBITMAPS-TDID
  i_btype = lv_tdbtype " STXBITMAPS-TDBTYPE
 IMPORTING
  e_bytecount = lv_bytecount " I
 TABLES
  content = lv_content " SBDST_CONTENT
 EXCEPTIONS
  not_found = 1
  bds_get_failed = 2
  bds_no_content = 3
  OTHERS = 4.

CHECK sy-subrc IS INITIAL.



*** convert graphics in BDS file format to BMP bitmap image format
CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
 EXPORTING
  old_format = 'BDS' " source image file type
  new_format = 'BMP' " target image file type => .bmp
  bitmap_file_bytecount_in = lv_bytecount
 IMPORTING
  bitmap_file_bytecount = graphic_size
 TABLES
  bitmap_file = graphic_table
  bds_bitmap_file = lv_content " SBDST_CONTENT
 EXCEPTIONS
  OTHERS = 1.

CHECK sy-subrc IS INITIAL.


CALL FUNCTION 'WS_DOWNLOAD'
 EXPORTING
  bin_filesize = graphic_size
  filename = lv_export_file_name " 'u:\export.bmp'
  filetype = 'BIN'
 TABLES
  data_tab = 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 <> 0.
 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

All credit go to kodyaz

Learn also how to do the?Migrating BDS Graphics into the MIME Repository