TYPE-POOLS: SLIS.
TABLES: MARA.
DATA: BEGIN OF IT_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MATKL LIKE MARA-MATKL,
END OF IT_MARA.
DATA: IT_FIELD_CAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELD_CAT TYPE SLIS_FIELDCAT_ALV,
IT_EVENTS TYPE SLIS_T_EVENT,
WA_EVENTS TYPE SLIS_ALV_EVENT,
IT_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM BUILD_FIELD_CAT.
PERFORM GET_EVENTS.
PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT MATNR
MTART
MATKL
FROM MARA
INTO TABLE IT_MARA
WHERE MATNR IN S_MATNR.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form build_field_cat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BUILD_FIELD_CAT .
CLEAR WA_FIELD_CAT.
WA_FIELD_CAT-COL_POS = 1.
WA_FIELD_CAT-FIELDNAME = 'MATNR'.
WA_FIELD_CAT-SELTEXT_L = 'Material Number'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
WA_FIELD_CAT-COL_POS = 2.
WA_FIELD_CAT-FIELDNAME = 'MTART'.
WA_FIELD_CAT-SELTEXT_L = 'Material Type'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
WA_FIELD_CAT-COL_POS = 3.
WA_FIELD_CAT-FIELDNAME = 'MATKL'.
WA_FIELD_CAT-SELTEXT_L = 'Material Group'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
ENDFORM. " build_field_cat
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FIELD_CAT
IT_EVENTS = IT_EVENTS
TABLES
T_OUTTAB = IT_MARA.
ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form get_events
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
ET_EVENTS = IT_EVENTS .
READ TABLE IT_EVENTS INTO WA_EVENTS
WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.
IF SY-SUBRC = 0.
WA_EVENTS-FORM = 'TOP_OF_PAGE'.
MODIFY IT_EVENTS FROM WA_EVENTS INDEX SY-TABIX.
ENDIF.
ENDFORM. " get_events
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'Material Data'.
APPEND WA_HEADER TO IT_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_HEADER.
ENDFORM. "top_of_page
ALSO READ:
- Double Click On ALV Grid/List Report.
- ALV Interactive (Double Clicking).
- Simple Example On How To Display Table Data In ALV Grid/List Display.
- Change Of ALV Grid/ List Layout (VARIANT).
..... Back To Index On ALV List/ Grid Display.
..... Back To MAIN INDEX.
Good Article
ReplyDelete