Mentor SAP

Basic Principle of the ALV Object Model

You must call the FACTORY method and the DISPLAY method of the CL_SALV_TABLE main class to obtain the desired ALV output.

 

The FACTORY method instantiates an object of the ALV main class. This method as a parameter where you must pass the internal table containing the data to be displayed. The display type (classic list, full screen, and in container) is also passed using a parameter of this method.

 

The FACTORY method is a static method. It returns an ALV instance and is used instead of CREATE OBJECT. You then use this instance for all other method calls relating to the ALV.

 

To call the FACTORY method, create a reference and type it with the CL_SALV_TABLE class. You also require an internal table. Fill this internal table with the data you want to display. The FACTORY method then creates the ALV instance.

 

 

 

Simplest Call – Source Code

 

The figure shows the two method calls which are needed. You can use the functional writing style for the method calls, or the longer classic CALL METHOD. Later in the lesson you will find that the functional writing style can be preferable when calling the methods of the ALV Object Model.

 

This program displays the data of the internal table in the ALV in full screen.

 

Methods for the ALV Object Model

 

The figure shows how to implement a method call easily using the Pattern function in the ABAP Editor.

 

To implement a method call of a global class, use the ABAP Objects pattern or the drag and drop function of the Object Navigator (transaction code SE80).

 

The steps to call a method statement with the ABAP Objects pattern are as follows:

  1. In the ABAP Editor, choose Pattern.
  2. On the Insert Statement screen, select the ABAP Objects Patterns radio button.
  3. On the OO Statement Pattern screen, select the Call Method radio button.
  4. In the Instance field, enter the reference variable for the object for which the method is used; if you want to generate the call of a class method, leave the field empty.
  5. In the Class/Interface field, enter the class of the object (CL_SALV_TABLE).
  6. In the Method field, enter the method name (FACTORY).

The CALL METHOD statement is inserted at the current cursor position in the source code of the program. The generated coding contains the entire signature and the required TRY and CATCH statements for exception handling. Optional parameters and exceptions are inserted as comments. In this way, you can avoid typing errors and omissions.

 

You then need to complete the actual parameters and program the exception handling.

 

Insertion of CALL METHOD by Drag and Drop

To use drag and drop, first you must display the object list of the global class (CL_SALV_TABLE) in the navigation area of the ABAP Workbench. You can then drag the method to the editing area by selecting it and holding down the left mouse button.

 

The CALL METHOD statement is inserted at the current cursor position, in the source code of the program. The generated coding contains the entire signature and the required TRY and CATCH statements for exception handling. Optional parameters and exceptions are inserted as comments.

 

You then need to complete the actual parameters and program the exception handling. In this case, the parameter and exception handling is enough because it is a call for a class method. If you want to generate the call for an instance method, for example, for the DISPLAY method from the CL_SALV_TABLE class, drag and drop will generate the method call in the format CALL METHOD xxxxxxxx->display.

 

In this case, insert the name of the correct reference variables instead of xxxxxxx.

 

 

Reference Variables