Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
horst_keller
Product and Topic Expert
Product and Topic Expert
3,153


In two preceding blogs I bragged about CL_DEMO_OUTPUT.

Predictably, there is some disappointment because this class is not intended for productive usage.


Fair enough. But you can use it for testing purposes.


As an example, I will show you how you can use CL_DEMO_OUTPUT to produce a logfile for an expression. Quick and dirty.


To do so I choose the following simple constructor expression.
TYPES itab TYPE STANDARD TABLE OF i WITH EMPTY KEY.

DATA(itab) =
VALUE itab(
FOR i = 1 UNTIL i > 3
FOR j = 1 UNTIL j > 3
( i * 10 + j ) ).


Of course, you can test the result with cl_demo_output=>display( itab ).

But assume that you want to know what happens inside the expression and it is a more complicated expression and you don't want to debug or you can't or don't want to use other convenience tools (watchpoint, logpoints) provided by the ABAP Workbench/ADT or whatsoever.

In that situation you can instrumentalize an expression with CL_DEMO_OUTPUT, e.g. by misusing a LET expression:

TYPES itab TYPE STANDARD TABLE OF i WITH EMPTY KEY.

DATA(log) = cl_demo_output=>new( ).

DATA(itab) =
VALUE itab(
FOR i = 1 UNTIL i > 3
FOR j = 1 UNTIL j > 3
LET o = log->write( |{ i }, { j }\n{ i * 10 + j } | )->line( ) IN
( i * 10 + j ) ).

log->display( ).


Adding these three temporary lines to the above code gives:




Note that the local variable o declared behind LET is not used at all. It simply serves as hook for writing into the output object referenced by log.

There are no limits to the imagination!

 

 

3 Comments
Labels in this area