This is a test message to test the length of the message box.
Login
ABAP Class Runner Console Application
Created by Software-Heroes

ABAP - Class Runner (Console Application)

Regardless of whether it is an application in the cloud or an easy program to quickly do a few tests and generate an output, a console application will support you.

Advertising

What is a console application about and how can it help you develop? Today we want to bring this closer to you in the article and show you the advantages of such an application.

 

Program in ADT

You probably also know the problem that you want to try something quickly to get a debugable output. In SE80 you would write a report for this and execute it. Here you even have the option of controlling the entries with a selection screen. Unfortunately, this is not so easy with ADTs and presents you with certain challenges.

The SAP GUI is loaded every time a report is started, even if a selection screen may not even be required. This costs time and unnecessary resources, since we only want the output. The GUI then also jumps to the internal debugger in ADT and has to change the status again if we also want to debug the application.

 

Class Runner

For this purpose, SAP introduced the Class Runner to start processing directly via a class and still generate an output. The whole thing is solved via a global interface that the system makes available and that we can implement in our classes. For this purpose we create a new global class and can add the interface directly via the ADT Wizard.

 

After the implementation we only have to define the main method of the interface and can start with the implementation directly. The basic implementation of the class looks like this:

CLASS zcl_bs_demo_class_runner DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


CLASS zcl_bs_demo_class_runner IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    " Implementation
  ENDMETHOD.
ENDCLASS.

 

If we look at the method in detail (via F2), we see that we are still provided with an import parameter. This object offers us a method for writing to the console.

 

If you want to run a console application, you can do this via F9 or the "Run" menu. Here you also have the opportunity to see whether the current release of the system supports the new function.

 

Example

For this purpose, we have expanded the example a little further and written some output to the console. In addition, you can also pass the object in other methods if you want to use the output there or if the main method becomes too big.

CLASS zcl_bs_demo_class_runner DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun .

  PROTECTED SECTION.
  PRIVATE SECTION.
    METHODS:
      sub_methods_with_output
        IMPORTING
          io_out TYPE REF TO if_oo_adt_classrun_out.
ENDCLASS.


CLASS zcl_bs_demo_class_runner IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    DATA(ld_text) = `Output with a string`.
    out->write( ld_text ).

    DATA(ld_integer) = 12.
    out->write( ld_integer ).

    SELECT *
      FROM zdemo_tr_table
      INTO TABLE @DATA(lt_table).
    out->write( lt_table ).

    sub_methods_with_output( out ).
  ENDMETHOD.


  METHOD sub_methods_with_output.
    io_out->write( 'Call from submethod' ).
  ENDMETHOD.
ENDCLASS.

 

You will receive the corresponding texts in the console (a view in ADT).

 

Function

How does the processing with the class work exactly? The system checks whether the current class also implements the IF_OO_ADT_CLASSRUN interface, otherwise an error message is displayed. In the next step, an instance of the class is created and the main method is called. Then the normal execution of the class and the display of the console takes place.

Hint: If you want to use a constructor, it must not have any import parameters or these should be optional, otherwise there will be a dump when executing the class.

 

Program output

Reports can currently also be executed with F9 and output all WRITE outputs to the console. Instead of Write you can of course also use the CL_DEMO_OUTPUT class, which also supports the function. As long as the report does not have a selection screen, this variant works very well.

 

Conclusion

With the Class Runner, SAP provides a powerful tool for testing and trying out. On the other hand, you also need the interface in the cloud environment, as there are no reports you can use. Have fun building your first console application.


Included topics:
New ABAPClass RunnerConsole ApplicationIF_OO_ADT_CLASSRUN
Comments (0)
Advertising

ABAP - Performance for the SELECT

Category - ABAP

In this article we will look at a few special cases with the SELECT and examine the performance of these constructs. We'll show you the current alternatives and give you little tips while reading.

04/02/2021

ABAP - Check objects (Instances)

Category - ABAP

In this article we will show you how you can analyze instances and react to them correctly, for example if you hand them over during processing and want to react individually.

03/19/2021

ABAP - Loops

Category - ABAP

With New ABAP, new loops and possibilities for restricting table contents were created. We'll take a closer look at these new commands in this article.

02/19/2021

ABAP - Comparison

Category - ABAP

Today we'll look at comparisons and comparison operators in terms of the new commands and their current usage. What has changed so far and what should still be done?

02/12/2021

ABAP - String Functions (Part 3)

Category - ABAP

This article is about other new string functions and a replacement for CONDENSE. We would like to show you why you should use the new functions.

01/22/2021

We use cookies for our services and functions. More informations