Sorting in ALV using CL_SALV_TABLE Class
let’s understand this concept by taking a requirement.
Requirement :-
- Use want to give a range of Sales document number as input to the selection screen and wants to see details of sales document of number from VBAK table in the descending order of Sales Document number.
Solution :-
-
Step 1 :- Create a executable program in ABAP Editor ( SE38 ).
-
Step 2 :- Create a type structure and a corresponding internal from VBAK table.
-
Step 3 :- We need to create a select option and then we will write a select query to fetch data into the internal table.
-
Step 4 :- We will call the factory method of CL_SALV_TABLE class to get the object of the class.
-
Step 5 :- Now, we need to call the method GET_SORT of CL_SALV_TABLE to get the object of CL_SALV_SORTS class.
- Here, we have got the object for our CL_SALV_SORTS class.
-
Step 6 :- Call method ADD_SORTS from CL_SALV_SORTS of class.
-
Step 7 :- then we call display method through the object of CL_SALV_TABLE class.
*&---------------------------------------------------------------------* *& Report ZAR_SORTING_FILTERING *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zar_sorting_filtering. TYPES : BEGIN OF ty_vbak, vbeln TYPE vbeln_va, erdat TYPE erdat, erzet TYPE erzet, ernam TYPE ernam, vbtyp TYPE vbtypl, END OF ty_vbak. DATA : lt_vbak TYPE TABLE OF ty_vbak. DATA : lv_vbeln TYPE vbeln_va. SELECT-OPTIONS : s_vbeln FOR lv_vbeln. START-OF-SELECTION. SELECT vbeln erdat erzet ernam vbtyp FROM vbak INTO TABLE lt_vbak WHERE vbeln IN s_vbeln. IF lt_vbak IS NOT INITIAL. TRY. CALL METHOD cl_salv_table=>factory EXPORTING list_display = if_salv_c_bool_sap=>false * r_container = * container_name = IMPORTING r_salv_table = DATA(lo_obj) CHANGING t_table = lt_vbak. CATCH cx_salv_msg. ENDTRY. CALL METHOD lo_obj->get_sorts RECEIVING value = data(lo_sorts) . TRY. CALL METHOD lo_sorts->add_sort EXPORTING columnname = 'VBELN' * position = 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 * receiving * value = . CATCH cx_salv_not_found. CATCH cx_salv_existing. CATCH cx_salv_data_error. ENDTRY. lo_obj->display( ). *&-------------------------------------------------------------------- *&End of Program *&------------------------------------------------------------------ ENDIF.
Execute this code :-
- Press F8.
- We can see above is in descending order.
Comments
Post a Comment