Display Setting in ALV using CL_SALV_TABLE

0
4600

In this tutorial, we will learn how to change the display settings like stripped pattern, remove horizontal lines etc. in OO ALV using CL_SALV_TABLE.

CL_SALV_DISPLAY_SETTINGS is the class used to apply display settings in ALV.

Stripped Pattern in ALV

To get Stripped pattern in ALV report, call the method  SET_STRIPED_PATTERN() in class CL_SALV_DISPLAY_SETTINGS.

alv4

Remove Horizontal Lines in ALV

To remove horizontal lines in ALV report, call the method  SET_HORIZONTAL_LINES() in class CL_SALV_DISPLAY_SETTINGS.

alv5

Remove Vertical Lines in ALV

To remove Vertical lines  in ALV report, call the method  SET_VERTICAL_LINES() in class CL_SALV_DISPLAY_SETTINGS.

alv4

ABAP Source Code

Below ABAP source code for above all options in OO ABAP ALV.

*----------------------------------------------------------------------*
*      Display Settings in ALV report using factory class CL_SALV_TABLE*
*----------------------------------------------------------------------*
*                    www.saplearners.com                               *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
*       CLASS lcl_sflight DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_sflight DEFINITION.

  PUBLIC SECTION.
    TYPES: BEGIN OF lty_sflight,
           carrid	         TYPE s_carr_id,
           connid	         TYPE s_conn_id,
           fldate	         TYPE s_date,
           price           TYPE s_price,
           currency	       TYPE s_currcode,
           planetype       TYPE s_planetye,
           seatsmax	       TYPE s_seatsmax,
           seatsocc	       TYPE s_seatsocc,
           END OF lty_sflight.

    METHODS: get_sflight_data,
             get_alv_instance,
             display.

    DATA: lo_alv      TYPE REF TO cl_salv_table,
          gt_sflight TYPE STANDARD TABLE OF lty_sflight.

ENDCLASS.                    "lcl_sflight DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_sflight IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_sflight IMPLEMENTATION.

* Get SFLIGHT data
  METHOD get_sflight_data.
    SELECT carrid connid fldate price currency planetype seatsmax
           seatsocc INTO TABLE me->gt_sflight
                    FROM sflight
                    WHERE carrid IN ('AA', 'JL' ).
  ENDMETHOD.                    "get_sflight_data

* Get ALV instance
  METHOD get_alv_instance.
    TRY.
        CALL METHOD cl_salv_table=>factory
          IMPORTING
            r_salv_table = lo_alv
          CHANGING
            t_table      = gt_sflight.
      CATCH cx_salv_msg.
    ENDTRY.

  ENDMETHOD.                    "get_alv_instance

* Display ALV
  METHOD display.
    CALL METHOD lo_alv->display.
  ENDMETHOD.                    "display
ENDCLASS.                    "lcl_sflight IMPLEMENTATION



START-OF-SELECTION.
  DATA: lo_cl_sflight     TYPE REF TO lcl_sflight,
        lo_display_settings TYPE REF TO cl_salv_display_settings.

  CREATE OBJECT lo_cl_sflight.

* Get the Data for ALV report
  lo_cl_sflight->get_sflight_data( ).

* Get ALV instance
  lo_cl_sflight->get_alv_instance( ).

  CALL METHOD lo_cl_sflight->lo_alv->get_display_settings
    RECEIVING
      value = lo_display_settings.

*------ Set Striped Pattern ----------
  CALL METHOD lo_display_settings->set_striped_pattern
    EXPORTING
      value = abap_true.

*---- No Horizontal Lines in ALV report ---------------
  CALL METHOD lo_display_settings->set_horizontal_lines
    EXPORTING
      value = abap_false.

*---- No Vertical Lines in ALV report ------------------
  CALL METHOD lo_display_settings->set_vertical_lines
    EXPORTING
      value = abap_false.

* Display ALV report
  lo_cl_sflight->display( ).

mail

SAPLearners.com is now on Telegram. Click here to join our channel and stay updated with the latest tutorials and updates.

Like us on Facebook and follow us on Twitter.