Top of page & End of list code example
Example: Top of page & End of list
REPORT ZALV_MATERIAL_TOP_OF_PAGE.
TYPE-POOLS : SLIS .
*DATA DECLARAATIONS
DATA : I_MARA TYPE TABLE OF MARA .
DATA : WA_MARA TYPE MARA .
*ALV DECLARATIONS
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV .
DATA : V_POS TYPE I .
DATA : I_EVENTS TYPE SLIS_T_EVENT .
DATA : WA_EVENTS LIKE LINE OF I_EVENTS .
DATA : I_HEADING TYPE SLIS_T_LISTHEADER .
DATA : WA_HEADING LIKE LINE OF I_HEADING .
START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT .
PERFORM GET_EVENTS .
PERFORM DISPLAY_DATA .
END-OF-SELECTION .
FORM GET_DATA .
SELECT * FROM MARA
INTO TABLE I_MARA
UP TO 100 ROWS .
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = I_FCAT
IT_EVENTS = I_EVENTS
TABLES
T_OUTTAB = I_MARA.
ENDFORM. " DISPLAY_DATA
FORM CREATE_FCAT .
V_POS = 1 .
WA_FCAT-COL_POS = V_POS.
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-SELTEXT_M = 'Material.NO' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-SELTEXT_M = 'Material.Type' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-SELTEXT_M = 'Ind.Sector' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MATKL' .
WA_FCAT-SELTEXT_M = 'Mat.Grp' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-SELTEXT_M = 'Units' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
ENDFORM. " CREATE_FCAT
FORM GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS .
READ TABLE I_EVENTS INTO WA_EVENTS WITH KEY NAME = 'TOP_OF_PAGE' .
WA_EVENTS-FORM = 'FORM_TOP_OF_PAGE' .
MODIFY I_EVENTS FROM WA_EVENTS INDEX SY-TABIX .
***********END OF LIST
READ TABLE I_EVENTS INTO WA_EVENTS WITH KEY NAME = 'END_OF_LIST' .
WA_EVENTS-FORM = 'FORM_END_OF_LIST' .
MODIFY I_EVENTS FROM WA_EVENTS INDEX SY-TABIX .
ENDFORM. " GET_EVENTS
FORM FORM_TOP_OF_PAGE .
WA_HEADING-TYP = 'H' .
* WA_HEADING-KEY = 'H' .
WA_HEADING-INFO = 'MATERIAL MASTER REPORT' .
APPEND WA_HEADING TO I_HEADING .
WA_HEADING-TYP = 'S' .
WA_HEADING-KEY = 'USERNAME' .
WA_HEADING-INFO = SY-UNAME .
APPEND WA_HEADING TO I_HEADING .
WA_HEADING-TYP = 'A' .
WA_HEADING-KEY = 'DATE' .
WA_HEADING-INFO = SY-DATUM .
APPEND WA_HEADING TO I_HEADING .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_HEADING
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM . "FORM_TOP_OF_PAGE
FORM FORM_END_OF_LIST .
REFRESH I_HEADING .
CLEAR WA_HEADING .
WA_HEADING-TYP = 'S' .
WA_HEADING-INFO = 'IBM INDIA PVT.LTD' .
APPEND WA_HEADING TO I_HEADING .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_HEADING
I_END_OF_LIST_GRID = 'X'
.
ENDFORM . "FORM_END_OF_LIST