[ABAP] Umwandlung SAP Codepage / HTTP Encoding Name

Tabellen

TCP00 (SAP Codepage Katalog)
TCP00A (Codepage-Attribute)

Variante 1 (cl_abap_codepage)

TRY.
    DATA(lv_http_codepage) = |utf-8|.
* utf-8 -> 4110
* get sap codepage by external name
    WRITE: / lv_http_codepage, '->', cl_abap_codepage=>sap_codepage( lv_http_codepage ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

Variante 2 (cl_i18n_utils)

* Encoding Name in SAP Codepage
DATA(lv_codepage_name) = |UTF-8|.
*H  HTTP-Name
*M  MIME-Name (wird nicht mehr benutzt)
*J  Java-Name (java.io und java.lang APIs)
*W  Microsoft-Windows Codepage-Nummer
*D  Dokumentenreferenz (ID(2),OBJ(60))
*T  Kurzer, internationaler Text
*A  Passende, ASCII-basierte Codepage
*C  RTF: /cpg Wert
*F  RTF: /fcharsetN Wert
*S  Sequenz von Code Units
*G  Enthält Filter Segmente
DATA(lv_kind) = CONV cpattrkind( 'H' ).
DATA(lv_sap_codepage) = CONV cpcodepage( '' ).

* Get a codepage from an encoding name
DATA(rv) = cl_i18n_utils=>get_cp_from_name( EXPORTING im_name = lv_codepage_name
                                                      im_kind = lv_kind
                                            IMPORTING ex_cp   = lv_sap_codepage ).

CASE rv.
* successful
  WHEN 0.
    WRITE: / lv_codepage_name, '->', lv_sap_codepage.
* internal error such as old kernel
  WHEN 1.
* I/O error such as missing TCP00A
  WHEN 8.
* invalid arguments
  WHEN 16.
* not found
  WHEN 128.
ENDCASE.

Variante 3 (cl_abap_codepage)

TRY.
    DATA(lv_sap_codepage) = CONV cpcodepage( '4110' ).
* 4110 -> utf-8
* convert sap codepage to http codepage
    WRITE: / lv_sap_codepage, '->', cl_abap_codepage=>sap_to_http( lv_sap_codepage ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

Variante 4 (cl_abap_codepage)

TRY.
    DATA(lv_sap_codepage) = CONV cpcodepage( '4110' ).
* 4110 -> UTF8
* convert sap codepage to JAVA codepage
    WRITE: / lv_sap_codepage, '->', cl_abap_codepage=>sap_to_java( lv_sap_codepage ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.