Posted: Sat Jan 26, 2008 5:00 pm Post subject: Buttons to display First, Prev. Next, Last records
Code:
REPORT z_alv_grid_ctrl_refresh_2.
***********************************************************************
* ALV Grid Control *
* This report reads and displays data from table MARA, using *
* the Method set_table_for_first_display of CL_GUI_ALV_GRID *
* Button 'NEXT_PAGE' : displays the next N records *
* Button 'PREV_PAGE' : displays the previous N records *
* Button 'FIRST_PAGE' : displays the first page *
* Button 'LAST_PAGE' : displays the last page *
* When the buttons Sort up, sort down, Filter, Delete Filter are *
* pressed, N record are still displayed *
*---------------------------------------------------------------------*
* Steps : *
* - Create the report Z_ALV_GRID_CTRL_REFRESH_2 *
* - Create the Dynpro 0100 (size 27x120) *
* - Add OKCODE (type OK) in the element list *
* - Modify the flow logic of dynpro 0100 : *
* * PROCESS BEFORE OUTPUT. *
* MODULE pbo_0100. *
* * PROCESS AFTER INPUT. *
* MODULE user_command_0100. *
* - Create a status named 'MAIN' *
* with the buttons : REFRESH BACK EXIT *
* and the buttons : FIRST_PAGE PREV_PAGE NEXT_PAGE LAST_PAGE *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : [email protected] HomePage : http://www.geocities.com/mpioud *
***********************************************************************
CONSTANTS:
c_first_page TYPE syucomm VALUE 'FIRST_PAGE',
c_next_page TYPE syucomm VALUE 'NEXT_PAGE',
c_prev_page TYPE syucomm VALUE 'PREV_PAGE',
c_last_page TYPE syucomm VALUE 'LAST_PAGE'.
TYPES:
BEGIN OF ty_s_mara,
ernam LIKE mara-ernam,
matnr LIKE mara-matnr,
ersda LIKE mara-ersda,
brgew LIKE mara-brgew,
END OF ty_s_mara.
CLASS lcl_event_alv DEFINITION DEFERRED.
DATA:
gt_mara TYPE STANDARD TABLE OF ty_s_mara,
go_container TYPE REF TO cl_gui_docking_container,
go_alv_grid TYPE REF TO cl_gui_alv_grid,
go_events TYPE REF TO lcl_event_alv,
gt_mara_ftr TYPE STANDARD TABLE OF ty_s_mara, " Data filtered
gt_mara_all TYPE STANDARD TABLE OF ty_s_mara, " Data readfrom DB
okcode TYPE syucomm,
gv_okcode TYPE syucomm.
*---------------------------------------------------------------------*
* CLASS lcl_event_alv DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_alv DEFINITION.
PUBLIC SECTION.
METHODS:
h_user_command FOR EVENT after_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm
sender.
ENDCLASS. " LCL_EVENT_ALV DEFINITION
*---------------------------------------------------------------------*
* Class (Implementation) lcl_event_alv
*---------------------------------------------------------------------*
CLASS lcl_event_alv IMPLEMENTATION.
METHOD h_user_command.
CASE e_ucomm.
WHEN '&SORT_ASC' OR '&SORT_DSC'. " Sort
PERFORM f_sort_big_table.
PERFORM f_read_data USING c_first_page.
PERFORM f_refresh_table.
WHEN '&FILTER'. " Filter
PERFORM f_filter_data.
PERFORM f_read_data USING c_first_page.
PERFORM f_refresh_table.
WHEN '&DELETE_FILTER'. " Delete filter
gt_mara_ftr[] = gt_mara_all[].
PERFORM f_read_data USING c_first_page.
PERFORM f_refresh_table.
ENDCASE.
ENDMETHOD. " user_command
ENDCLASS. " LCL_EVENT_ALV
*---------------------------------------------------------------------*
SELECTION-SCREEN :
BEGIN OF LINE,COMMENT 10(20) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
*---------------------------------------------------------------------*
INITIALIZATION.
CASE gv_okcode.
WHEN 'BACK'.
SET SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN c_first_page OR c_next_page OR c_last_page OR c_prev_page.
PERFORM f_read_data USING gv_okcode. " Update gt_mara
PERFORM f_refresh_table.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_read_data USING u_ucomm TYPE syucomm.
STATICS :
l_1 TYPE sytabix,
l_2 TYPE sytabix.
DATA l_max TYPE sytabix. " Internal table size
DESCRIBE TABLE gt_mara_ftr LINES l_max.
CASE u_ucomm.
WHEN c_first_page. " 1st page
l_1 = 1.
WHEN c_prev_page. " Previous page
SUBTRACT p_max FROM l_1.
IF l_1 < 1.
l_1 = 1.
ENDIF.
WHEN c_next_page. " Next page
IF l_1 IS INITIAL.
l_1 = 1.
ELSE.
ADD p_max TO l_1.
ENDIF.
IF l_1 > l_max.
l_1 = l_max.
ENDIF.
WHEN c_last_page. " Last page
l_1 = l_max - p_max + 1.
IF l_1 < 1.
l_1 = 1.
ENDIF.
ENDCASE.
l_2 = l_1 + p_max - 1.
IF l_2 > l_max.
l_2 = l_max.
ENDIF.
REFRESH gt_mara.
IF l_max > 0.
APPEND LINES OF gt_mara_ftr FROM l_1
TO l_2
TO gt_mara.
ENDIF.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form create_and_init_alv
*---------------------------------------------------------------------*
FORM create_and_init_alv.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_alv_cat-col_pos.
ls_alv_cat-fieldname = &1.
ls_alv_cat-ref_table = 'MARA'.
append ls_alv_cat to lt_alv_cat.
END-OF-DEFINITION.
DATA:
ls_variant TYPE disvariant,
lt_alv_cat TYPE lvc_t_fcat,
ls_alv_cat TYPE lvc_s_fcat,
ls_alv_lay TYPE lvc_s_layo,
l_offline TYPE char1.
IF l_offline EQ 0.
CREATE OBJECT go_container
EXPORTING
extension = 2000
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
IF sy-subrc NE 0.
MESSAGE e208(00) WITH 'The control could not be created'.
ENDIF.
ENDIF.
* Create an instance of alv control
CREATE OBJECT go_alv_grid
EXPORTING i_parent = go_container.
CREATE OBJECT go_events.
SET HANDLER go_events->h_user_command FOR go_alv_grid.
ENDFORM. " CREATE_AND_INIT_ALV
*---------------------------------------------------------------------*
* Form F_REFRESH_TABLE
*---------------------------------------------------------------------*
FORM f_refresh_table.
ENDFORM. " F_REFRESH_TABLE
*---------------------------------------------------------------------*
* Form F_SORT_BIG_TABLE
*---------------------------------------------------------------------*
FORM f_sort_big_table.
DATA:
lt_sort_kkblo TYPE kkblo_t_sortinfo,
lt_sort TYPE lvc_t_sort.
* Format LVC --> KKBLO
CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
EXPORTING
it_sort_lvc = lt_sort
IMPORTING
et_sort_kkblo = lt_sort_kkblo.
* The big tables must be sorted like the small one
PERFORM fb_outtab_sort(saplkkbl) TABLES gt_mara_ftr
lt_sort_kkblo
USING 'X'
'X'.
PERFORM fb_outtab_sort(saplkkbl) TABLES gt_mara_all
lt_sort_kkblo
USING 'X'
'X'.
ENDFORM. " F_SORT_BIG_TABLE
*---------------------------------------------------------------------*
* Form f_filter_data
*---------------------------------------------------------------------*
FORM f_filter_data.
DATA:
lt_filter_lvc TYPE lvc_t_filt,
lt_filter_index TYPE lvc_t_fidx WITH HEADER LINE.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.