TYPES : BEGIN OF MAT,

        MATNR TYPE MARA-MATNR,
        ERNAM TYPE MARA-ERNAM,
        ERSDA TYPE MARA-ERSDA,
      END OF MAT.

DATA : WA_MAT TYPE MAT,
       IT_MAT TYPE TABLE OF MAT,
       OK_CODE TYPE SY-UCOMM,
       O_CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
       O_ALV TYPE REF TO CL_GUI_ALV_GRID,
       IT_FCAT TYPE LVC_T_FCAT,
       WA_FCAT TYPE LVC_S_FCAT.



 DATA : IT_MAKT TYPE TABLE OF MAKT.
 DATA : O_DOCK TYPE REF TO CL_GUI_DOCKING_CONTAINER,
        O_ALV1 TYPE REF TO CL_GUI_ALV_GRID.

 SELECT-OPTIONS : S_MATNR FOR WA_MAT-MATNR.

CLASS HANDLE_EVENT DEFINITION.

   PUBLIC SECTION.

   CLASS-METHODS : HANDLE_DOUBLE_CLICK
                  FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                  IMPORTING E_ROW.

 ENDCLASS.

CLASS HANDLE_EVENT IMPLEMENTATION.
   METHOD HANDLE_DOUBLE_CLICK.

     READ TABLE IT_MAT INTO WA_MAT INDEX E_ROW.
     SELECT * FROM MAKT INTO TABLE IT_MAKT WHERE MATNR = WA_MAT-MATNR.
      CALL SCREEN 200.
   ENDMETHOD.

 ENDCLASS.

START-OF-SELECTION.
 PERFORM FETCH_DATA.

 PERFORM FIELDCAT.

 CALL SCREEN 100.

FORM FETCH_DATA .

SELECT MATNR ERNAM ERSDA FROM MARA INTO TABLE
  IT_MAT WHERE MATNR IN S_MATNR.


ENDFORM. 

FORM FIELDCAT .

  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 1.
  WA_FCAT-FIELDNAME = 'MATNR'.
  WA_FCAT-SELTEXT = 'MATERIAL NUMBER'.
  WA_FCAT-OUTPUTLEN = 18.

  APPEND WA_FCAT TO IT_FCAT.


  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 2.
  WA_FCAT-FIELDNAME = 'ERNAM'.
  WA_FCAT-SELTEXT = 'NAME OF PERSON'.
  WA_FCAT-OUTPUTLEN = 18.

  APPEND WA_FCAT TO IT_FCAT.


  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 3.
  WA_FCAT-FIELDNAME = 'ERSDA'.
  WA_FCAT-SELTEXT = 'DATE'.
  WA_FCAT-OUTPUTLEN = 8.

  APPEND WA_FCAT TO IT_FCAT.

ENDFORM.                    " FIELDCAT


MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STAT'.
*  SET TITLEBAR 'xxx'.

IF O_CUST IS NOT BOUND.

  create object O_CUST
    exporting
*      PARENT                      =
      CONTAINER_NAME              = 'CUST'
*      STYLE                       =
*      LIFETIME                    = LIFETIME_DEFAULT
*      REPID                       =
*      DYNNR                       =
*      NO_AUTODEF_PROGID_DYNNR     =
    exceptions
      CNTL_ERROR                  = 1
      CNTL_SYSTEM_ERROR           = 2
      CREATE_ERROR                = 3
      LIFETIME_ERROR              = 4
      LIFETIME_DYNPRO_DYNPRO_LINK = 5
      OTHERS                      = 6
      .
  if SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.


ENDIF.
IF O_ALV IS NOT BOUND.

  create object O_ALV
    exporting
*      I_SHELLSTYLE      = 0
*      I_LIFETIME        =
      I_PARENT          = O_CUST
*      I_APPL_EVENTS     = SPACE
*      I_PARENTDBG       =
*      I_APPLOGPARENT    =
*      I_GRAPHICSPARENT  =
*      I_NAME            =
*      I_FCAT_COMPLETE   = SPACE
    exceptions
      ERROR_CNTL_CREATE = 1
      ERROR_CNTL_INIT   = 2
      ERROR_CNTL_LINK   = 3
      ERROR_DP_CREATE   = 4
      OTHERS            = 5
      .
  if SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

call method O_ALV->SET_TABLE_FOR_FIRST_DISPLAY
*    exporting
*      I_BUFFER_ACTIVE               =
*      I_BYPASSING_BUFFER            =
*      I_CONSISTENCY_CHECK           =
*      I_STRUCTURE_NAME              =
*      IS_VARIANT                    =
*      I_SAVE                        =
*      I_DEFAULT                     = 'X'
*      IS_LAYOUT                     =
*      IS_PRINT                      =
*      IT_SPECIAL_GROUPS             =
*      IT_TOOLBAR_EXCLUDING          =
*      IT_HYPERLINK                  =
*      IT_ALV_GRAPHICS               =
*      IT_EXCEPT_QINFO               =
*      IR_SALV_ADAPTER               =
    changing
      IT_OUTTAB                     = IT_MAT
      IT_FIELDCATALOG               = IT_FCAT
*      IT_SORT                       =
*      IT_FILTER                     =
    exceptions
      INVALID_PARAMETER_COMBINATION = 1
      PROGRAM_ERROR                 = 2
      TOO_MANY_LINES                = 3
      OTHERS                        = 4
          .
  if SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

ENDIF.

DATA : O_KFC TYPE REF TO  HANDLE_EVENT.
CREATE OBJECT O_KFC .
  SET HANDLER O_KFC->HANDLE_DOUBLE_CLICK FOR O_ALV.
ENDMODULE.   

MODULE STATUS_0200 OUTPUT.
  SET PF-STATUS 'KSTAT'.
*  SET TITLEBAR 'xxx'.


  IF O_DOCK IS NOT BOUND.

    create object O_DOCK
      exporting
*        PARENT                      =
*        REPID                       =
*        DYNNR                       =
       SIDE                        = O_DOCK->DOCK_AT_LEFT
        EXTENSION                   = 5000
*        STYLE                       =
*        LIFETIME                    = LIFETIME_DEFAULT
*        CAPTION                     =
*        METRIC                      = 0
*        RATIO                       =
*        NO_AUTODEF_PROGID_DYNNR     =
*        NAME                        =
      exceptions
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        OTHERS                      = 6
        .
    if SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.


  ENDIF.

IF O_ALV1 IS NOT BOUND.

    create object O_ALV1
      exporting
*        I_SHELLSTYLE      = 0
*        I_LIFETIME        =
        I_PARENT          = O_DOCK
*        I_APPL_EVENTS     = SPACE
*        I_PARENTDBG       =
*        I_APPLOGPARENT    =
*        I_GRAPHICSPARENT  =
*        I_NAME            =
*        I_FCAT_COMPLETE   = SPACE
      exceptions
        ERROR_CNTL_CREATE = 1
        ERROR_CNTL_INIT   = 2
        ERROR_CNTL_LINK   = 3
        ERROR_DP_CREATE   = 4
        OTHERS            = 5
        .
    if SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.

call method O_ALV1->SET_TABLE_FOR_FIRST_DISPLAY
      exporting
*        I_BUFFER_ACTIVE               =
*        I_BYPASSING_BUFFER            =
*        I_CONSISTENCY_CHECK           =
        I_STRUCTURE_NAME              = 'MAKT'
*        IS_VARIANT                    =
*        I_SAVE                        =
*        I_DEFAULT                     = 'X'
*        IS_LAYOUT                     =
*        IS_PRINT                      =
*        IT_SPECIAL_GROUPS             =
*        IT_TOOLBAR_EXCLUDING          =
*        IT_HYPERLINK                  =
*        IT_ALV_GRAPHICS               =
*        IT_EXCEPT_QINFO               =
*        IR_SALV_ADAPTER               =
      changing
        IT_OUTTAB                     = IT_MAKT
*        IT_FIELDCATALOG               =
*        IT_SORT                       =
*        IT_FILTER                     =
*      exceptions
*        INVALID_PARAMETER_COMBINATION = 1
*        PROGRAM_ERROR                 = 2
*        TOO_MANY_LINES                = 3
*        OTHERS                        = 4
            .
    if SY-SUBRC <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
endif.
ENDMODULE.         

MODULE USER_COMMAND_0100 INPUT.

  CASE SY-UCOMM.
    WHEN 'BACK'.
  LEAVE TO SCREEN 100.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_0100  INPUT
===========
MODULE USER_COMMAND_0200 INPUT.
CASE SY-UCOMM.
    WHEN 'BACK'.
  LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0200  INPUT



Serkan AKKAVAK
Computer Engineer BSc
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com