[ABAP] String in Textabelle (SOLITAB) konvertieren

* Teststring bauen
DATA(lv_string) = REDUCE string( INIT s = ||
                                 FOR i = 1 WHILE i < 1001
                                 NEXT s = |{ s }{ i }| ).

* Ausgabetabelle
DATA(it_soli_txt) = VALUE soli_tab( ).

* string -> solitab (Text-Tabelle mit Zeilen a 255 Zeichen)
CALL FUNCTION 'SO_STRING_TO_TAB'
  EXPORTING
    content_str = lv_string
  TABLES
    content_tab = it_soli_txt.

* Ausgabe
cl_demo_output=>display( it_soli_txt ).

[ABAP] Binärdaten (xstring) zu String wandeln (xstring -> string)

Variante 1 (xstring -> string)

* Binärdaten als xstring
DATA(lv_xstring) = CONV xstring( 'A0B0C0FF' ).
* xstring -> string
DATA(lv_string) = CONV string( lv_xstring ).

WRITE: / lv_string.

Variante 2 (String als formatierten Hexcode 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 ).

* formatierte Ausgabe (80 Zeichen Breite)
    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] String -> JSON

DATA: text TYPE string VALUE 'Hello world!'.

* ABAP (string) -> JSON
DATA(o_writer_json) = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
CALL TRANSFORMATION id SOURCE text = text RESULT XML o_writer_json.
DATA(json) = cl_abap_codepage=>convert_from( o_writer_json->get_output( ) ).

WRITE: / json.

[ABAP] XML -> String

DATA: xml TYPE string VALUE '<?xml version="1.0" encoding="utf-8"?><asx:abap version="1.0" xmlns:asx="http://www.sap.com/abapxml"><asx:values><TEXT>Hello world!</TEXT></asx:values></asx:abap>'.
DATA: text TYPE string.

* XML -> ABAP (string)
CALL TRANSFORMATION id SOURCE XML xml RESULT text = text.

WRITE: / text.