Saturday, December 18, 2010
We use USER_COMMAND event type to get interactive functionality when we use REUSE_ALV_GRID_DISPLAY.

REPORT  ZALV_GRID_INTERACTIVE.
*&---------------------------------------------------------------------*
"Variables declarations
*&---------------------------------------------------------------------*
TYPES:
    BEGIN OF T_F_LIST,
      F1 TYPE I,
      F2 TYPE CHAR5,
      F3 TYPE CHAR5,
      F4 TYPE CHAR5,
    END OF T_F_LIST,
    BEGIN OF T_S_LIST,
      F1 TYPE I,
      F5 TYPE CHAR5,
      F6 TYPE CHAR5,
      F7 TYPE CHAR5,
    END OF T_S_LIST.
DATA:
    W_F_LIST TYPE T_F_LIST,
    W_S_LIST TYPE T_S_LIST.
DATA:
    I_F_LIST TYPE STANDARD TABLE OF T_F_LIST,
    I_S_LIST TYPE STANDARD TABLE OF T_S_LIST.

*&---------------------------------------------------------------------*
" ALV Declarations
*----------------------------------------------------------------------*
* Types Pools
TYPE-POOLS:
SLIS.
* Types
TYPES:
  T_FIELDCAT         TYPE SLIS_FIELDCAT_ALV,
  T_EVENTS           TYPE SLIS_ALV_EVENT,
  T_LAYOUT           TYPE SLIS_LAYOUT_ALV.
* Workareas
DATA:
W_FIELDCAT         TYPE T_FIELDCAT,
W_EVENTS           TYPE T_EVENTS,
W_LAYOUT           TYPE T_LAYOUT.
* Internal Tables
DATA:
  I_FIELDCAT         TYPE STANDARD TABLE OF T_FIELDCAT,
  I_FIELDCAT1        TYPE STANDARD TABLE OF T_FIELDCAT,
  I_EVENTS           TYPE STANDARD TABLE OF T_EVENTS.


START-OF-SELECTION.

  PERFORM GET_DATA.

END-OF-SELECTION.

  PERFORM BUILD_FIELDCAT.
  PERFORM BUILD_LAYOUT.
  PERFORM BUILD_EVENTS.
  PERFORM DISPLAY_DATA.


*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_DATA.
  DO 10  TIMES.
    W_F_LIST-F1 = SY-INDEX.
    W_F_LIST-F2 = 'Char1'.
    W_F_LIST-F3 = 'Char2'.
    W_F_LIST-F4 = 'Char3'.
    APPEND W_F_LIST TO I_F_LIST.
    CLEAR  W_F_LIST.
  ENDDO.
ENDFORM.                    "get_data
*&---------------------------------------------------------------------*
*&      Form  build_fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT.

  CLEAR :W_FIELDCAT, I_FIELDCAT[].

  PERFORM BUILD_FCAT USING:
  'F1' 'I_F_LIST' 'F1',
  'F2' 'I_F_LIST' 'F2',
  'F3' 'I_F_LIST' 'F3',
  'F4' 'I_F_LIST' 'F4'.
ENDFORM.                    "build_fieldcat
*&---------------------------------------------------------------------*
*&      Form  build_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT.
  CLEAR:
  W_LAYOUT.
  W_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM.                    "build_layout
*&---------------------------------------------------------------------*
*&      Form  build_events
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_EVENTS .
  CLEAR :
  W_EVENTS,I_EVENTS.
  W_EVENTS-NAME = 'TOP_OF_PAGE'.
  W_EVENTS-FORM = 'TOP_OF_PAGE'.
  APPEND W_EVENTS TO I_EVENTS.
  CLEAR W_EVENTS.


  W_EVENTS-NAME = 'USER_COMMAND'.
  W_EVENTS-FORM = 'USER_COMMAND'.
  APPEND W_EVENTS TO I_EVENTS.
  CLEAR W_EVENTS.

ENDFORM.                    " build_events
*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA.
  DATA:
  L_PROGRAM TYPE SY-REPID VALUE SY-REPID.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = L_PROGRAM
      IS_LAYOUT          = W_LAYOUT
      IT_FIELDCAT        = I_FIELDCAT
      IT_EVENTS          = I_EVENTS
    TABLES
      T_OUTTAB           = I_F_LIST
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM.                    "display_data
*&---------------------------------------------------------------------*
*&      Form  build_fcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0153   text
*      -->P_0154   text
*      -->P_0155   text
*----------------------------------------------------------------------*
FORM BUILD_FCAT  USING L_FIELD L_TAB L_TEXT.

  W_FIELDCAT-FIELDNAME = L_FIELD.
  W_FIELDCAT-TABNAME   = L_TAB.
  W_FIELDCAT-SELTEXT_M = L_TEXT.
  APPEND W_FIELDCAT TO I_FIELDCAT.
  CLEAR W_FIELDCAT.

ENDFORM.                    " build_fcat
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
  DATA :
  I_HEADER TYPE SLIS_T_LISTHEADER,
  W_HEADER LIKE LINE OF I_HEADER.

  DATA:L_DATE1 TYPE DATUM,
  L_DATE2 TYPE DATUM.

  W_HEADER-TYP = 'S'.
  W_HEADER-INFO = SY-TITLE.
  APPEND W_HEADER TO I_HEADER.
  CLEAR W_HEADER.

  W_HEADER-TYP = 'H'.
  W_HEADER-INFO = SY-REPID.
  APPEND W_HEADER TO I_HEADER.
  CLEAR W_HEADER.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY = I_HEADER
      I_LOGO             = 'ENJOYSAP_LOGO'.
ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING UCOMM TYPE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
  IF UCOMM = '&IC1'. "When u double click on perticular record.
    PERFORM GET_DATA1.
    READ TABLE I_F_LIST INTO W_F_LIST INDEX SELFIELD-TABINDEX.
    IF SY-SUBRC = 0.
      DELETE I_S_LIST WHERE F1 <> W_F_LIST-F1.
      CLEAR I_FIELDCAT1[].
      PERFORM BUILD_FCAT1 USING:
      'F1' 'I_S_LIST' 'F1',
      'F5' 'I_S_LIST' 'F5',
      'F6' 'I_S_LIST' 'F6',
      'F7' 'I_S_LIST' 'F7'.
      PERFORM DISPLAY_DATA1.
    ENDIF.
  ENDIF..


ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  build_fcat1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0153   text
*      -->P_0154   text
*      -->P_0155   text
*----------------------------------------------------------------------*
FORM BUILD_FCAT1  USING L_FIELD L_TAB L_TEXT.

  W_FIELDCAT-FIELDNAME = L_FIELD.
  W_FIELDCAT-TABNAME   = L_TAB.
  W_FIELDCAT-SELTEXT_M = L_TEXT.
  APPEND W_FIELDCAT TO I_FIELDCAT1.
  CLEAR W_FIELDCAT.

ENDFORM.                    " build_fcat1
*&---------------------------------------------------------------------*
*&      Form  display_data1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA1 .
  DATA:
  L_PROGRAM TYPE SY-REPID VALUE SY-REPID.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = L_PROGRAM
      IS_LAYOUT          = W_LAYOUT
      IT_FIELDCAT        = I_FIELDCAT1
    TABLES
      T_OUTTAB           = I_S_LIST
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " display_data1
*&---------------------------------------------------------------------*
*&      Form  get_data1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA1 .

  DO 10  TIMES.
    W_S_LIST-F1 = SY-INDEX.
    W_S_LIST-F5 = 'Char5'.
    W_S_LIST-F6 = 'Char6'.
    W_S_LIST-F7 = 'Char7'.
    APPEND W_S_LIST TO I_S_LIST.
    CLEAR  W_S_LIST.
  ENDDO.
ENDFORM.                                                    " get_data1

0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.