[ABAP] Bild (JPEG) aus dem MIME-Repository laden und anzeigen

* Demo-Programm: SAP_PICTURE_DEMO
DATA: o_dock TYPE REF TO cl_gui_docking_container.

PARAMETERS: p_name TYPE string. " Dummy-Parameter

AT SELECTION-SCREEN OUTPUT.

  IF NOT o_dock IS BOUND.
* Dockingcontainer erzeugen
    o_dock = NEW #( repid = sy-repid
                    dynnr = sy-dynnr
                    side  = cl_gui_docking_container=>dock_at_right
                    ratio = 50 ).

    DATA: lv_xstr TYPE xstring.

* MIME-API holen
    DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

* Bild aus dem MIME-Repository laden
    o_mime_rep->get( EXPORTING
                       i_url = '/SAP/PUBLIC/Test123.jpg'
                       i_check_authority = abap_false
                     IMPORTING
                       e_content = lv_xstr ).

* xstring nach binary (RAW) wandeln
    DATA(it_bin_data) = cl_bcs_convert=>xstring_to_solix( lv_xstr ).

    DATA: lv_url TYPE swk_url.

* temporäre URL auf das Bild erzeugen
    CALL FUNCTION 'DP_CREATE_URL'
      EXPORTING
        type                 = 'image/jpeg' " https://wiki.selfhtml.org/wiki/MIME-Type/%C3%9Cbersicht
        subtype              = 'jpg'
      TABLES
        data                 = it_bin_data
      CHANGING
        url                  = lv_url
      EXCEPTIONS
        dp_invalid_parameter = 1
        dp_error_put_table   = 2
        dp_error_general     = 3
        OTHERS               = 4.

* Bild über die URL laden und anzeigen
    DATA(o_pic) = NEW cl_gui_picture( parent = o_dock ).
    o_pic->set_display_mode( display_mode = cl_gui_picture=>display_mode_fit_center ).
    o_pic->load_picture_from_url_async( lv_url ).
  ENDIF.

Weiterführende Infos: Link