REPORT Z_ALVGRIDTESTCLICK.
TYPE-POOLS: SLIS.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF FIELDCAT,
SORTCAT TYPE SLIS_T_SORTINFO_ALV,
SORTCAT_LN LIKE LINE OF SORTCAT,
EVENTCAT TYPE SLIS_T_EVENT,
EVENTCAT_LN LIKE LINE OF EVENTCAT.
TABLES : MARA.
* Internal table for storing line item data per document number
data: begin of itab occurs 10,
MATNR like MARA-MATNR,
MTART LIKE MARA-MTART,
BISMT LIKE MARA-BISMT,
end of itab.
START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK BA WITH FRAME TITLE TTL1.
SELECT-OPTIONS: P_MATNR FOR MARA-MATNR.
SELECTION-SCREEN END OF BLOCK BA.
*&--------------------------------------------------------------------*
* INITIALIZATION.
*&--------------------------------------------------------------------*
INITIALIZATION.
ttl1 = 'Input Condition'.
*&--------------------------------------------------------------------*
* AT SELECTION-SCREEN.
*&--------------------------------------------------------------------*
AT SELECTION-SCREEN.
*&--------------------------------------------------------------------*
* START-OF-SELECTION.
*&--------------------------------------------------------------------*
START-OF-SELECTION.
* DEFINE PAGE LEFT MARGIN AND TOP MARGIN
SET MARGIN 7 5.
* DEFINE PIRNT FORMATE
PRINT-CONTROL FUNCTION: 'SABLD' LINE 1,
'SAOFF' LINE 2,
'SAULN' LINE 3.
* The above sentence print-control function used to define print format
* Find document header data and line item data from given parameters.
PERform find_document .
PERform ALVDISPLAY.
*------------------------------------------------*
* GET DATA FROM SOME SYSTEM TABLE
* THEN ,PUT THESE DATA INTO INTERNAL TABLE.
*------------------------------------------------*
form find_document .
SELECT MATNR
MTART
BISMT
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM MARA
WHERE MATNR IN P_MATNR.
endform .
*---------------ALV Disply Function ---------------------*
form alvdisplay .
DATA: COL_POS TYPE I.
DATA: PGM LIKE SY-REPID.
PGM = SY-REPID.
*Add The 1th column :company code .
ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME = 'MTART'.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.
ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME = 'MATNR'.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.
ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME = 'BISMT'.
FIELDCAT_LN-KEY = SPACE.
*DEFINE AN SUM
FIELDCAT_LN-DO_SUM = 'X'.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.
SORTCAT_LN-SPOS = '1'.
SORTCAT_LN-FIELDNAME = 'MATNR'.
SORTCAT_LN-UP = 'X'.
SORTCAT_LN-DOWN = SPACE.
SORTCAT_LN-SUBTOT = 'X'.
APPEND SORTCAT_LN TO SORTCAT.
**** Call Function to response user command event .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = PGM
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = FIELDCAT
IT_SORT = SORTCAT
I_SAVE = 'A'
"IT_EVENT = EVENTCAT
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
endform.
form USER_COMMAND USING UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
READ TABLE ITAB INDEX SELFIELD-TABINDEX.
CHECK SY-SUBRC = 0.
CASE UCOMM.
WHEN '&IC1'.
CASE SELFIELD-SEL_TAB_FIELD.
WHEN 'ITAB-MATNR'.
SET PARAMETER ID 'MAT' FIELD ITAB-MATNR.
CALL TRANSACTION 'MM43' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDform.