[ABAP] Prüfen, ob eine Datei in UTF-8 codiert ist

PARAMETERS: p_file TYPE string DEFAULT '/usr/sap/tmp/testmara.csv' .

START-OF-SELECTION.
  TRY.
      DATA: lv_bom TYPE sychar01.
      DATA: lv_encoding TYPE sychar01.

      cl_abap_file_utilities=>check_utf8( EXPORTING file_name = p_file
                                          IMPORTING bom       = lv_bom
                                                    encoding  = lv_encoding ).

      CASE lv_bom.
        WHEN cl_abap_file_utilities=>no_bom.
          WRITE: / 'no_bom'.
        WHEN cl_abap_file_utilities=>bom_utf8.
          WRITE: / 'bom_utf8'.
        WHEN cl_abap_file_utilities=>bom_utf16_be.
          WRITE: / 'bom_utf16_be'.
        WHEN cl_abap_file_utilities=>bom_utf16_le.
          WRITE: / 'bom_utf16_le'.
      ENDCASE.

      CASE lv_encoding.
        WHEN cl_abap_file_utilities=>encoding_utf8.
          WRITE: / 'encoding_utf8'.
        WHEN cl_abap_file_utilities=>encoding_7bit_ascii.
          WRITE: / 'encoding_7bit_ascii'.
        WHEN cl_abap_file_utilities=>encoding_other.
          WRITE: / 'encoding_other'.
      ENDCASE.

    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
  ENDTRY.