[ABAP] Nützliche ABAP-Datentypen

Datentypen

* DD04L
* DD04V

Name          Typ         Länge   Beschreibung
------------------------------------------------------------
SURL          char        255     URL Länge 255
SWK_URL       char        2048    URL Länge 2048
TEXT255       char        255     Text Lowercase
USS_Y_URL     char        255     URL Länge 255
VBC_TEXT      char        255     Beschreibung Lowercase
VBC_URL2      char        1024    URL Länge 1024
VBI_TEXT      char        255     Beschreibung Lowercase
VEPTEXT       char        255     Kurzbeschreibung Lowercase

Tabellentypen

* DD40L
* DD40T

Typ           Zeilentyp   Länge   Beschreibung
---------------------------------------------------------------------------
bdcdata_tab   bdcdata             Tabelle für Batchdaten
sotr_txts     char        255     Texttabelle
stringtab     string              Tabelle mit Strings
tttext255     char        255     Texttabelle
w3_htmltab    char        255     Texttabelle für HTML
wd_objects    REF                 Tabelle zur Speicherung von REF TO OBJECT
xml_rawdata   raw         255     Tabelle für RAW-Daten

[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] String -> XML

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

* ABAP (string) -> XML
DATA(o_writer_xml) = cl_sxml_string_writer=>create( if_sxml=>co_xt_xml10 ).
CALL TRANSFORMATION id SOURCE text = text RESULT XML o_writer_xml.
DATA(xml) = cl_abap_codepage=>convert_from( o_writer_xml->get_output( ) ).

WRITE: / xml.

[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.

[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.