메뉴 건너뛰기

SAP 한국 커뮤니티

REPORT z18_033

sapjoy 2008.10.13 18:50 조회 수 : 9044

 

REPORT  z18_033        MESSAGE-ID ztest.

TABLES : sflight.

DATA : con1_ref TYPE REF TO cl_gui_custom_container.

DATABEGIN OF gt_sflight OCCURS 0.
        INCLUDE STRUCTURE sflight.
DATA: chk   TYPE c.
DATA: light TYPE c"to display exceptions
data: drop_down_handle type int4.
DATA: cellcolor TYPE lvc_t_scol. "Table for colors
DATA: cellbtn   TYPE lvc_t_styl. "Table buttons
DATAEND OF gt_sflight.

DATA : gs_sflight LIKE gt_sflight.


DATA : grid1  TYPE REF TO cl_gui_alv_grid,
       gs_variant     LIKE disvariant,
       gs_cs_variant  LIKE disvariant,
       gs_layout     TYPE lvc_s_layo,
       gs_toolbar    TYPE ui_functions,
       gt_sort       TYPE lvc_t_sort,
       gt_fieldcat   TYPE lvc_t_fcat.

*       gt_sflight    TYPE TABLE OF sflight.

TYPE-POOLS: icon.

*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.

  PUBLIC SECTION.
    METHODS:

    handle_double_click
        FOR EVENT double_click OF cl_gui_alv_grid
            IMPORTING e_row e_column.

    METHODS : handle_toolbar
                 FOR EVENT toolbar OF cl_gui_alv_grid
                 IMPORTING e_object e_interactive.


    METHODS : handle_command
                 FOR EVENT user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.

    METHODS : handle_button_click
        FOR EVENT button_click OF cl_gui_alv_grid
        IMPORTING es_col_id es_row_no.


  PRIVATE SECTION.

ENDCLASS.                    "lcl_event_receiver DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.

  METHOD handle_double_click.
    LEAVE TO SCREEN 0.
  ENDMETHOD.                           "handle_double_click

*-- Add ToolBar
  METHOD handle_toolbar.

    DATA: ls_toolbar  TYPE stb_button.

    CLEAR ls_toolbar.
    ls_toolbar-butn_type = 3.
    APPEND ls_toolbar    TO e_object->mt_toolbar.

    CLEAR ls_toolbar.
    ls_toolbar-function  = 'RESH'.
    ls_toolbar-icon      = icon_refresh.
    ls_toolbar-quickinfo = 'Refresh'.
    ls_toolbar-text      = ' '.
    ls_toolbar-disabled  = ' '.
    APPEND ls_toolbar    TO e_object->mt_toolbar.

  ENDMETHOD.                    "handle_toolbar


  METHOD handle_command.
    DATA : l_scroll TYPE lvc_s_stbl.

    CASE e_ucomm.
*-  REFRESH
      WHEN 'RESH'.

        SELECT * FROM sflight
        INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
        l_scroll-row = 'X'.
        l_scroll-col = 'X'.
        CALL METHOD grid1->refresh_table_display
          EXPORTING
            i_soft_refresh = ''
            is_stable      = l_scroll.
    ENDCASE.
  ENDMETHOD.                    "handle_user_command

  METHOD handle_button_click.
    CLEAR gt_sflight.
    READ TABLE gt_sflight INDEX es_row_no-row_id INTO gs_sflight.
    IF sy-subrc EQ 0.
      MESSAGE i002 WITH gs_sflight-carrid 'is selected'.
    ENDIF.
  ENDMETHOD.                    "handle_on_entered

ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
*

DATA :     event_receiver TYPE REF TO lcl_event_receiver.


START-OF-SELECTION.
  SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.

  LOOP AT gt_sflight.

    IF gt_sflight-seatsocc <= 0.
      gt_sflight-light = '1'.
    ELSEIF gt_sflight-seatsocc <= 50.
      gt_sflight-light = '2'.
    ELSE.
      gt_sflight-light = '3'.
    ENDIF.



    MODIFY gt_sflight.

  ENDLOOP.


  CALL SCREEN 100.


*---------------------------------------------------------------------*
*  MODULE init_con OUTPUT
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
MODULE init_con OUTPUT.

  IF con1_ref IS INITIAL.
    CREATE OBJECT con1_ref
    EXPORTING container_name = 'CON1'.


    CREATE OBJECT grid1
           EXPORTING
                i_parent = con1_ref.

    PERFORM setting_layout.
    PERFORM getting_catalog.
    PERFORM setting_catalog.
    PERFORM setting_dropdown.
    perform build_data changing gt_sflight[].
*    PERFORM setting_cell.
*    PERFORM setting_toolbar.
*    PERFORM setting_sort.
*    PERFORM setting_event.

CALL METHOD grid1->register_edit_event
  EXPORTING
    i_event_id = cl_gui_alv_grid=>mc_evt_modified.


    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
*        i_structure_name     = 'SFLIGHT'
        i_save               = 'A'
        is_variant           = gs_variant  " variant display
        i_default            = ' '
        is_layout            = gs_layout
        it_toolbar_excluding = gs_toolbar
      CHANGING
        it_outtab            = gt_sflight[]
        it_fieldcatalog      = gt_fieldcat[]
        it_sort              = gt_sort.




  ENDIF.
ENDMODULE.                 " init_con  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'G100'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  setting_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GS_LAYOCAT  text
*----------------------------------------------------------------------*
FORM setting_layout .
*- General display options
  gs_layout-cwidth_opt = 'X'.
* TITLE BAR
  gs_layout-grid_title = 'Drop Down List Box'.
* Selection modes for SEL_MODE
  gs_layout-sel_mode = 'D'.

  gs_layout-edit = 'X'.

* exception
  gs_layout-excp_fname = 'LIGHT'.

* coloring row
  gs_layout-ctab_fname = 'CELLCOLOR'.

* STYLEFNAME of the layout structure.
  gs_layout-stylefname = 'CELLBTN'.

* Grid pattern
*  gs_layout-zebra      = 'X'.
ENDFORM.                    " setting_layout
*&---------------------------------------------------------------------*
*&      Form  setting_toolbar
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GS_TOOLBAR  text
*----------------------------------------------------------------------*
FORM setting_toolbar.
  DATA: l_exclude TYPE ui_func.

  l_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
  APPEND l_exclude TO gs_toolbar.

  l_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
  APPEND l_exclude TO gs_toolbar.

ENDFORM.                    " setting_toolbar
*&---------------------------------------------------------------------*
*&      Form  setting_sort
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setting_sort .

  DATA : ls_sort TYPE lvc_s_sort.

  ls_sort-spos = '1'.
  ls_sort-fieldname = 'CARRID'.
  ls_sort-up = 'X'.
  ls_sort-subtot = 'X'.
  APPEND ls_sort TO gt_sort.




ENDFORM.                    " setting_sort
*&---------------------------------------------------------------------*
*&      Form  setting_event
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setting_event .
  CREATE OBJECT event_receiver.
  SET HANDLER event_receiver->handle_double_click FOR grid1.
  SET HANDLER event_receiver->handle_toolbar       FOR grid1.
  SET HANDLER event_receiver->handle_command       FOR grid1.
  SET HANDLER event_receiver->handle_button_click  FOR grid1.

ENDFORM.                    " setting_event
*&---------------------------------------------------------------------*
*&      Form  setting_catalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setting_catalog .
DATA ls_fieldcat  TYPE lvc_s_fcat.

  ls_fieldcat-fieldname = 'CARRID'.
*  ls_fieldcat-drdn_hndl = '1'.
  ls_fieldcat-drdn_field = 'DROP_DOWN_HANDLE'.
  APPEND ls_fieldcat TO gt_fieldcat.



ENDFORM.                    " setting_catalog
*&---------------------------------------------------------------------*
*&      Form  getting_catalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM getting_catalog .
  DATA : lt_fieldcat TYPE kkblo_t_fieldcat.
  CALL FUNCTION 'K_KKB_FIELDCAT_MERGE'
    EXPORTING
      i_callback_program     = sy-repid
      i_tabname              = 'GT_SFLIGHT'
*      i_strucname            = i_structure
      i_inclname             = sy-repid
    CHANGING
      ct_fieldcat            = lt_fieldcat[]
    EXCEPTIONS
      inconsistent_interface = 1
      OTHERS                 = 2.
  IF sy-subrc EQ 0.
    CALL FUNCTION 'LVC_TRANSFER_FROM_KKBLO'
      EXPORTING
        it_fieldcat_kkblo = lt_fieldcat[]
      IMPORTING
        et_fieldcat_lvc   = gt_fieldcat[].
  ENDIF.

ENDFORM.                    " getting_catalog
*&---------------------------------------------------------------------*
*&      Form  SETTING_CELL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setting_cell .
* SETTING CELL
  DATA : lt_color    TYPE lvc_t_scol,
         ls_color    TYPE lvc_s_scol,
         lt_cellbtn  TYPE lvc_t_styl,
         ls_cellbtn  TYPE lvc_s_styl,
         ls_fieldcat TYPE lvc_s_fcat,
         l_mode      TYPE raw4,
         l_type(4)   TYPE c,
         index       TYPE i.

  CLEAR index.
  LOOP AT gt_sflight.
    index = index + 1.
    CLEAR: lt_color[], lt_cellbtn[].

    LOOP AT gt_fieldcat INTO ls_fieldcat.

      CLEAR ls_color.
      ls_color-fname = ls_fieldcat-fieldname.
      IF ls_color-fname EQ 'PLANETYPE'.
        CASE gt_sflight-planetype.
          WHEN '747-400'.
            ls_color-color-col = 5.
            ls_color-color-int = 0.
          WHEN 'A319'.
            ls_color-color-col = 3.
            ls_color-color-int = 0.
          WHEN 'A310-300'.
            ls_color-color-col = 6.
            ls_color-color-int = 0.
          WHEN OTHERS.
*      ls_color-color-col = 1.
*      ls_color-color-int = 0.
        ENDCASE.

        INSERT ls_color INTO TABLE lt_color.
      ENDIF.

* Display cell as PUSHBUTTON
      CLEAR ls_cellbtn.
      ls_cellbtn-fieldname = ls_fieldcat-fieldname.

      IF ls_cellbtn-fieldname EQ 'CHK'.
        ls_cellbtn-fieldname = 'CHK'.
        ls_cellbtn-style     = cl_gui_alv_grid=>mc_style_button.
*    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. "
      ELSEIF ls_cellbtn-fieldname EQ'QSTATUS' .
        ls_cellbtn-style = cl_gui_alv_grid=>mc_style_enabled."
      ENDIF.
      INSERT ls_cellbtn INTO TABLE lt_cellbtn.

    ENDLOOP.

    CLEAR: gt_sflight-cellcolor[].

    INSERT LINES OF lt_color   INTO TABLE gt_sflight-cellcolor.
    INSERT LINES OF lt_cellbtn INTO TABLE gt_sflight-cellbtn.

    MODIFY gt_sflight INDEX index.
    CLEAR  gt_sflight.

  ENDLOOP.

ENDFORM.                    " SETTING_CELL
*&---------------------------------------------------------------------*
*&      Form  SETTING_DROPDOWN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setting_dropdown .
DATA: lt_dropdown TYPE lvc_t_dral,
    ls_dropdown TYPE lvc_s_dral.

  ls_dropdown-handle = '1'.
  ls_dropdown-value = 'AA : American Airlines'.
  APPEND ls_dropdown TO lt_dropdown.

 clear ls_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'AZ : Alitalia'.
  APPEND ls_dropdown TO lt_dropdown.


  CALL METHOD GRID1->set_drop_down_table
    EXPORTING
      it_drop_down_alias = lt_dropdown.


ENDFORM.                    " setting_dropdown
*&---------------------------------------------------------------------*
*&      Form  BUILD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_SFLIGHT  text
*----------------------------------------------------------------------*
form build_data changing pt_outtab type standard table.

 data : ls_outtab like gt_sflight.
 data : l_index type i.

  loop at pt_outtab into ls_outtab.
    l_index = sy-tabix.


*
    if ls_outtab-carrid eq 'AA'.
      ls_outtab-drop_down_handle = '1'.
    else.
      ls_outtab-drop_down_handle = '2'.
    endif.
    modify  pt_outtab from ls_outtab.
  endloop.


endform.                               " build_data
번호 제목 글쓴이 날짜 조회 수
271 report zunicode_003. sapjoy 2008.11.22 2202
270 report zunicode_002 sapjoy 2008.11.22 2563
269 zunicode_001 sapjoy 2008.11.22 2397
268 REPORT Z07_024 sapjoy 2006.12.09 2474
» REPORT z18_033 [47] sapjoy 2008.10.13 9044
266 REPORT Z13_021 [1] sapjoy 2008.09.29 2156
265 REPORT Z17_004. sapjoy 2007.02.12 2508
264 REPORT z19_005 [1] sapjoy 2007.04.04 2927
263 REPORT z18_035 sapjoy 2007.03.14 2450
262 REPORT z16_003 [1] sapjoy 2008.08.08 2551
261 REPORT z16_002 sapjoy 2008.08.08 2649
260 REPORT Z04_003 [9] sapjoy 2007.05.17 2561
259 <b>ABAP SOURCE는 교재에 사용된 소스들입니다.</b> [1] sapjoy 2006.12.03 3619
258 REPORT z18_037 [3] sapjoy 2008.04.22 2728
257 REPORT z18_038 [2] sapjoy 2008.04.22 2636
256 REPORT Z07_031 [2] sapjoy 2006.12.09 2309
255 REPORT Z05_001 [3] sapjoy 2007.05.22 2881
254 REPORT Z05_003 sapjoy 2007.05.22 2406
253 REPORT Z15_027 . sapjoy 2007.02.01 2718
252 REPORT Z17_021 . sapjoy 2007.02.21 2388