[ABAP] Datenausgabe mit cl_demo_output

Demoprogramme

* DEMO_USAGE_OUTPUT_GET
* DEMO_USAGE_OUTPUT_STATIC
* DEMO_USAGE_OUTPUT_INSTANCE
* DEMO_USAGE_OUTPUT_STREAM

Text mit Abschnitten

* Abschnitt 1
cl_demo_output=>begin_section( '1. Überschrift' ).
cl_demo_output=>begin_section( '1.1 Überschrift' ).
* Text
cl_demo_output=>write_text( 'Text 1.1' ).
cl_demo_output=>write( 'Text 1.1 non proportional' ).
cl_demo_output=>end_section( ).
cl_demo_output=>end_section( ).
* Abschnitt 2
cl_demo_output=>begin_section( '2. Überschrift' ).
cl_demo_output=>begin_section( '2.1 Überschrift' ).
* Text
cl_demo_output=>write_text( 'Text 2.1' ).
cl_demo_output=>write( 'Text 2.1 non proportional' ).
cl_demo_output=>end_section( ).
cl_demo_output=>end_section( ).
* alles anzeigen
cl_demo_output=>display( ).

Überschrift

cl_demo_output=>next_section( 'Überschrift' ).

Variablen, Strukturen, Tabellen

TYPES: BEGIN OF ty_struct,
         f1 TYPE string,
         f2 TYPE i,
       END OF ty_struct.

TYPES: ty_it_tab TYPE STANDARD TABLE OF ty_struct WITH DEFAULT KEY.

DATA(lv_struct) = VALUE ty_struct( f1 = 'Field1' f2 = 1 ).
DATA(it_tab) = VALUE ty_it_tab( ( f1 = 'T1' f2 = 1 )
                                ( f1 = 'T2' f2 = 2 )
                                ( f1 = 'T3' f2 = 3 ) ).

cl_demo_output=>write_data( value = -100         name = 'Zahl' ).
cl_demo_output=>write_data( value = 'ein String' name = 'Text' ).
cl_demo_output=>write_data( value = lv_struct    name = 'Struct' ).
cl_demo_output=>write_data( value = it_tab       name = 'Tab' ).
* alles anzeigen
cl_demo_output=>display( ).

Trennlinie

cl_demo_output=>write_text( 'Oben' ).
cl_demo_output=>line( ).
cl_demo_output=>write_text( 'Unten' ).
* alles anzeigen
cl_demo_output=>display( ).

HTML

* HTML hinzufügen
cl_demo_output=>write_html( '<b>Text bold</b>' ).
* HTML anzeigen
cl_demo_output=>display_html( '<i>Text italic</i>' ).

XML

DATA: lv_xml TYPE string.
...
cl_demo_output=>display_xml( lv_xml ).

JSON

DATA: lv_json TYPE xstring.
...
cl_demo_output=>display_json( lv_json ).

Plaintext ausgeben

cl_demo_output=>set_mode( cl_demo_output=>text_mode ).
cl_demo_output=>write_data( value = it_tab name = 'Tab' ).
cl_demo_output=>display( ).

oder

SELECT * FROM tnapr INTO TABLE @DATA(it_tnapr).
cl_demo_output=>new( 'TEXT' )->display( it_tnapr ).

HTML-Code generieren lassen

SELECT * FROM mara INTO TABLE @DATA(it_mara).
IF sy-subrc = 0.
  cl_demo_output=>write_data( it_mara ).
* HTML-Code vom Demo-Output holen
  DATA(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING
                                title        = 'Daten aus der Tabelle MARA'
                                html_string  = lv_html
                                container    = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.
ENDIF.

Links