[ABAP] String als Hexcode (HEX) ausgeben

DATA: lv_mime_type TYPE string.
DATA: lv_image_bytes TYPE xstring.
DATA: it_text80 TYPE STANDARD TABLE OF text80 WITH DEFAULT KEY.

TRY.
* Ein paar Bytes holen: Screenshot aufnehmen
    cl_gui_frontend_services=>get_screenshot( IMPORTING
                                                mime_type_str = lv_mime_type
                                                image         = lv_image_bytes ).

* xstring -> string
    DATA(lv_string) = CONV string( lv_image_bytes ).

* Breite 80 Zeichen für Ausgabe
    CALL FUNCTION 'SWA_STRING_TO_TABLE'
      EXPORTING
        character_string = lv_string
      IMPORTING
        character_table  = it_text80.

    LOOP AT it_text80 ASSIGNING FIELD-SYMBOL(<t>).
      WRITE: / <t>.
    ENDLOOP.

  CATCH cx_root INTO DATA(e_txt).
ENDTRY.

[ABAP] Hexadezimale IP-Adresse in IPv4-String umwandeln

CLASS lcl_conv DEFINITION.
  PUBLIC SECTION.
*--------------------------------------------------------------------*
    CLASS-METHODS: ipv4hex_to_ipv4string
      IMPORTING
                i_hexadr      TYPE mshostadr
      RETURNING VALUE(ret_ip) TYPE string.
ENDCLASS.
*--------------------------------------------------------------------*
CLASS lcl_conv IMPLEMENTATION.
*--------------------------------------------------------------------*
* Konvertiert IP-Adresse (Hex) nach IPv4-String
*--------------------------------------------------------------------*
* -> i_hexadr - Hostadresse (IP) in Hex
* <- ret_ip   - IP-Adresse (IPv4)
*--------------------------------------------------------------------*
  METHOD ipv4hex_to_ipv4string.
* IP besteht aus 4 Bytes (Hex)
    IF xstrlen( i_hexadr ) = 4.
* jeder Hex-Wert wird in Integer konvertiert
      ret_ip = |{ CONV i( i_hexadr+0(1) ) }.{ CONV i( i_hexadr+1(1) ) }.{ CONV i( i_hexadr+2(1) ) }.{ CONV i( i_hexadr+3(1) ) }|.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

* mshostadr -> TYPE RAW4 -> x
* 255.255.255.0
DATA: ip_hex TYPE mshostadr VALUE 'FFFFFF00'.

WRITE: / lcl_conv=>ipv4hex_to_ipv4string( ip_hex ).

[ABAP] String nach Integer konvertieren

Variante 1 (Typecast -> direkte Zuweisung)

DATA: lv_string TYPE string VALUE '01234567'.
DATA: lv_int TYPE i.

* Typecast durch direkte Zuweisung
lv_int = lv_string.

* Ausgabe: 1.234.567
WRITE: / lv_int.

Variante 2 (CL_ABAP_CONTAINER_UTILITIES)

* String
DATA(lv_str_val) = |123|.
* Int
DATA(lv_int) = 0.

* String -> Int
cl_abap_container_utilities=>read_container_c( EXPORTING
                                                 im_container = lv_str_val
                                               IMPORTING
                                                 ex_value     = lv_int ).

WRITE: / lv_int.

[ABAP] xstring (Bytes) nach string (Text) wandeln

DATA: lv_xstr TYPE xstring VALUE '54657374737472696E672066C3BC7220646965204B6F6D7072657373696F6E206D697420475A49502E'.
DATA: lv_str TYPE string.
  
* xstring (binary) -> string (UTF-8)
DATA(o_conv_r) = cl_abap_conv_in_ce=>create( input = lv_xstr encoding = 'UTF-8' ).
o_conv_r->read( IMPORTING data = lv_str ).

WRITE: / lv_str.