Skip to Content
Author's profile photo Horst Keller

Expression Logging

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:

/wp-content/uploads/2016/05/out8_949743.gif

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!

 

 

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Raja Dhandapani
      Raja Dhandapani

      Thanks for the blog Horst Keller!
      When I try to check the above code lines, I am getting error as "TYPE I is not a structure". I am checking it in ABAP 740 system.
      Please advise.

      Cheers,
      Raja D

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

      What's your SP? The examples work in 7.40, SP08, where conditional iteration expressions were introduced.
       

      Author's profile photo Raja Dhandapani
      Raja Dhandapani

      Thanks for your quick response!
      We are in  7.40 SP07.

      Cheers,
      Raja D