ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ALV002

ALV002

原创 Linux操作系统 作者:fivezhuo 时间:2009-08-01 02:52:49 0 删除 编辑
ALV002
2009-07-30 23:25:44

*&---------------------------------------------------------------------*
*& Report  ZFIVE_001
*&
*&---------------------------------------------------------------------*


REPORT zfive_001 MESSAGE-ID bd no standard page heading.
TYPE-POOLS: icon.
tables:sflight.
TYPES: BEGIN OF st_sflight.
        INCLUDE STRUCTURE sflight.
*       Field for traffic light
TYPES:  traffic_light TYPE c.
*       Field for line color
types:  line_color(4) type c.
TYPES: END OF st_sflight.
CLASS lcl_event_receiver DEFINITION DEFERRED.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.


DATA: ok_code LIKE sy-ucomm,
      g_wa_sflight LIKE sflight,
       gs_layout       TYPE lvc_s_layo.

DATA:
  go_grid             TYPE REF TO cl_gui_alv_grid,
  go_custom_container TYPE REF TO cl_gui_custom_container,
  o_event_receiver    TYPE REF TO lcl_event_receiver.
data: g_screen200 LIKE sflight,
* Internal table
     gi_index_rows TYPE lvc_t_row,
* Information about 1 row
     g_selected_row LIKE lvc_s_row.

*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
     handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
       IMPORTING
         e_object e_interactive,
     handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
       IMPORTING e_ucomm.
ENDCLASS.                    "lcl_event_receiver DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_toolbar.
*  Event handler method for event toolbar.
    CONSTANTS:
*  Constants for button type
      c_button_normal           TYPE i VALUE 0,
      c_menu_and_default_button TYPE i VALUE 1,
     c_menu                    TYPE i VALUE 2,
      c_separator               TYPE i VALUE 3,
      c_radio_button            TYPE i VALUE 4,
      c_checkbox                TYPE i VALUE 5,
      c_menu_entry              TYPE i VALUE 6.
    DATA:
        ls_toolbar  TYPE stb_button.
*   Append seperator to the normal toolbar
    CLEAR ls_toolbar.
    MOVE c_separator TO ls_toolbar-butn_type..
    APPEND ls_toolbar TO e_object->mt_toolbar.
*   Append a new button that to the toolbar. Use E_OBJECT of
*   event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
*   This class has one attribute MT_TOOLBAR which is of table type
*   TTB_BUTTON. The structure is STB_BUTTON
    CLEAR ls_toolbar.
    MOVE 'CHANGE'        TO ls_toolbar-function.
    MOVE  icon_change    TO ls_toolbar-icon.
    MOVE 'Change flight' TO ls_toolbar-quickinfo.
    MOVE 'Change'        TO ls_toolbar-text.
    MOVE ' '             TO ls_toolbar-disabled.
    APPEND ls_toolbar    TO e_object->mt_toolbar.
  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
*   Handle own functions defined in the toolbar
    CASE e_ucomm.
      WHEN 'CHANGE'.
        LEAVE TO SCREEN 0.
    ENDCASE.
  ENDMETHOD.                    "handle_user_command
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION

selection-screen: begin of block test.
parameters: dd_k as checkbox.
selection-screen:end of block test..

START-OF-SELECTION.
  SET SCREEN '100'.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE ok_code.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS '100'.
set titlebar 'S100'.
* Create objects
  IF go_custom_container IS INITIAL.
    CREATE OBJECT go_custom_container
      EXPORTING container_name = 'ALV_CONTAINER'.
    CREATE OBJECT go_grid
      EXPORTING
        i_parent = go_custom_container.
    CREATE OBJECT o_event_receiver.
    SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
    SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
    PERFORM. load_data_into_grid.
  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Form  load_data_into_grid

*&---------------------------------------------------------------------*
FORM. load_data_into_grid.
* Read data from table SFLIGHT
  SELECT *
    FROM sflight
    INTO TABLE gi_sflight.
* Load data into the grid and display them
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = 'SFLIGHT'
    CHANGING
      it_outtab        = gi_sflight.
  CALL METHOD go_grid->set_toolbar_interactive.
  CALL METHOD cl_gui_control=>set_focus
    EXPORTING
      control = go_grid.
ENDFORM.                    " load_data_into_grid

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14397246/viewspace-611028/,如需转载,请注明出处,否则将追究法律责任。

下一篇: ALV OO
请登录后发表评论 登录
全部评论

注册时间:2009-08-01

  • 博文量
    110
  • 访问量
    46732