Wednesday, 14 March 2018

Classic ALV ( Set Column Hide / Visible )




 Set column ( Hide / Visible)  classic ALV Report.

  Steps to create classic ALV report are below.

1.      create an executable ABAP program YUA_ALV_REPORT using transaction SE38.

2.      create local class demo

3.      declare TYPES in private section of class definition

4.      declare static internal table in private section of class definition

5.      declare main method in public section of class definition

6.      implement main method of demo class

7.      retrieve data into internal table inside main method

8.      create alv object for class cl_salv_table

9.      display ALV report using clv object

 

Sample code demonstarates how to hide colums in classic ALV report 
 

 



 
REPORT yua_alv_report.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    TYPESBEGIN OF ty_data,
            carrid  TYPE  s_carr_id,
            carrname  TYPE    s_carrname,
            currcode  TYPE  s_currcode,
            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,
            paymentsum TYPE  s_sum,
            seatsmax_b   TYPE  s_smax_b,
            seatsocc_b  TYPE  s_socc_b,
            seatsmax_f TYPE  s_smax_f,
            seatsocc_f TYPE  s_socc_f,
            url TYPE   s_carrurl,
           END OF ty_data.
    CLASS-DATA  t_data TYPE TABLE OF ty_data.

ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

    SELECT  b~carrid
            b~carrname
            b~currcode
            a~connid
            a~fldate
            a~price
            a~currency
            a~planetype
            a~seatsmax
            a~seatsocc
            a~paymentsum
            a~seatsmax_b
            a~seatsocc_b
            a~seatsmax_f
            a~seatsocc_f
            b~url
           FROM sflight as  a
             INNER JOIN scarr as  b
            ON a~carrid b~carrid
           INTO TABLE t_data.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table t_data ).

        DATA(columnsalv->get_columns).
        DATA(col_tabcolumns->get).
        LOOP AT col_tab ASSIGNING FIELD-SYMBOL(<column>).
          <column>-r_column->set_output_length40 ).
          IF <column>-columnname EQ 'CARRID' OR <column>-columnname 'CARRNAME' OR
             <column>-columnname 'URL'.
            <column>-r_column->set_visible'X' ).
          ELSE.
            <column>-r_column->set_visible' ' ).
          ENDIF.
        ENDLOOP.


        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  demo=>main).
 
 




Output generated as below:

 

No comments:

Post a Comment

Code Inspector

The Code Inspector tests single objects or object sets (programs, function groups, classes, interfaces, Dictionary objects) for performanc...