Skip to Content
You may wonder that this is a very weird blog…But you know me…I love weird things LOL  What we need first is a Dynpro screen with a Custom Control named *PICTURE* attached to it. LIKE LINE OF graphic_table.  *&———————————————————- &* *&      START-OF-SELECTION                                   &* *&———————————————————- &* START-OF-SELECTION.   CALL SCREEN 100.  *&———————————————————- * *&      Module  STATUS_0100  OUTPUT                          * *&———————————————————- * MODULE status_0100 OUTPUT.   PERFORM load_image. ENDMODULE.                 ” STATUS_0100  OUTPUT  *———————————————————– * *       FORM LOAD_IMAGE                                      * *———————————————————– * FORM load_image.    CREATE OBJECT: container1 EXPORTING container_name = ‘PICTURE’,                  picture EXPORTING parent = container1.    CALL FUNCTION ‘SAPSCRIPT_GET_GRAPHIC_BDS’     EXPORTING       i_object       = ‘GRAPHICS’       i_name         = ‘ENJOY’       i_id           = ‘BMAP’       i_btype        = ‘BCOL’     IMPORTING       e_bytecount    = l_bytecount     TABLES       content        = l_content     EXCEPTIONS       not_found      = 1       bds_get_failed = 2       bds_no_content = 3       OTHERS         = 4.    CALL FUNCTION ‘SAPSCRIPT_CONVERT_BITMAP’     EXPORTING       old_format               = ‘BDS’       new_format               = ‘BMP’       bitmap_file_bytecount_in = l_bytecount     IMPORTING       bitmap_file_bytecount    = graphic_size     TABLES       bds_bitmap_file          = l_content       bitmap_file              = graphic_table     EXCEPTIONS       OTHERS                   = 1.    DESCRIBE TABLE graphic_table LINES lines.    lines = lines.   w_counter = lines – 1.    read table graphic_table index 1.   move graphic_table-line to graphic_table_new-line.   append graphic_table_new.    DO lines TIMES.     READ TABLE graphic_table INDEX w_counter.     MOVE graphic_table-line TO in_line.     PERFORM reverse_string USING in_line                            CHANGING line.     MOVE line TO graphic_table_new-line.     APPEND graphic_table_new.     CLEAR line.     w_counter = w_counter – 1.   ENDDO.    CALL FUNCTION ‘DP_CREATE_URL’     EXPORTING       type    = ‘IMAGE’       subtype = ‘BMP’     TABLES       data    = graphic_table_new     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.  ENDFORM.                    “LOAD_IMAGE  *———————————————————– * *      Form  REVERSE_STRING                                  * *———————————————————– * FORM reverse_string USING p_line CHANGING p_outline.    DATA: long TYPE i,         w_counter TYPE i.    long = STRLEN( p_line ).   w_counter = long – 1.    DO long TIMES.     CONCATENATE p_outline p_line+w_counter(1)     INTO p_outline.     w_counter = w_counter – 1.   ENDDO.  ENDFORM.                    “REVERSE_STRING   If you run this program, without doing any harm to the original picture…Your going to get this…imageIf you harm the image, your going to end with this…imageAs you can see…I actually could reverse the image…But the color looks like a mess…So…Can you fix this? Can you improve the program to get new image filters? Sounds like a little challenge to me -:)  *————————————— UPDATE————————————— *    I recieved a mail from one of my SDN heroes Mr. Thomas Jung  (https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=5%2bhlk9c3p0q%3d) a couple of days ago…Thomas took my challenge and showed me that I was completely wrong…Image processing can be done in ABAP…He kindly send me this awesome code… LIKE LINE OF graphic_table.  *&———————————————————- &* *&      START-OF-SELECTION                                   &* *&———————————————————- &* START-OF-SELECTION.   CALL SCREEN 100.  *&———————————————————- * *&      Module  STATUS_0100  OUTPUT                          * *&———————————————————- * MODULE status_0100 OUTPUT.   PERFORM load_image. ENDMODULE.                 ” STATUS_0100  OUTPUT  *———————————————————– * *       FORM LOAD_IMAGE                                      * *———————————————————– * FORM load_image.    CREATE  OBJECT: container1 EXPORTING  container_name = ‘PICTURE’ ,                    picture EXPORTING  parent = container1.    CALL FUNCTION ‘SAPSCRIPT_GET_GRAPHIC_BDS’     EXPORTING       i_object       = ‘GRAPHICS’       i_name         = ‘ENJOY’       i_id           = ‘BMAP’       i_btype        = ‘BCOL’     IMPORTING       e_bytecount    = l_bytecount     TABLES       content        = l_content     EXCEPTIONS       not_found      = 1       bds_get_failed = 2       bds_no_content = 3       OTHERS         = 4.    CALL FUNCTION ‘SAPSCRIPT_CONVERT_BITMAP’     EXPORTING       old_format               = ‘BDS’       new_format               = ‘BMP’       bitmap_file_bytecount_in = l_bytecount     IMPORTING       bitmap_file_bytecount    = graphic_size     TABLES       bds_bitmap_file          = l_content       bitmap_file              = graphic_table     EXCEPTIONS       OTHERS                   = 1.    DESCRIBE TABLE graphic_table LINES lines.    lines  = lines.   w_counter = lines  – 1.   DATA  x_bmp TYPE  xstring.   CALL FUNCTION ‘SCMS_BINARY_TO_XSTRING’     EXPORTING       input_length = graphic_size     IMPORTING       buffer       = x_bmp     TABLES       binary_tab   = graphic_table     EXCEPTIONS       failed       = 1       OTHERS       = 2.    DATA : w2(2) TYPE  x , w4(4) TYPE  x , xstr TYPE  xstring.   DEFINE  read2.  “#EC NEEDED read two bytes as integer and move offset     w2 = &1.     concatenate  w2+1(1) w2+0(1) into  xstr in  byte mode .     &2 = xstr.   END-OF-DEFINITION .    DEFINE  read4. “#EC NEEDED read four bytes as integer and move offset     w4 = &1 .     concatenate  w4+3(1) w4+2(1) w4+1(1) w4+0(1) into  xstr in  byte mode .     &2 = xstr.   END-OF-DEFINITION .    DATA  magic_number(2) TYPE x.   magic_number = x_bmp+0(2).   DATA size(4) TYPE  x.   DATA i_size TYPE  i.   size = x_bmp+2(4).   DATA data_offset(4) TYPE x.   DATA i_data_offset TYPE i.   data_offset = x_bmp+10(4).   read4 size i_size.   read4 data_offset i_data_offset.    DATA  header_size(4) TYPE x.   DATA  i_header_size TYPE i.   header_size = x_bmp+14(4).   read4 header_size i_header_size.    DATA : width(4) TYPE  x,         height(4) TYPE  x,         i_width TYPE  i,         i_height TYPE i,         bpp(2) TYPE x,         i_bpp TYPE i,         compression(4) TYPE x,         i_compression TYPE i,         s_compression TYPE string.    IF  i_header_size = 40. “Windows V3 Format     width = x_bmp+18(4).     height = x_bmp+22(4).     bpp = x_bmp+28(2).     compression = x_bmp+30(4).     read4 width i_width.     read4 height i_height.     read2 bpp i_bpp.     read4 compression i_compression.   ENDIF.   CASE  i_compression.     WHEN  0.       s_compression = ‘RGB – None’.     WHEN  1.       s_compression = ‘RLE 8-bit/pixel’.     WHEN  2.       s_compression = ‘RLE 4-bit/pixel’.     WHEN  3.       s_compression = ‘Bit Field’.     WHEN  4.       s_compression = ‘JPEG’.     WHEN  5.       s_compression = ‘PNG’.   ENDCASE.    DATA x_data TYPE xstring.   DATA x_new_data TYPE xstring.   DATA i_num_pixels TYPE i.   DATA i_counter TYPE i.   DATA i_counter2 TYPE i.    x_data = x_bmp+i_data_offset. *  i_num_pixels = XSTRLEN( x_data ).   i_num_pixels = i_width. “i_num_pixels / 3 / i_height.   DATA  i_width_in_bytes TYPE  i.   i_width_in_bytes = i_width * 3.    DATA  x_row TYPE  xstring.   DATA  x_new_row TYPE  xstring.   DO  i_height TIMES.     x_row = x_data+i_counter(i_width).     CLEAR  i_counter2.     CLEAR  x_new_row.     DO  i_num_pixels TIMES .       CONCATENATE  x_row+i_counter2(1) x_new_row INTO x_new_row IN BYTE MODE.       i_counter2 = i_counter2 + 1.     ENDDO .     CONCATENATE  x_new_row x_new_data INTO  x_new_data IN BYTE MODE.     i_counter = i_counter + i_width.   ENDDO .    DATA  x_new_image TYPE  xstring.   CONCATENATE x_bmp(i_data_offset) x_new_data INTO x_new_image IN BYTE MODE.    CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’     EXPORTING       buffer     = x_new_image     TABLES       binary_tab = graphic_table_new.    CALL FUNCTION ‘DP_CREATE_URL’     EXPORTING       type    = ‘IMAGE’       subtype = ‘BMP’     TABLES       data    = graphic_table_new     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_normal.  ENDFORM.                    “LOAD_IMAGE    We’re going to see this picture as the result…image
To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

      1. Former Member
        Hello Blag,

        We upload about 6000 jpeg Forms in SAP every month and store in Cluster table. Then we have come up with interface to display these jpeg pics in Custom control screen. Your blog is similar but you are showing BMP files. 

        Do you know of a way to print jpeg format directly in SAP ? As soon as Invoices are printed, we want to pick this jpeg format form and print along with Invoice

        (0) 
        1. Alvaro Tejada Galindo Post author
          Niranjan:

          AFAIK, SAP only supports BMP and TIFF…JPEG is out of line…But check the code updated by Thomas Jung…Maybe that can help you out -;)

          Greetings,

          Blag.

          (0) 
  1. Thomas Jung
    Actually what you are trying to do is perfectly possible in ABAP (read on for the solution code). The problem is that in most environments there is a provided library that abstracts the bitmap. It has properties like height and width and usually has basic transformation methods built-in.

    In ABAP, no one (that I know of) has taken the time to build such a thing. It just means that to do such a thing, you need to know about the general structure of how a bitmap is stored. You can’t just reverse the byte order because there is important header information. Also reversing the order of the RGB values will change the color value of individual pixels (as you found out).

    I suggest this Wikipedia page for some basic reading on the structure of a Bitmap:
    http://en.wikipedia.org/wiki/Bitmap

    Also in ABAP you will need to cast the DWORD bytes into into integers.

    Here is the solution code that I came up with and it works fine for extracting most of the header information and inverting the image. If I had more time I could more interesting transformations:

    FORM load_image.

    CREATE OBJECT: container1 EXPORTING container_name = ‘PICTURE’,
    picture EXPORTING parent = container1.

    CALL FUNCTION ‘SAPSCRIPT_GET_GRAPHIC_BDS’
    EXPORTING
    i_object = ‘GRAPHICS’
    i_name = ‘ENJOY’
    i_id = ‘BMAP’
    i_btype = ‘BCOL’
    IMPORTING
    e_bytecount = l_bytecount
    TABLES
    content = l_content
    EXCEPTIONS
    not_found = 1
    bds_get_failed = 2
    bds_no_content = 3
    OTHERS = 4.

    CALL FUNCTION ‘SAPSCRIPT_CONVERT_BITMAP’
    EXPORTING
    old_format = ‘BDS’
    new_format = ‘BMP’
    bitmap_file_bytecount_in = l_bytecount
    IMPORTING
    bitmap_file_bytecount = graphic_size
    TABLES
    bds_bitmap_file = l_content
    bitmap_file = graphic_table
    EXCEPTIONS
    OTHERS = 1.

    DESCRIBE TABLE graphic_table LINES lines.

    lines = lines.
    w_counter = lines – 1.
    DATA x_bmp TYPE xstring.
    CALL FUNCTION ‘SCMS_BINARY_TO_XSTRING’
    EXPORTING
    input_length = graphic_size
    IMPORTING
    buffer = x_bmp
    TABLES
    binary_tab = graphic_table
    EXCEPTIONS
    failed = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    DATA: w2(2) TYPE x, w4(4) TYPE x, xstr TYPE xstring.
    DEFINE read2. “#EC NEEDED read two bytes as integer and move offset
    w2 = &1.
    concatenate w2+1(1) w2+0(1) into xstr in byte mode.
    &2 = xstr.
    END-OF-DEFINITION.
    DEFINE read4. “#EC NEEDED read four bytes as integer and move offset
    w4 = &1.
    concatenate w4+3(1) w4+2(1) w4+1(1) w4+0(1) into xstr in byte mode.
    &2 = xstr.
    END-OF-DEFINITION.

    DATA magic_number(2) TYPE x.
    magic_number = x_bmp+0(2).
    DATA size(4) TYPE x.
    DATA i_size TYPE i.
    size = x_bmp+2(4).
    DATA data_offset(4) TYPE x.
    data i_data_offset type i.
    data_offset = x_bmp+10(4).
    read4 size i_size.
    read4 data_offset i_data_offset.

    DATA header_size(4) TYPE x.
    DATA i_header_size TYPE i.
    header_size = x_bmp+14(4).
    read4 header_size i_header_size.

    DATA: width(4) TYPE x,
    height(4) TYPE x,
    i_width TYPE i,
    i_height TYPE i,
    bpp(2) TYPE x,
    i_bpp TYPE i,
    compression(4) TYPE x,
    i_compression TYPE i,
    s_compression TYPE string.

    IF i_header_size = 40. “Windows V3 Format
    width = x_bmp+18(4).
    height = x_bmp+22(4).
    bpp = x_bmp+28(2).
    compression = x_bmp+30(4).
    read4 width i_width.
    read4 height i_height.
    read2 bpp i_bpp.
    read4 compression i_compression.
    ENDIF.
    CASE i_compression.
    WHEN 0.
    s_compression = ‘RGB – None’.
    WHEN 1.
    s_compression = ‘RLE 8-bit/pixel’.
    WHEN 2.
    s_compression = ‘RLE 4-bit/pixel’.
    WHEN 3.
    s_compression = ‘Bit Field’.
    WHEN 4.
    s_compression = ‘JPEG’.
    WHEN 5.
    s_compression = ‘PNG’.
    ENDCASE.

    DATA x_data TYPE xstring.
    DATA x_new_data TYPE xstring.
    DATA i_num_pixels TYPE i.
    DATA i_counter TYPE i.

    x_data = x_bmp+i_data_offset.
    i_num_pixels = XSTRLEN( x_data ).
    i_num_pixels = i_num_pixels / 3.

    do i_height times.
    concatenate x_data+i_counter(i_width) x_new_data into x_new_data in byte mode.
    i_counter = i_counter + i_width.
    enddo.

    data x_new_image type xstring.
    concatenate x_bmp(i_data_offset) x_new_data into x_new_image in byte mode.

    CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
    EXPORTING
    buffer = x_new_image
    TABLES
    binary_tab = graphic_table_new.

    CALL FUNCTION ‘DP_CREATE_URL’
    EXPORTING
    type = ‘IMAGE’
    subtype = ‘BMP’
    TABLES
    data = graphic_table_new
    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_NORMAL.

    ENDFORM. “LOAD_IMAGE

    Have Fun!

    (0) 
    1. Alvaro Tejada Galindo Post author
      Thanks a lot Thomas -:) I already updated the weblog…After this…I can say that there’s no limits on what we can do on ABAP…We just need a good idea and some time to implement it…

      Greetings,

      Blag.

      (0) 
  2. Dushyant Shetty
    Great experiment !
    Other than the image-related stuff, because of your blog I finally started reading up on Scripting+ABAP 🙂 Thanks 🙂

    Regards,
    Dushyant

    (0) 
  3. Former Member
    Hi all, I have the problem to convert any binary code (for a new technology barcode) and convert this into a BMP. IN SAP exists an modulepool(Test se73) to convert this binary into otf and this otf into an pdf. (This works fine, but I want a BMP and not an PDF.) Have any ideas! Thanks a lot! Anne
    (0) 
  4. Thorsten Franz
    Amazing indeed. I wonder what Thomas is up to: An adaption of C64 vector graphics game “Elite” for Sapgui, using CL_GUI_TIMER and bitmaps generated ad hoc at PROCESS BEFORE OUTPUT?

    Cheers,

    Thorsten

    (0) 
  5. Former Member

    Hi,

    I am trying to compress the image by the same code shared in the thread but after image compression not able to view the image.

    Can you please guide how you are converting the compressed image from url?

     

    Thanks

    Sonali

    (0) 

Leave a Reply