ALV Report with Header and Logo

Follow below steps to disply ALV Report with Header and Logo.

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.      Set ALV header with logo 

10.    display ALV report using clv object

 
 ABAP code:

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 Header **************
        DATAlr_grid  TYPE REF TO cl_salv_form_layout_grid,
        lr_logo  TYPE REF TO cl_salv_form_layout_logo,
        lr_label TYPE REF TO cl_salv_form_label,
        lr_text  TYPE REF TO cl_salv_form_text.

        DATA(lv_lineslines(  col_tab ).
        CREATE OBJECT lr_grid.

        DATA(lv_msg=  sy-title  &&   | Report Title  |.

        lr_grid->create_header_informationrow 1  column 2
                                            text lv_msg
                                            tooltip lv_msg ).
        DATA(lr_gridxlr_grid->create_gridrow 6  column 1  ).
*
*        lr_label = lr_gridx->create_label( row = 3 column = 1
*                                          text = lv_msg tooltip = lv_msg ).

        lr_label lr_gridx->create_labelrow column 1
                                           text 'Run Date:' tooltip 'Run Date' ).
        lr_text  lr_gridx->create_text(  row column 2
                                           text sy-datum  tooltip sy-datum ).
        lr_label lr_gridx->create_labelrow column 1
                                           text 'Run Time:' tooltip 'Run Time' ).
        lr_text  lr_gridx->create_text(  row column 2
                                           text sy-uzeit tooltip sy-uzeit ).
        lr_label lr_gridx->create_labelrow column 1
                                           text 'Total Records:' tooltip 'Total Records' ).
        lr_text  lr_gridx->create_text(  row column 2
                                           text lv_lines tooltip lv_lines ).

*       Create logo layout, set grid content on left and logo image on right
        CREATE OBJECT lr_logo.
        lr_logo->set_left_contentlr_grid ).
*      *****
        lr_logo->set_right_logo'ENJOYSAP_LOGO' ).

*       Set element top_of_list
        alv->set_top_of_listlr_logo ).



        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:


 
 


1 comment:

Code Inspector

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