Professional Documents
Culture Documents
Community WIKI SAP Community Welcome, Guest Login Register Search the Community
ALV Grid Report - with Object Oriented SALV Classes Useful Information
ALV Grid Report using Object Oriented
Summary Programming Concept
This Post narrates the sample code for creating ALV Grid Report with Object Oriented method. Basic Functionalities for ALV Grid display is attained
using different SALV Classes.
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 1/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 2/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
Sample Code
*&---------------------------------------------------------------------*
*& Report ZVK_CL_SALV
*&---------------------------------------------------------------------*
*&Report using OOPs with Basic functionalities.
*&---------------------------------------------------------------------*
REPORT zvk_cl_salv_1.
TABLES : vbak.
TYPE-POOLS : abap,rsanm.
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 3/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
** Class for handling Events
CLASS : lcl_handle_events DEFINITION DEFERRED.
DATA : gr_events TYPE REF TO lcl_handle_events,
lr_events TYPE REF TO cl_salv_events_table.
START-OF-SELECTION.
REFRESH : lt_vbak.
SELECT * FROM vbak
INTO CORRESPONDING FIELDS OF TABLE lt_vbak
WHERE erdat IN p_erdat.
IF sy-subrc EQ 0.
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 4/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
DESCRIBE TABLE lt_vbak LINES l_rec.
PERFORM set_color.
PERFORM alv_grid_display.
ENDIF.
*&---------------------------------------------------------------------*
*& Form alv_grid_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_grid_display.
CLEAR : gr_table.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_vbak.
CATCH cx_salv_msg .
ENDTRY.
IF gr_table IS INITIAL.
MESSAGE 'Error Creating ALV Grid ' TYPE 'I' DISPLAY LIKE 'E'.
STOP.
ENDIF.
** Get functions details
gr_functions = gr_table->get_functions( ).
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 5/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
ENDTRY.
TRY.
gr_sort->add_sort( columnname = 'ERDAT'
position = 2
sequence = if_salv_c_sort=>sort_down
subtotal = if_salv_c_bool_sap=>false
group = if_salv_c_sort=>group_none
obligatory = if_salv_c_bool_sap=>false ).
CATCH cx_salv_not_found .
CATCH cx_salv_existing .
CATCH cx_salv_data_error .
ENDTRY.
ENDIF.
******* Table Selection Settings *******
gr_select = gr_table->get_selections( ).
IF gr_select IS NOT INITIAL.
gr_select-
>set_selection_mode( if_salv_c_selection_mode=>row_column ). "Allow single row Selection"
ENDIF.
*&---------------------------------------------------------------------*
*& Form column_settings
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM column_settings.
LOOP AT lt_column_ref INTO ls_column_ref.
TRY.
gr_column ?= gr_columns->get_column( ls_column_ref-columnname ).
CATCH cx_salv_not_found.
ENDTRY.
IF gr_column IS NOT INITIAL.
** Make Mandt column invisible **
IF gr_column->get_ddic_datatype( ) = 'CLNT'.
gr_column->set_technical( if_salv_c_bool_sap=>true ).
ENDIF.
** Create Aggregate function total for All Numeric/Currency Fields **
IF gr_column->get_ddic_inttype( ) EQ 'P' OR
gr_column->get_ddic_datatype( ) EQ 'CURR'.
IF gr_aggr IS NOT INITIAL.
TRY.
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 6/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
gr_aggr->add_aggregation( columnname = ls_column_ref-columnname
aggregation = if_salv_c_aggregation=>total ).
CATCH cx_salv_data_error .
CATCH cx_salv_not_found .
CATCH cx_salv_existing .
ENDTRY.
ENDIF.
ENDIF.
** Create Check box for fields with domain "XFELD"
IF gr_column->get_ddic_domain( ) EQ 'XFELD'.
gr_column->set_cell_type( if_salv_c_cell_type=>checkbox ).
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. "column_settings
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page CHANGING lr_content TYPE REF TO cl_salv_form_element.
DATA : lr_grid TYPE REF TO cl_salv_form_layout_grid,
lr_text TYPE REF TO cl_salv_form_text,
lr_label TYPE REF TO cl_salv_form_label,
lr_head TYPE string.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 7/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
FORM get_ord_info USING row TYPE salv_de_row
column TYPE salv_de_column.
IF column EQ 'VBELN'.
CLEAR : ls_vbak.
READ TABLE lt_vbak INTO ls_vbak INDEX row.
IF sy-subrc EQ 0.
SET PARAMETER ID 'AUN' FIELD ls_vbak-vbeln.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
ENDFORM. "get_ord_info
*&---------------------------------------------------------------------*
*& Form set_color
*&---------------------------------------------------------------------*
* Set color to the column VBELN & NETWR for Order Value > 1000
*----------------------------------------------------------------------*
FORM set_color.
LOOP AT lt_vbak ASSIGNING .
IF -netwr GT 1000.
REFRESH : lt_color.
CLEAR : ls_color.
MOVE 'VBELN' TO ls_color-fname.
MOVE 3 TO ls_color-color-col.
MOVE 0 TO ls_color-color-int.
MOVE 0 TO ls_color-color-inv.
APPEND ls_color TO lt_color.
CLEAR : ls_color.
MOVE 'NETWR' TO ls_color-fname.
MOVE 3 TO ls_color-color-col.
MOVE 0 TO ls_color-color-int.
MOVE 0 TO ls_color-color-inv.
APPEND ls_color TO lt_color.
Remarks
Select Query used for this report is only for representational purpose. Performance of the query is not taken into consideration.
salv cl_salv_table ooabap alv grid
1 Child Page
using FACTORY method
9 Comments
Keshav.T
Hi Vinod,
It should be better if you add the basic things like Header logo , end of list etc.
Keshav
Vinod Kumar
Keshav, Thanks for your suggestion.
Vinod
Guest
Thank you for the summary. Is there a possibility to change the color of a row? Would be nice if you could add the class and method.
regards, Patrick
Guest
Very helpful example.
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 8/9
6/6/2018 ALV Grid Report - with Object Oriented SALV Classes - ABAP Development - SCN Wiki
Former Member
I want to include a little info to this good example.
Here is the coding for setting up the logo in the Top Of Page of the ALV and I have included End of List
as well.Content in the End of List is exactly similar to the Content created on the Top Of List.
****Setting Up Logo*******
FORM top_of_page CHANGING lr_content TYPE REF TO cl_salv_form_element.
DATA: lr_picture TYPE REF TO cl_salv_form_picture.
CREATE OBJECT lr_picture.
lr_picture->set_picture_id( 'LOGO_NAME' ).
lr_grid->set_element( row = 3 column = 1 r_element = lr_picture ) .
ENDFORM.
Sijin Sij
Hello ,
Very thanks for this really valuable document for learning ALV using ABAP OO.
I was googling for adding All Buttons in Tool Bar of ALV using OO approach and got my answer by referring your post.
Former Member
This example is incomplete. If you copy and paste it into the workbench there are variables missing and compile/activation issues.
Former Member
Good example, however you should have posted a working code.
Former Member
Hi Vinod ,
How Can We Provide DropDown In SALV Output SET_CELL_TYPE = DROPDOWN is not working is there anything to do after this and also how can we provide values to the
dropdown box
https://wiki.scn.sap.com/wiki/display/ABAP/ALV+Grid+Report+-+with+Object+Oriented+SALV+Classes 9/9