F MIME Repository in SAP | CodeTheta

MIME Repository in SAP

June 12, 2024

MIME Repository used to store various MIME objects in SAP. MIME objects are icons, excel sheets, graphics and so on. We can create MIME objects in SE80.

We can create a folder and within the folder we can import required MIME objects.

To create MIME repository follow below steps -

1. Go to SE80 then click on MIME repository.
2. Click on the PUBLIC folder. Then click a folder within the PUBLIC folder.
3. Then import your MIME objects into that newly created folder.

Then after that we can access that MIME objects through below programs

Code:

DATA: xlsurl TYPE string VALUE '/SAP/PUBLIC/ZMIME/Sample.xls'.

  DATA: o_mr_api TYPE REF TO if_mr_api.

  DATA: l_xls_xstr TYPE xstring,
        l_xls_conv TYPE i,
        l_xls_offs TYPE i,
        l_xls_size TYPE i.

  REFRESH xls_table.

  IF o_mr_api IS INITIAL.
    o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
  ENDIF.

  CALL METHOD o_mr_api->get
    EXPORTING
      i_url              = xlsurl
    IMPORTING
      e_content          = l_xls_xstr
    EXCEPTIONS
      parameter_missing  = 1
      error_occured      = 2
      not_found          = 3
      permission_failure = 4
      OTHERS             = 5.

  l_xls_size = xstrlen( l_xls_xstr ).

  CHECK l_xls_size > 0.

  l_xls_conv = l_xls_size.
  l_xls_offs = 0.

  WHILE l_xls_conv > 255.
    xls_table-line = l_xls_xstr+l_xls_offs(255).
    APPEND xls_table.
    l_xls_offs = l_xls_offs + 255.
    l_xls_conv = l_xls_conv - 255.
  ENDWHILE.

  xls_table-line = l_xls_xstr+l_xls_offs(l_xls_conv).
  APPEND xls_table.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.

  DATA: mydocuments     TYPE string.

  MOVE 'C:\' TO mydocuments.

  CALL METHOD cl_gui_frontend_services=>registry_get_value
    EXPORTING
      root      = 1   " HKEY_CURRENT_USER
      key       = 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
      value     = 'Personal'
    IMPORTING
      reg_value = mydocuments.


  DATA: l_fname         TYPE string,
        mytemplate(255) TYPE   c,
        filesize        TYPE   i,
        mymimeurl(255)      TYPE   c,
        mysave(120)     TYPE   c,
        fname(60)       VALUE 'Sample.xls'. "'multiple_linking_format.xls'.

  DATA spreadsheetintf     TYPE REF TO  i_oi_spreadsheet.
  DATA documentintf        TYPE REF TO i_oi_document_proxy.

  CONCATENATE mydocuments '\' fname INTO mytemplate.

  MOVE mytemplate TO l_fname.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filetype   = 'BIN'
      filename   = l_fname
    IMPORTING
      filelength = filesize
    TABLES
      data_tab   = xls_table.

  IF sy-subrc <> 0.
*    message e999 with 'XLS Download failed'.
  ENDIF.

  CONCATENATE 'file://' mytemplate INTO mymimeurl.


  CALL FUNCTION 'ZJNC_START_EXCEL'
    EXPORTING
      document_url    = mymimeurl
    IMPORTING
      spreadsheetintf = spreadsheetintf
      documentintf    = documentintf.

  IF documentintf    IS INITIAL OR spreadsheetintf IS INITIAL.
*    message e999 with 'NULL document/spreadsheet interfaces'.
  ENDIF.


  CALL FUNCTION 'POPUP_TO_INFORM'
    EXPORTING
      titel = sy-repid
      txt2  = ''
      txt1  = 'Save file first '.

IDE Used To Test This Code : SAP ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

Post a Comment