REPORT z_demo_alv_refresh_button_3.
*>*********************************************************************
* This report reads and displays data from table MARA. *
* Each time, the refresh button is pressed, the next 25 records are *
* read and displayed. *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*>*********************************************************************
SELECTION-SCREEN : BEGIN OF LINE,COMMENT 10(20) v_1 FOR FIELD p_max.
PARAMETERS p_max(2) TYPE n DEFAULT '25' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
TYPE-POOLS: slis. " ALV Global types
CONSTANTS :
gc_refresh TYPE syucomm VALUE '&REFRESH'.
DATA:
BEGIN OF gt_mara OCCURS 0,
matnr LIKE mara-matnr, " Material number
ernam LIKE mara-ernam, " Name of Person who Created
ersda LIKE mara-ersda, " Creation date
brgew LIKE mara-brgew, " Gross weight
END OF gt_mara.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'Lines per page'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.
STATICS l_mara TYPE matnr. " Last Material number
DATA lt_mara LIKE gt_mara OCCURS 0 WITH HEADER LINE.
* Read next 25 records
SELECT mandt matnr ernam ersda brgew
INTO CORRESPONDING FIELDS OF TABLE lt_mara
FROM mara
UP TO p_max ROWS
WHERE matnr GT l_mara
ORDER BY PRIMARY KEY. "#EC PORTABLE
IF sy-subrc EQ 0.
MESSAGE s208(00) WITH 'Reading data ...'.
DESCRIBE TABLE gt_mara.
READ TABLE lt_mara INDEX sy-tfill.
* Save last Material number
l_mara = lt_mara-matnr.
gt_mara[] = lt_mara[].
ELSE.
MESSAGE i208(00) WITH 'Nothing to read ... '.
ENDIF.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = 'MARA'.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DATA :
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit.
* Build Sort table
m_sort 'MATNR'.
* Build Field Catalog
m_fieldcat 'MATNR'.
m_fieldcat 'ERNAM'.
m_fieldcat 'ERSDA'.
m_fieldcat 'BRGEW'.
CLEAR ls_event_exit.
ls_event_exit-ucomm = gc_refresh. " Refresh
ls_event_exit-after = 'X'.
APPEND ls_event_exit TO lt_event_exit.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_pf_status_set = 'PF_STATUS_SET'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = lt_fieldcat
it_sort = lt_sort
it_event_exit = lt_event_exit
TABLES
t_outtab = gt_mara.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm LIKE sy-ucomm
us_selfield TYPE slis_selfield. "#EC CALLED
CASE u_ucomm.
WHEN gc_refresh.
PERFORM f_read_data. " Refresh data
us_selfield-refresh = 'X'.
us_selfield-col_stable = 'X' .
us_selfield-row_stable = 'X' .
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* FORM PF_STATUS_SET *
*---------------------------------------------------------------------*
FORM pf_status_set USING ut_extab TYPE slis_t_extab. "#EC CALLED
DELETE ut_extab WHERE fcode = gc_refresh.
SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING ut_extab.
ENDFORM. " PF_STATUS_SET
******** END OF PROGRAM Z_DEMO_ALV_REFRESH_BUTTON_3 *******************
유용하게 사용하겠습니다. 감사합니다^^