Saturday, December 18, 2010
Define one field for checkbox in ALV output table and set W_FIELDCAT-CHECKBOX = 'X'. for the field in the fieldcatalog table.
REPORT ZALV_CHECKBOX. DATA: BEGIN OF W_EMP , CHECKBOX TYPE C , "declare one variable for Checkbox STATUS TYPE CHAR3, PERNR TYPE PA0001-PERNR, ENDDA TYPE PA0001-ENDDA, BEGDA TYPE PA0001-BEGDA, ENAME TYPE PA0001-ENAME, END OF W_EMP, I_EMP LIKE W_EMP OCCURS 0 WITH HEADER LINE. *&---------------------------------------------------------------------* * 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_EVENTS TYPE STANDARD TABLE OF T_EVENTS. START-OF-SELECTION. PERFORM GET_DATA. PERFORM BUILD_FIELD. PERFORM BUILD_EVENTS. PERFORM BUILD_LAYOUT. PERFORM DISPLAY_DATA. *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM GET_DATA . SELECT PERNR ENDDA BEGDA ENAME FROM PA0001 INTO CORRESPONDING FIELDS OF TABLE I_EMP UP TO 20 ROWS. ENDFORM. " get_data *&---------------------------------------------------------------------* *& Form build_field *&---------------------------------------------------------------------* FORM BUILD_FIELD . CLEAR W_FIELDCAT. CLEAR I_FIELDCAT. PERFORM BUILD_FCAT USING: "Field Itab Text 'CHECKBOX' 'I_EMP' ' ', 'STATUS' 'I_EMP' 'STATUS', 'PERNR' 'I_EMP' 'PERNR', 'ENDDA' 'I_EMP' 'ENDDA', 'BEGDA' 'I_EMP' 'BEGDA', 'ENAME' 'I_EMP' 'ENAME'. ENDFORM. "BUILD_FIELD *&---------------------------------------------------------------------* *& Form BUILD_FCAT *&---------------------------------------------------------------------* 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. IF L_FIELD = 'CHECKBOX'. W_FIELDCAT-CHECKBOX = 'X'. "Setting Check box W_FIELDCAT-EDIT = 'X'. ENDIF. APPEND W_FIELDCAT TO I_FIELDCAT. CLEAR W_FIELDCAT. ENDFORM. " build_field *&---------------------------------------------------------------------* *& Form display_data *&---------------------------------------------------------------------* FORM DISPLAY_DATA . DATA:L_PROGRAM TYPE SY-REPID. L_PROGRAM = 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_EMP 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_events *&---------------------------------------------------------------------* FORM BUILD_EVENTS . CLEAR I_EVENTS. CLEAR I_EVENTS. W_EVENTS-FORM = 'TOP_OF_PAGE'. "Name of the callback subroutine for top_of_page event. W_EVENTS-NAME = 'TOP_OF_PAGE'. "Name of the event APPEND W_EVENTS TO I_EVENTS. CLEAR W_EVENTS. ENDFORM. " build_events *&---------------------------------------------------------------------* " Form build_layout *&---------------------------------------------------------------------* FORM BUILD_LAYOUT . W_LAYOUT-INFO_FIELDNAME = 'STATUS'. "Status field defined in the internal tables ENDFORM. " build_layout *----------------------------------------------------------------------* " FORM : top_of_page *----------------------------------------------------------------------* 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 = 'A'. W_HEADER-INFO = 'GRID Display TOP OF PAGE'. 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
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Sending email with pdf attachment
- ABAP - Step by step tutorial on Smart Forms - Template Node
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
0 comments:
Post a Comment
Your useful comments, suggestions are appreciated.Your comments are moderated.