SAP 实例 8 HTML from the MIME Repository
阅读原文时间:2023年07月11日阅读:1

REPORT demo_html_from_mime.

CLASS mime_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
TYPES: mime_line(1022) TYPE x,
mime_tab TYPE STANDARD TABLE OF mime_line
WITH EMPTY KEY.
CLASS-METHODS get_mime_obj
IMPORTING
mime_url TYPE csequence
RETURNING
VALUE(mime_tab) TYPE mime_tab.
ENDCLASS.

CLASS mime_demo IMPLEMENTATION.
METHOD main.
DATA html_url TYPE c LENGTH 255.

DATA(custom\_container) = NEW  
  cl\_gui\_custom\_container( container\_name = 'CUSTOM\_CONTAINER' ).  
DATA(html\_control) = NEW  
 cl\_gui\_html\_viewer( parent = custom\_container ).

DATA(pict\_tab) = get\_mime\_obj(  
  mime\_url = '/SAP/PUBLIC/BC/ABAP/mime\_demo/ABAP\_Docu\_Logo.gif' ).  
html\_control->load\_data(  
  EXPORTING  
    url          = 'picture\_url'  
    type         = 'image'  
    subtype      = '.gif'  
  CHANGING  
    data\_table   = pict\_tab ).

DATA(html\_tab) = get\_mime\_obj(  
  mime\_url = '/SAP/PUBLIC/BC/ABAP/mime\_demo/demo\_html.html' ).  
html\_control->load\_data(  
  IMPORTING  
    assigned\_url = html\_url  
  CHANGING  
    data\_table   = html\_tab ).

html\_control->show\_url(  
   EXPORTING  
     url = html\_url ).  

ENDMETHOD.

METHOD get_mime_obj.
cl_mime_repository_api=>get_api( )->get(
EXPORTING i_url = mime_url
IMPORTING e_content = DATA(mime_wa)
EXCEPTIONS OTHERS = 4 ).
IF sy-subrc = 4.
RETURN.
ENDIF.
mime_tab =
VALUE #( LET l1 = xstrlen( mime_wa ) l2 = l1 - 1022 IN
FOR j = 0 THEN j + 1022 UNTIL j >= l1
( COND #( WHEN j <= l2 THEN
mime_wa+j(1022)
ELSE mime_wa+j ) ) ).
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
mime_demo=>main( ).
CALL SCREEN 100.

Description

An API is used to load a HTML file and an image from the MIME repository and save them in internal tables. The method LOAD_DATA of the class CL_GUI_HTML_VIEWER is used to associate the data with the HTML control of CFW and the HTML file is displayed. The name of the image in the HTML file is the same as the URL passed to the method LOAD_DATA for the image. LOAD_DATA is given a URL for the image in the internal table and is used on the HTML page.

See also the example for direct access to objects from the MIME repository using ICF.

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章