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

CL_DEMO_OUTPUT invigorated

Some time ago, we introduced CL_DEMO_OUTPUT for simple examples and demonstrations.

CL_DEMO_OUTPUT, Part 1 of 2 – Usage | SAP Blogs

The functionality up to now was already nice and useful, but somehow it was not complete.

Writing a simple piece of code such as

    BEGIN OF super,
      col1 TYPE i VALUE 1,
      BEGIN OF sub,
        col2 TYPE i VALUE 2,
        col3 TYPE i VALUE 3,
      END OF sub,
    END OF super.

  cl_demo_output=>display( super ).

results in


We are happy to announce that from ABAP release 7.56, SP01 on, this output will look as follows:

In fact, you can output  (nearly?) everything now:

      BEGIN OF spfli_line,
        carrid   TYPE spfli-carrid,
        connid   TYPE spfli-connid,
        cityfrom TYPE spfli-cityfrom,
        cityto   TYPE spfli-cityto,
      END OF spfli_line,
      spfli_tab TYPE HASHED TABLE OF spfli_line
                     WITH UNIQUE KEY carrid connid,
      BEGIN OF struct,
        carrname TYPE scarr-carrname,
        spfli    TYPE REF TO spfli_tab,
      END OF struct.
    DATA result TYPE SORTED TABLE OF struct WITH UNIQUE KEY carrname.
    METHODS constructor.

  METHOD constructor.
    SELECT s~carrname, p~carrid, p~connid, p~cityfrom, p~cityto
           FROM scarr AS s
             INNER JOIN spfli AS p
               ON s~carrid = p~carrid
           ORDER BY s~carrname
           INTO TABLE @DATA(itab).
    LOOP AT itab ASSIGNING FIELD-SYMBOL(<fs>) GROUP BY <fs>-carrname.
      INSERT VALUE #( carrname = <fs>-carrname ) INTO TABLE result
             ASSIGNING FIELD-SYMBOL(<line>).
      <line>-spfli = NEW #(
        FOR <wa> IN GROUP <fs> ( CORRESPONDING #( <wa> ) ) ).


  DATA(oref) = NEW demo_class( ).

  cl_demo_output=>display( oref ).


Note, that simply the name of the reference variable oref is passed to the display method.

This has been achieved by introducing some recursions in CL_DEMO_OUTPUT_STREAM. That means that the intermediate XML coming from CL_DEMO_OUTPUT_STREAM supports nested stuff now and that the conversion capabilities of CL_DEMO_OUTPUT_HTML were enhanced accordingly.

And just for fun, we can also write self-explaining demos now:

DATA(o) = cl_demo_output=>new(
)->write_doc( cl_demo_output_helper=>get_infobox_html(
     `This output is produced by program ` && sy-repid )
)->next_section( 'ABAP CDS View Entity'
)->write_doc( cl_demo_output_helper=>get_ddls_source_code_html(
     source = 'DEMO_CDS_SPFLI_ENTITY' )
)->next_section( `ABAP SQL SELECT`
   `The following code snippet demonstrates a ` &&
   `<code>SELECT</code> statement accessing `   &&
   `the CDS view entity without `               &&
   `<code>ORDER BY</code> clause:`
)->begin_code( `select1` ).

       FROM demo_cds_spfli_entity

o->end_code( `select1`
)->write_doc( `The result in <code>itab</code> is:`
)->write( itab
)->write_doc( `Adding`
     code = `ORDER BY cityfrom, cityto`  )
)->write_doc( `as follows`
)->begin_code( `select2` ).

       FROM demo_cds_spfli_entity
       ORDER BY cityfrom, cityto
       INTO TABLE @itab. "#EC CI_NOWHERE

o->end_code( `select2`
)->write_doc( `gives:`
)->write( itab
)->display( ).


As before, you can retrieve the HTML file with method GET instead of DISPLAY in order to become independent from SAP GUI.


  • You have to wait for 7.56, SP01
  • The new complex outputs are not fully supported by the text mode (but who wants to reprogram a browser in CL_DEMO_OUTPUT_TEXT?)
  • ADT console supports only text but not HTML mode
  • It is for demonstration purposes only …









Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      Thanks for an update, Horst! This is great news. Too many times I've run into "data type not yet supported" and was wondering when that "yet" might be coming. I guess we're there now. 🙂

      Thanks for sharing!

      Author's profile photo AjeethKumar R
      AjeethKumar R

      Wow. This looks cool.

      Author's profile photo Shai Sinai
      Shai Sinai


      though still for demonstration purposes only…

      Author's profile photo Rahul Abrol
      Rahul Abrol

      Hi Horst,

      Cl_DEMO_OUTPUT is only for developer testing since we cannot move these classes to production systems, Could you please the let me know the possibilities where I could use this except testing?

      Thanks & Regards

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

      It is only for testing and demonstration purposes.

      Author's profile photo Peter Inotai
      Peter Inotai

      It's great to see that the good old cl_demo_output is still being developed. It makes me happy. 🙂

      I won't ask about planned downport, because I think I know the answer 🙂

      Author's profile photo Yasin N
      Yasin N


      Nice blog, I got some issues earlier while using Cl_DEMO_OUTPUT (data type not yet supported)

      Thanks for sharing it is very helpful.


      Author's profile photo Frederic Girod
      Frederic Girod

      It is really amazing!

      But, is it possible SAP release this tool, stop spelling it as "demo"?  This is so usefull.

      Personnaly I used it in productive program.

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

      There are good reasons for keeping it as "Demo". First of all, it was developed for demo programs only (for a never finished follow-up of the ABAP Objects Book, later for the ABAP Keyword Documentation). If iit s useful for you in your demos, that's fine, but productive usage is at your own risk. For example, CL_DEMO_OUTPUT and CL_DEMO_OUTPT_STREAM are not suitable for large amounts of data. If we would publish it for productive usage, shortly we would be swamped with demands for improvement,

      Furthermore, keeping it as "Demo" allows incompatible improvements. The change discussed under was in fact incompatible and we received a customer incident regarding this change just recently!  Of course we reacted by improving the respective behavior (method GET delivers HTML in background processing again, only DISPLAY switches to text mode), but we are not forced to backport that.

      All in all, the classes might serve as patterns for your own (productive) classes but then it is your own responsibility. Please be aware, that it is not "SAP"  that is shirking responsibility here. The classes are just the product of ABAP documentation writers playing around for their own purposes.

      Author's profile photo Frederic Girod
      Frederic Girod

      It is the problem of the tool coming realy usefull. But I understand the reasons you exposed.

      As you set-it as FINAL class, we could not use inheritance to encapsulate in specific class.


      Is it allowed to create a public version on GitHub of this tool ? if we want to propose a new version.

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

      Removing the FINAL would cause the same compatibility problems. We couldn't change or even remove components of the class any more. In fact, that problem already occurred internally.

      Since we promote it as a demo, you can copy it to your own (GIT) repositories.