MIME Types truncated in SAP Web Repository (SMW0)

Estimated read time 12 min read

Context: I have some Microsoft Office files, Excel, Word and PowerPoint, already uploaded to the SAP Web Repository (transaction SMW0). My system is ABAP 7.52.

Goal: I want to display these files from SMW0, via the Microsoft Office applications installed on my laptop.

Standard solution and issues:

Their MIME Types must be defined via the menu Settings > Define MIME Types:

Here I can enter the MIME types and corresponding file extensions of Microsoft Office applications.

I repeat the operation 3 times, each time pickup the value for MIME TYPE and EXTENSION:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xlsxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document.docxapplication/vnd.openxmlformats-officedocument.presentationml.presentation.pptx

Now, associate the corresponding programs installed on my laptop via the menu Settings > Assign MIME editor; these settings are user-dependent:

The possible MIME type values are truncated in the screen:

If you choose one of the Office MIME types, its name appears truncated again:

If you don’t fix it and save, you get the error “MIME type application/vnd.openxmlformats-officedocument unknown. Edit the settings”:

NB: what’s fun is that the setting is saved (but it’s useless).

So, the first problem about the truncation is that you have to remember its complete name and type it manually. We’ll see below a custom solution to display the full MIME types.

Now, complete the MIME type name, the Excel one for instance:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

In the Editor, you define the path to the program on your laptop, for instance:

C:Program FilesMicrosoft OfficerootOffice16EXCEL.EXE

Now, if you select an Excel file (uploading files is simple, so I didn’t show how to do it), it downloads the file to a temporary folder on your laptop, Excel opens it:

NB: if you open it in change mode, SMW0 will propose to import the temporary file.

So far, so good.

 

Now comes the second problem about the MIME type truncation (on the screen). If the associated program has been upgraded and is now at a different location, or if you just want to see the MIME type/editor associations, the truncation problem prevents from retrieving and showing the associated program.

So, I have created this little program to display and edit these associations (press F4 to select the MIME type editor; press Save or Execute to save):

Have fun!

For information, in SMW0, the menu Settings > Delete assignments doesn’t help, it deletes all the assignments, so it’s not very useful:

Code of the program to display and edit the MIME type/editor associations:

REPORT.
TABLES sscrfields.
PARAMETERS dummy.
CLASS lcl_app DEFINITION DEFERRED.
DATA app TYPE REF TO lcl_app.
LOAD-OF-PROGRAM.
CREATE OBJECT app TYPE (‘LCL_APP’).
AT SELECTION-SCREEN OUTPUT.
CALL METHOD app->(‘PBO’).
AT SELECTION-SCREEN.
CALL METHOD app->(‘PAI’).

CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS pbo.
METHODS pai.

PRIVATE SECTION.
TYPES:
“! w3mimeappl-appli TYPE c LENGTH 250
BEGIN OF ty_alv_mimeapp_appli,
appli_1 TYPE c LENGTH 128,
appli_2 TYPE c LENGTH 122,
END OF ty_alv_mimeapp_appli.
TYPES:
BEGIN OF ty_alv_mimeapp,
mtype TYPE w3mimeappl-mtype.
INCLUDE TYPE ty_alv_mimeapp_appli AS appli.
TYPES:
END OF ty_alv_mimeapp.
TYPES tt_alv_mimeapps TYPE STANDARD TABLE OF ty_alv_mimeapp WITH EMPTY KEY.
TYPES tt_mimeapps TYPE TABLE OF w3mimeappl WITH EMPTY KEY.

CONSTANTS c_mimeappl TYPE w3objid VALUE ‘mimeappl’.

DATA alv_mimeapps TYPE tt_alv_mimeapps.
DATA grid TYPE REF TO cl_gui_alv_grid.
DATA table_spfli TYPE TABLE OF spfli.

METHODS get_mimetypes RETURNING VALUE(et_mimeapps) TYPE tt_mimeapps.
METHODS save_mimetypes IMPORTING it_mimeapps TYPE tt_mimeapps.

METHODS on_onf4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
e_fieldvalue
er_event_data.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
METHOD pbo.
IF grid IS BOUND.
RETURN.
ENDIF.
SELECT * FROM mimetypes INTO TABLE @DATA(mimetypes).
DATA(mimeapps) = get_mimetypes( ).
alv_mimeapps = VALUE #( FOR <mimeapp> IN mimeapps
( mtype = <mimeapp>-mtype
appli_1 = <mimeapp>-appli(128)
appli_2 = <mimeapp>-appli+128 ) ).
LOOP AT mimetypes REFERENCE INTO DATA(mimetype).
IF NOT line_exists( alv_mimeapps[ mtype = mimetype->type ] ).
INSERT VALUE #( mtype = mimetype->type
appli_1 = ”
appli_2 = ” ) INTO TABLE alv_mimeapps.
ENDIF.
ENDLOOP.
LOOP AT alv_mimeapps REFERENCE INTO DATA(alv_mimeapp)
WHERE appli NP ‘!! *’.
IF NOT line_exists( mimetypes[ type = alv_mimeapp->mtype ] ).
alv_mimeapp->appli = CONV w3mimeappl-appli( |!! { CONV string( alv_mimeapp->appli ) }| ).
ENDIF.
ENDLOOP.
grid = NEW cl_gui_alv_grid( i_parent = cl_gui_container=>screen0 ).
SET HANDLER on_onf4 FOR grid.
grid->register_f4_for_fields( it_f4 = VALUE #( register = abap_true
chngeafter = abap_true
( fieldname = ‘APPLI_1’ )
( fieldname = ‘APPLI_2’ ) ) ).
DATA(fieldcatalog) = VALUE lvc_t_fcat( ( fieldname = ‘MTYPE’ ref_table = ‘W3MIMEAPPL’ ref_field = ‘MTYPE’ )
( fieldname = ‘APPLI_1’
dd_outlen = 128
inttype = ‘C’
lowercase = abap_true
f4availabl = abap_true
scrtext_l = ‘Editor path (128 first characters)’ )
( fieldname = ‘APPLI_2’
dd_outlen = 122
inttype = ‘C’
lowercase = abap_true
f4availabl = abap_true
scrtext_l = ‘Editor path (last characters)’ ) ).
grid->set_table_for_first_display( EXPORTING is_layout = VALUE #( edit = abap_true
cwidth_opt = abap_true )
CHANGING it_outtab = alv_mimeapps
it_fieldcatalog = fieldcatalog
EXCEPTIONS OTHERS = 4 ).
ENDMETHOD.

METHOD pai.
CASE sscrfields-ucomm.
WHEN ‘ONLI’
OR ‘SPOS’.
grid->check_changed_data( ).
DATA(mimeapps) = VALUE tt_mimeapps( FOR <alv_mimeapp> IN alv_mimeapps
( mtype = <alv_mimeapp>-mtype
appli = <alv_mimeapp>-appli ) ).
save_mimetypes( mimeapps ).
MESSAGE ‘Data saved’ TYPE ‘I’.
” Don’t trigger save of selection screen variant
sscrfields-ucomm = ”.
ENDCASE.
ENDMETHOD.

METHOD on_onf4.
DATA lt_filetable TYPE filetable.
DATA l_rc TYPE i.
DATA l_action TYPE i.
DATA return TYPE TABLE OF ddshretval.

FIELD-SYMBOLS <ls_file> TYPE file_table.
FIELD-SYMBOLS <table_modi> TYPE lvc_t_modi.

CASE e_fieldname.
WHEN ‘APPLI_1’
OR ‘APPLI_2’.
DATA(alv_mimeapp) = alv_mimeapps[ es_row_no-row_id ].
cl_gui_frontend_services=>file_open_dialog( EXPORTING default_filename = CONV #( alv_mimeapp-appli )
CHANGING file_table = lt_filetable
rc = l_rc
user_action = l_action
EXCEPTIONS OTHERS = 5 ).
IF sy-subrc <> 0.
” TODO error
ELSEIF l_action <> cl_gui_frontend_services=>action_ok.
” F4 cancelled by user
ELSE.
” 1 file selected
READ TABLE lt_filetable INDEX 1 ASSIGNING <ls_file>.
IF sy-subrc = 0.
DATA(ls_alv_mimeapp) = CONV ty_alv_mimeapp-appli( <ls_file>-filename ).
ASSIGN er_event_data->m_data->* TO <table_modi>.
<table_modi> = VALUE #( BASE <table_modi>
row_id = es_row_no-row_id
( fieldname = ‘APPLI_1’
value = ls_alv_mimeapp-appli_1 )
( fieldname = ‘APPLI_2’
value = ls_alv_mimeapp-appli_2 ) ).
ENDIF.
ENDIF.
er_event_data->m_event_handled = ‘X’.
ENDCASE.
ENDMETHOD.

METHOD get_mimetypes.
DATA l_objid TYPE wwwdataid.

CONCATENATE c_mimeappl sy-uname INTO l_objid-objid.
CLEAR et_mimeapps.
IMPORT mimeapps = et_mimeapps FROM DATABASE wwwdata(st) ID l_objid.
ENDMETHOD.

METHOD save_mimetypes.
DATA l_objid TYPE wwwdataid.

CONCATENATE c_mimeappl sy-uname INTO l_objid-objid.
EXPORT mimeapps = it_mimeapps TO DATABASE wwwdata(st) ID l_objid.
ENDMETHOD.
ENDCLASS.

 

 

​ Context: I have some Microsoft Office files, Excel, Word and PowerPoint, already uploaded to the SAP Web Repository (transaction SMW0). My system is ABAP 7.52.Goal: I want to display these files from SMW0, via the Microsoft Office applications installed on my laptop.Standard solution and issues:Their MIME Types must be defined via the menu Settings > Define MIME Types:Here I can enter the MIME types and corresponding file extensions of Microsoft Office applications.I repeat the operation 3 times, each time pickup the value for MIME TYPE and EXTENSION:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xlsxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document.docxapplication/vnd.openxmlformats-officedocument.presentationml.presentation.pptxNow, associate the corresponding programs installed on my laptop via the menu Settings > Assign MIME editor; these settings are user-dependent:The possible MIME type values are truncated in the screen:If you choose one of the Office MIME types, its name appears truncated again:If you don’t fix it and save, you get the error “MIME type application/vnd.openxmlformats-officedocument unknown. Edit the settings”:NB: what’s fun is that the setting is saved (but it’s useless).So, the first problem about the truncation is that you have to remember its complete name and type it manually. We’ll see below a custom solution to display the full MIME types.Now, complete the MIME type name, the Excel one for instance:application/vnd.openxmlformats-officedocument.spreadsheetml.sheetIn the Editor, you define the path to the program on your laptop, for instance:C:Program FilesMicrosoft OfficerootOffice16EXCEL.EXENow, if you select an Excel file (uploading files is simple, so I didn’t show how to do it), it downloads the file to a temporary folder on your laptop, Excel opens it:NB: if you open it in change mode, SMW0 will propose to import the temporary file.So far, so good. Now comes the second problem about the MIME type truncation (on the screen). If the associated program has been upgraded and is now at a different location, or if you just want to see the MIME type/editor associations, the truncation problem prevents from retrieving and showing the associated program.So, I have created this little program to display and edit these associations (press F4 to select the MIME type editor; press Save or Execute to save):Have fun!For information, in SMW0, the menu Settings > Delete assignments doesn’t help, it deletes all the assignments, so it’s not very useful:Code of the program to display and edit the MIME type/editor associations:REPORT.
TABLES sscrfields.
PARAMETERS dummy.
CLASS lcl_app DEFINITION DEFERRED.
DATA app TYPE REF TO lcl_app.
LOAD-OF-PROGRAM.
CREATE OBJECT app TYPE (‘LCL_APP’).
AT SELECTION-SCREEN OUTPUT.
CALL METHOD app->(‘PBO’).
AT SELECTION-SCREEN.
CALL METHOD app->(‘PAI’).

CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS pbo.
METHODS pai.

PRIVATE SECTION.
TYPES:
“! w3mimeappl-appli TYPE c LENGTH 250
BEGIN OF ty_alv_mimeapp_appli,
appli_1 TYPE c LENGTH 128,
appli_2 TYPE c LENGTH 122,
END OF ty_alv_mimeapp_appli.
TYPES:
BEGIN OF ty_alv_mimeapp,
mtype TYPE w3mimeappl-mtype.
INCLUDE TYPE ty_alv_mimeapp_appli AS appli.
TYPES:
END OF ty_alv_mimeapp.
TYPES tt_alv_mimeapps TYPE STANDARD TABLE OF ty_alv_mimeapp WITH EMPTY KEY.
TYPES tt_mimeapps TYPE TABLE OF w3mimeappl WITH EMPTY KEY.

CONSTANTS c_mimeappl TYPE w3objid VALUE ‘mimeappl’.

DATA alv_mimeapps TYPE tt_alv_mimeapps.
DATA grid TYPE REF TO cl_gui_alv_grid.
DATA table_spfli TYPE TABLE OF spfli.

METHODS get_mimetypes RETURNING VALUE(et_mimeapps) TYPE tt_mimeapps.
METHODS save_mimetypes IMPORTING it_mimeapps TYPE tt_mimeapps.

METHODS on_onf4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
e_fieldvalue
er_event_data.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
METHOD pbo.
IF grid IS BOUND.
RETURN.
ENDIF.
SELECT * FROM mimetypes INTO TABLE @DATA(mimetypes).
DATA(mimeapps) = get_mimetypes( ).
alv_mimeapps = VALUE #( FOR <mimeapp> IN mimeapps
( mtype = <mimeapp>-mtype
appli_1 = <mimeapp>-appli(128)
appli_2 = <mimeapp>-appli+128 ) ).
LOOP AT mimetypes REFERENCE INTO DATA(mimetype).
IF NOT line_exists( alv_mimeapps[ mtype = mimetype->type ] ).
INSERT VALUE #( mtype = mimetype->type
appli_1 = ”
appli_2 = ” ) INTO TABLE alv_mimeapps.
ENDIF.
ENDLOOP.
LOOP AT alv_mimeapps REFERENCE INTO DATA(alv_mimeapp)
WHERE appli NP ‘!! *’.
IF NOT line_exists( mimetypes[ type = alv_mimeapp->mtype ] ).
alv_mimeapp->appli = CONV w3mimeappl-appli( |!! { CONV string( alv_mimeapp->appli ) }| ).
ENDIF.
ENDLOOP.
grid = NEW cl_gui_alv_grid( i_parent = cl_gui_container=>screen0 ).
SET HANDLER on_onf4 FOR grid.
grid->register_f4_for_fields( it_f4 = VALUE #( register = abap_true
chngeafter = abap_true
( fieldname = ‘APPLI_1’ )
( fieldname = ‘APPLI_2’ ) ) ).
DATA(fieldcatalog) = VALUE lvc_t_fcat( ( fieldname = ‘MTYPE’ ref_table = ‘W3MIMEAPPL’ ref_field = ‘MTYPE’ )
( fieldname = ‘APPLI_1’
dd_outlen = 128
inttype = ‘C’
lowercase = abap_true
f4availabl = abap_true
scrtext_l = ‘Editor path (128 first characters)’ )
( fieldname = ‘APPLI_2’
dd_outlen = 122
inttype = ‘C’
lowercase = abap_true
f4availabl = abap_true
scrtext_l = ‘Editor path (last characters)’ ) ).
grid->set_table_for_first_display( EXPORTING is_layout = VALUE #( edit = abap_true
cwidth_opt = abap_true )
CHANGING it_outtab = alv_mimeapps
it_fieldcatalog = fieldcatalog
EXCEPTIONS OTHERS = 4 ).
ENDMETHOD.

METHOD pai.
CASE sscrfields-ucomm.
WHEN ‘ONLI’
OR ‘SPOS’.
grid->check_changed_data( ).
DATA(mimeapps) = VALUE tt_mimeapps( FOR <alv_mimeapp> IN alv_mimeapps
( mtype = <alv_mimeapp>-mtype
appli = <alv_mimeapp>-appli ) ).
save_mimetypes( mimeapps ).
MESSAGE ‘Data saved’ TYPE ‘I’.
” Don’t trigger save of selection screen variant
sscrfields-ucomm = ”.
ENDCASE.
ENDMETHOD.

METHOD on_onf4.
DATA lt_filetable TYPE filetable.
DATA l_rc TYPE i.
DATA l_action TYPE i.
DATA return TYPE TABLE OF ddshretval.

FIELD-SYMBOLS <ls_file> TYPE file_table.
FIELD-SYMBOLS <table_modi> TYPE lvc_t_modi.

CASE e_fieldname.
WHEN ‘APPLI_1’
OR ‘APPLI_2’.
DATA(alv_mimeapp) = alv_mimeapps[ es_row_no-row_id ].
cl_gui_frontend_services=>file_open_dialog( EXPORTING default_filename = CONV #( alv_mimeapp-appli )
CHANGING file_table = lt_filetable
rc = l_rc
user_action = l_action
EXCEPTIONS OTHERS = 5 ).
IF sy-subrc <> 0.
” TODO error
ELSEIF l_action <> cl_gui_frontend_services=>action_ok.
” F4 cancelled by user
ELSE.
” 1 file selected
READ TABLE lt_filetable INDEX 1 ASSIGNING <ls_file>.
IF sy-subrc = 0.
DATA(ls_alv_mimeapp) = CONV ty_alv_mimeapp-appli( <ls_file>-filename ).
ASSIGN er_event_data->m_data->* TO <table_modi>.
<table_modi> = VALUE #( BASE <table_modi>
row_id = es_row_no-row_id
( fieldname = ‘APPLI_1’
value = ls_alv_mimeapp-appli_1 )
( fieldname = ‘APPLI_2’
value = ls_alv_mimeapp-appli_2 ) ).
ENDIF.
ENDIF.
er_event_data->m_event_handled = ‘X’.
ENDCASE.
ENDMETHOD.

METHOD get_mimetypes.
DATA l_objid TYPE wwwdataid.

CONCATENATE c_mimeappl sy-uname INTO l_objid-objid.
CLEAR et_mimeapps.
IMPORT mimeapps = et_mimeapps FROM DATABASE wwwdata(st) ID l_objid.
ENDMETHOD.

METHOD save_mimetypes.
DATA l_objid TYPE wwwdataid.

CONCATENATE c_mimeappl sy-uname INTO l_objid-objid.
EXPORT mimeapps = it_mimeapps TO DATABASE wwwdata(st) ID l_objid.
ENDMETHOD.
ENDCLASS.    Read More Technology Blog Posts by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author