Skip to Content
Technical Articles
Author's profile photo Horst Keller

CL_DEMO_OUTPUT, Part 1 of 2 – Usage

In the ABAP Keyword Documentation, in SCN blogs or in other demos you might have recognized the usage of class CL_DEMO_OUTPUT. This blog in two parts will explain that class a little bit closer. Part 1 explains its usage while Part 2 will have a look behind the scenes.

Some extensions coming with ABAP release 7.56, SP01 are introduced in CL_DEMO_OUTPUT invigorated | SAP Blogs,


The classes described here are not intended for productive usage. You might use them in demonstration programs, local test programs or for temporary testing in productive programs. You must not use them productively in productive programs.



From the beginning, ABAP lacked a simple way of outputting data for test or demonstration purposes (System.out.println(…) in Java or printf in C so to say). In the old SAP GUI days of classical dynpros you could use the MESSAGE statement for short outputs in information messages or you mainly (mis)used the WRITE statemtent for creating list output. Simple and straightforward – but only in executable programs (reports)! Already in classical dialog programs this kind of WRITE output failed. Even worse in service oriented programming using classes. And nowadays when programming ABAP in ADT for UI5 and FIORI? Don’t ask. The class CL_DEMO_OUTPUT was invented as a demonstration, how this lack can be circumvented.



The methods of class CL_DEMO_OUTPUT create simple outputs of data in example programs without the need of classical lists. The class can be used via static methods and instance methods. The following methods create output in an output stream: 

  • Methods BEGIN_SECTION, NEXT_SECTION, and END_SECTION create headers and open or close header levels.
  • Methods WRITE_DATA, WRITE_TEXT, WRITE_XML, WRITE_JSON, and WRITE_HTML write different kinds of output into the output stream.
    • With method WRITE_DATA you can write elementary data objects (no reference variables), structures with elementary components, and internal tables of such line types.
    • The other methods create formated outputs of texts, XML, JSON, or HTML data.
  • Method WRITE is generic. It handles ABAP data as well as texts (in non proportional format).
  • Methods DISPLAY_… (available  as static methods only) work as WRITE_…, but close the current output stream and open a new one. If a SAP GUI is available, the output is displayed in a window.
  • Method LINE creates a horzontal line.
  • Method DISPLAY closes the current output stream and opens a new one. If a SAP GUI is available, the output is displayed in a window. Optionally you can also pass data to DISPLAY as you can do for WRITE.
  • Method GET works like DISPLAY but does not display the data. Instead the formated output data are returned in a text string and can be handled further.

The standard output format is HTML. Optionally you can choose a simple text format with tabulators and line breaks. You choose the format with method SET_MODE for the static methods or using the input parameter MODE of the factory method NEW for the instance methods.

The class CL_DEMO_OUTPUT is available in release 7.03/7.31 since SP07 and in higher releases. It has a class documentation.


Code Examples

The most simple and common type of usage might look as follows:

       FROM scarr
       INTO TABLE @DATA(carriers).

cl_demo_output=>display( carriers ).

The output is:




A program using more than one static method of CL_DEMO_OUTPUT might look as follows:

       FROM scarr
       INTO TABLE @DATA(carriers).

CALL TRANSFORMATION id SOURCE carriers = carriers
                       RESULT XML DATA(xml).

cl_demo_output=>begin_section( `Some Text` ).
cl_demo_output=>write_text( |blah blah blah \n| &&
                            |blah blah blah| ).
cl_demo_output=>next_section( `Some Data` ).
cl_demo_output=>begin_section( `Elementary Object` ).
cl_demo_output=>write_data( carriers[ 1 ]-carrid ).
cl_demo_output=>next_section( `Internal Table` ).
cl_demo_output=>write_data( carriers ).
cl_demo_output=>end_section( ).
cl_demo_output=>next_section( `XML` ).
cl_demo_output=>write_xml( xml ).
cl_demo_output=>display( ).

Since this looks very ugly, it is better to use the instance methods instead of the static methods if you call more than 3 to 4 methods of the class within a program:

       FROM scarr
       INTO TABLE @DATA(carriers).

CALL TRANSFORMATION id SOURCE carriers = carriers
                       RESULT XML DATA(xml).

  )->begin_section( `Some Text`
  )->write_text( |blah blah blah \n| &&
                 |blah blah blah|
  )->next_section( `Some Data`
  )->begin_section( `Elementary Object`
  )->write_data( carriers[ 1 ]-carrid
  )->next_section( `Internal Table`
  )->write_data( carriers
  )->next_section( `XML`
  )->write_xml( xml
  )->display( ).

Both give the same output:



You might ask yourself two things:


  • How can static methods and instance methods have the same name?

    The instance methods are interface methods. Method NEW returns a reference variable of type IF_DEMO_OUTPUT. This interface is implemented by CL_DEMO_OUTPUT. The interface methods have the same names as the static methods of the class.
  • Why can you chain these methods?For this convenience, each instance method returns the self reference me.


If you want a more simplistic output, you can switch to text mode:

       FROM scarr
       INTO TABLE @DATA(carriers).

cl_demo_output=>new( 'TEXT'
  )->display( carriers ).



If you want to deal with the resulting formatted data yourself, you use GET instead of DISPLAY:

       FROM scarr
       INTO TABLE @DATA(carriers).

DATA(html) = cl_demo_output=>get( carriers ).

cl_abap_browser=>show_html( html_string = html ).

You can also examine and run the following programs to get a complete overview of all possiblities:



Examples of Usage

An example how CL_DEMO_OUTPUT can be used by a framework is provided by the ABAP Keyword Documentation in ADT (aka ABAP in Eclipse). If an example of the ABAP Example Library uses CL_DEMO_OUTPUT, the documentation framework allows you to execute the example and displays the output. This is done by getting the HTML output from CL_DEMO_OUTPUT  and merging it into the (non SAP GUI) documentation display.


Another example is quite remarkable. CL_DEMO_OUTPUT made it to the stage in SAP Teched 2013!

Here a snapshot from Dr. Vishal Sikka’s keynote:


I guess it is quite safe to assume that nobody recognized how that demo output was created  😉 .

(B.t.w., see  AMDP, Comparison of SQLScript with Open SQL for a closer look at the performance results of that example; The bad ABAP results above come from nested SELECT loops …).




The methods of CL_DEMO_OUTPUT can serve for quick and dirty outputs in tests or in demo programs. But the class is not made for productive usage. Particularly, CL_DEMO_OUTPUT and the framework behind are not prepared for handling large amounts of data.


CL_DEMO_OUTPUT has a little sister CL_DEMO_INPUT that can be used for simple inputs of elementary values.



Recent versions of ADT allow you to execute ABAP programs by F9 instead of F8 in order to write output into an Eclipse console. And guess what? Outputs created by CL_DEMO_OUTPUT are also written to the console after F9!


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Enno Wulff
      Enno Wulff
      data(out) = cl_demo_output=>new( ).
      out->write( : data = sy-uname ),
                    data = sy-datum ),
                    data = sy-uzeit )->display( ).


      Author's profile photo Sandra Rossi
      Sandra Rossi

      Hello Horst, thank you for detailing this useful test class.

      Is it planned to make this class work for background jobs too, to output the data into a spool request(i.e. output tables using _ and | characters, as for ALV)? Currently, in my system (7.40 SP 7), it doesn't output anything in background, and that would be very useful for medium-long duration tasks.



      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author

      It does work in background if you use the GET method instead of display. You must send the result to spool yourself.

      Author's profile photo Sandra Rossi
      Sandra Rossi

      Thanks. As the result is HTML, it requires a few manual actions to display it (menu list -> save as -> clipboard, then open a text processing software, paste, remove "line feed" characters, save as an html, and display it). It's not so complex as I don't need it so frequently, but the task is tedious when I need it... and I'm lazy 😉

      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author

      Hmm, there is already a text mode available that returns plain text instead of HTML. I could modify the existing textual output mode by introducing | between columns and _ between lines and sell that as an additional list mode, hmm, not too much work. Maybe. But can’t you use the text mode anyway. Should be enough for tests. Already now, you can GET the text output into an internal table (split the string at |\n|) and WRITE that to spool.


      Author's profile photo Sandra Rossi
      Sandra Rossi

      Oh sorry, I hadn't seen the section about SET_MODE. It's just what I needed. Having borders would be nice, but I can easily live without it. Thanks a lot!

      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author


      Others asked for that too. In an upcoming release, the output mode will be switched from html to text mode automatically if sy-batch is 'X' and the generated text will be written to a spool list. No sophistication (no borders or colors), just quick and dirty WRITEs of the text lines.

      Author's profile photo Alexander K
      Alexander K

      Hi, Horsl.

      I am using cl_demo_output=>display_text( 'My small text'), but it opened buggest window with more space.

      Can I adjust the size of the displayed window

      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author

      No, not in CL_DEMO_OUTPUT=>DISPLAY_...

      Workaround: Use CL_DEMO_OUTPUT=>GET_... and send it yourself to CL_ABAP_BROWSER where you can set the size and orientation.

      Author's profile photo Alexander K
      Alexander K

      Thanks, Horst.

      Author's profile photo Chris Xu
      Chris Xu

      Hi  Horst,

      Is there an ADT version of CL_DEMO_INPUT? I tried it in ADT and failed.

      Is it possible to trigger prompt for input in ADT?



      Chris Xu

      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author


      No, how should that work?

      For output, ADT provides its console. But for input there would be the need of some "input console", which is not available. Only in the HTML of the executable examples of the ABAP Keyword Documentation, CL_DEMO_INPUT is supported.

      But why did you fail? Isn't it opened in the SAP GUI Plugin?

      Author's profile photo Chris Xu
      Chris Xu

      Understand and thank you Horst.

      I executed the report by 'F9', so there was no GUI window triggered.


      Chris Xu

      Author's profile photo Mike Pokraka
      Mike Pokraka

      Is there a simple way to suppress blank lines?

      Repeated write( ) calls always get a blank line inserted, which is unsuitable for lists. Use case:

      data(output) = cl_demo_output=>new( ). 
      loop at itab into data(row). 
        blah = derive_something_from( row ).
        output->write( blah ).
      output->display( ). 

      I tried various combinations of text mode and write_text to no avail. I still get:


      Which looks a bit ugly, especially for longer lists.

      I'm aware I can append to a string table as an alternative and write that, but that adds the itab name as header. I don't want the header in the output, just the list (for a simple ctrl-A ctrl-C to copy/paste).

      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author


      No, sorry ...

      Author's profile photo Mike Pokraka
      Mike Pokraka

      Thanks for the quick reply. In case anyone is interested, I created a (very) simple clone that outputs via ALV. I can click the top of the column and copy the list in one go with nothing superflous and no blank lines.

      CLASS lcl_output_list DEFINITION.
          METHODS write IMPORTING i_line TYPE clike.
          METHODS display.
          DATA: BEGIN OF t_output,
                  line TYPE string,
                END OF t_output.
          DATA output LIKE STANDARD TABLE OF t_output.
      CLASS lcl_output_list IMPLEMENTATION.
        METHOD write.
          APPEND VALUE #( line = i_line ) TO output.
        METHOD display.
              cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv)
                                      CHANGING  t_table      = output ).
            CATCH cx_salv_msg INTO DATA(bummer).
              MESSAGE bummer TYPE 'E'.
          alv->display( ).


      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author


      ~ Listing 11.16 from the good ol’ ABAP Objects book ?

      Author's profile photo Mike Pokraka
      Mike Pokraka

      <digs out copy of 2007 2nd edition>

      Yep! Wrote it myself, so something must have sunk in 🙂

      Author's profile photo Thorsten Klingbeil
      Thorsten Klingbeil

      Excellent! - very handy 🙂

      Author's profile photo Jonathan David Briceño Torralvo
      Jonathan David Briceño Torralvo

      The information that I have just read is amazing!

      Thanks , but I have a question, do you know what is the maximun capacity of data that can get into the pop-up ????