Skip to Content

Why

When using the ALV class CL_SALV_TABLE you always have to type some code that is the same for every ALV. I have created an ALV wrapper class for this that is really simple and fast to use. You only have to insert the global class ZCL_ALV_OM and you can build fast and easy ALV’s.

Setup

You can add the class ZCL_ALV_OM with the program SAPLINK
The link to the class is: ZCL_ALV_OM

Because SAPLINK does not provide export of a class textpool, you can insert your own message in the class textpool.

Class textpool

Simple example

Example for the most simple way to create an ALV:

DATA lt_sflight   TYPE TABLE OF sflight.

DATA lo_alv       TYPE REF TO zcl_alv_om.


“Get sflight data to insert in ALV

SELECT *  FROM  sflight

          INTO  TABLE lt_sflight

          WHERE carrid = ‘AA’.


“Create and display ALV

CREATE OBJECT lo_alv.

lo_alv->set_data( CHANGING ct_data = lt_sflight ).

lo_alv->display( ).

Advanced example

Example with advanced ALV options.
First create the local class LCL_ALV_OM that is inherited from the global class ZCL_ALV_OM and redefine the methods you want to use

*———————————————————————-*

* CLASS lcl_alv_om DEFINITION

*———————————————————————-*

CLASS lcl_alv_om DEFINITION INHERITING FROM zcl_alv_om.

  PROTECTED SECTION.

    METHODS set_header      REDEFINITION.

    METHODS set_column      REDEFINITION.

    METHODS on_double_click REDEFINITION.

ENDCLASS.                    “lcl_alv_om DEFINITION


*———————————————————————-*

* CLASS lcl_alv_om IMPLEMENTATION

*———————————————————————-*

CLASS lcl_alv_om IMPLEMENTATION.

  “Set header

  METHOD set_header.

    io_header->create_text( EXPORTING row     = 1

                                      column  = 1

                                      text    = ‘Test’ ).

  ENDMETHOD.                    “set_header


 
“Set column

  METHOD set_column.

    IF  iv_column_name <> ‘CARRID’

    AND iv_column_name <> ‘CONNID’

    AND iv_column_name <> ‘FLDATE’.

      io_column->set_visible( value = abap_false ).

    ENDIF.

  ENDMETHOD.                    “set_column


 
“On double click

  METHOD on_double_click.

    “Do something. You have the row data in variable is_row_data

  ENDMETHOD.                    “on_double_click

ENDCLASS.                    “lcl_alv_om IMPLEMENTATION

Then create and display the ALV

DATA lt_sflight   TYPE TABLE OF sflight.

DATA lo_alv       TYPE REF TO lcl_alv_om.


“Get sflight data to insert in ALV

SELECTFROM  sflight

          INTO  TABLE lt_sflight

          WHERE carrid = ‘AA’.


“Create and display ALV

CREATE OBJECT lo_alv

       EXPORTING  iv_double_click  = abap_true.


lo_alv->set_data(
CHANGING ct_data = lt_sflight ).

lo_alv->display( ).

UML

UML

Regards,

Robin Vleeschhouwer
RV SAP Consultancy

DATA lt_sflight   TYPE TABLE OF sflight.

DATA lo_alv       TYPE REF TO zcl_alv_om.

“Get sflight data to insert in ALV

SELECT *  FROM  sflight

          INTO  TABLE lt_sflight

          WHERE carrid = ‘AA’.

         

“Create and display ALV

CREATE OBJECT lo_alv.

lo_alv->set_data( CHANGING ct_data = lt_sflight ).

lo_alv->display( ).

To report this post you need to login first.

14 Comments

You must be Logged on to comment or reply to a post.

  1. Rich Heilman
    Just wanted to let you know that we have added code to the core class plugin for saplink to handle class text pools. So in the next release of saplink, this will be supported.

    Regards,
    Rich Heilman

    (0) 
    1. Robin Vleeschhouwer Post author
      Hi Yoshitaka,

      There are two ways to display an ALV
      1: Fullscreen
      2: In a container

      When you display the ALV in fullscreen create a GUI-status or copy the GUI-status SALV_TABLE_STANDARD from function group SALV_METADATA_STATUS.
      Then redefine the method SET_TOOLBAR

      Example:
      METHOD set_toolbar.
      * GUI-STATUS
        go_alv->set_screen_status(
          report    = sy-repid
          pfstatus  = ‘STATUS_NAME’ ).
      ENDMETHOD.

      ————————————

      When you display the ALV in a container you just have to redefine the function SET_TOOLBAR and you will get the variable IO_FUNCTIONS of type CL_SALV_FUNCTIONS.

      Example:
      METHOD set_toolbar.
        TRY.
          io_functions->add_function(
            EXPORTING name     = ‘BTN’
                      text     = ‘Button’
                      tooltip  = ‘Button’
                      position = 1 ).
          CATCH cx_root.
        ENDTRY.
      ENDMETHOD.

      I hope this answers your question.

      Regards Robin

      (0) 
    1. Robin Vleeschhouwer Post author
      Hi Eric,

      Thanks for your reply.
      I have tested the ALV in background, but it works fine. It could be possible that the spool error is not related to the ALV.

      When searching on SDN for spool errors there are several solutions. For example: SPOOL_INTERNAL_ERROR

      Regards, Robin

      (0) 
  2. Lui Di Matteo
    Hi Robin,

    This is very useful code and I have implemented already in some of my development work. 

    The only thing I am not clear on is how to use and implement methods on_double_click, on_link_click, and on_added _function.  Is it possible for you to provide some example?

    Much appreciated.
    Thanks!

    (0) 
  3. David Mattice
    Thanks for putting this together, I have been looking for a better way to hide the complexity of the ALV, this has given me some good ideas that I am going to start with. I am still learning oo, this will be of great help.
    (0) 

Leave a Reply