When you are using SAP trial account to practice ABAP – you are basically working on ABAP on Cloud. There are many restrictions here – but there are two restriction that impacts us the most.

  1. No screen – No selection screen, no module pool screen – not even output screen.
  2. No Program – You can not create a program – you have to create a class for anything that you want to try out.

So, if you can not have a screen – how would you test anything.

The answer is – ABAP CONSOLE.

In this post, you will learn – how to use ABAP console.

Follow below steps to write your internal tables or structure or variables to console from your class.

Step 1 : Add interface if_oo_adt_classrun and attribute of type if_oo_adt_classrun_out to your class. The attribute can be added in any visibility section. However the interface has to be added in a PUBLIC section because of its definition.

INTERFACES : if_oo_adt_classrun.
DATA : out TYPE REF TO if_oo_adt_classrun_out.

Step 2 : Implement method if_oo_adt_classrun~main and add below code. This method gets called when we execute the class.

me->out = out.
method_to_be_tested( ).

Here, out is the attribute that is declared in the first step and method_to_be_tested is, you know, method to be tested.

Step 3 : Once the internal table or structure or variable that you want to display on the screen is filled with value/values, simply write below code to display the output.

out->write( lt_itab ).
out->write( lt_structure ).
out->write( lv_variable ).

And you are done. You will get the output on the console.

Here is an example of complete class with the additions highlighted in bold.

CLASS zcl_console DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES : if_oo_adt_classrun.
  PRIVATE SECTION.
    DATA : out TYPE REF TO if_oo_adt_classrun_out.
    METHODS : get_flight_data.
ENDCLASS.

CLASS zcl_console IMPLEMENTATION.

  METHOD if_oo_adt_classrun~main.
    me->out = out.
    get_flight_data( ).
  ENDMETHOD.

  METHOD get_flight_data.
    SELECT * FROM /dmo/flight INTO TABLE @DATA(lt_flights).
    IF sy-subrc EQ 0.
      out->write( lt_flights ).
    ENDIF.
  ENDMETHOD.

ENDCLASS.

To execute the class on Console, you can use below icon or simply press the key F9.

Below is the output.

With these simple steps you can easily test the code you are creating using the ABAP console.

Visit ABAP on HANA series for Tutorials on CDS, AMDP, Eclipse, and ALV IDA.


If you like the content, please subscribe…

Join 4,017 other subscribers

Discovering ABAP YouTube Channel