메뉴 건너뛰기

SAP 한국 커뮤니티

zsalv_edit

sapjoy 2010.08.20 10:56 조회 수 : 3205


report  zsalv_edit.

*----------------------------------------------------------------------*
*  Define the Local class inheriting from the CL_SALV_MODEL_LIST
*  to get an access of the model, controller and adapter which inturn
*  provides the Grid Object
*----------------------------------------------------------------------*
class lcl_salv_model definition inheriting from cl_salv_model_list.

  public section.
    data: o_control type ref to cl_salv_controller_model,
          o_adapter type ref to cl_salv_adapter.

    methods:
      grabe_model
        importing
          io_model type ref to cl_salv_model,

      grabe_controller,

      grabe_adapter.


  private section.
    data: lo_model type ref to cl_salv_model.

endclass.                    "LCL_SALV_MODEL DEFINITION

*----------------------------------------------------------------------*
* Event handler for the added buttons
*----------------------------------------------------------------------*
class lcl_event_handler definition.

  public section.
    methods:
      on_user_command for event added_function of cl_salv_events
        importing e_salv_function.

endclass.                    "lcl_event_handler DEFINITION


*----------------------------------------------------------------------*
* Local Report class - Definition
*----------------------------------------------------------------------*
class lcl_report definition.

  public section.

    types: ty_t_sflights type standard table of sflights.

    data: t_data type ty_t_sflights.

    data: o_salv       type ref to cl_salv_table.
    data: o_salv_model type ref to lcl_salv_model.


    methods:
      get_data,

      generate_output.

endclass.                    "lcl_report DEFINITION

*----------------------------------------------------------------------*
* Global data
*----------------------------------------------------------------------*
data: lo_report type ref to lcl_report.

*----------------------------------------------------------------------*
* Start of selection
*----------------------------------------------------------------------*
start-of-selection.

  create object lo_report.

  lo_report->get_data( ).

  lo_report->generate_output( ).


*----------------------------------------------------------------------*
* Local Report class - Implementation
*----------------------------------------------------------------------*
class lcl_report implementation.

  method get_data.

*   test data
    select * from sflights
           into table me->t_data
           up to 30 rows.

  endmethod.                    "get_data

  method generate_output.

*...New ALV Instance ...............................................
    try.
        cl_salv_table=>factory(
          exporting
*          r_container    = w_alv1
            list_display = abap_false
          importing
            r_salv_table = o_salv
          changing
            t_table      = t_data ).
      catch cx_salv_msg.                                "#EC NO_HANDLER
    endtry.

*...PF Status.......................................................
*   Add MYFUNCTION from the report SALV_DEMO_TABLE_EVENTS
    o_salv->set_screen_status(
      pfstatus      =  'SALV_STANDARD'
      report        =  'SALV_DEMO_TABLE_EVENTS'
      set_functions = o_salv->c_functions_all ).

*...Event handler for the button.....................................
    data: lo_events type ref to cl_salv_events_table,
          lo_event_h type ref to lcl_event_handler.

* event object
    lo_events = o_salv->get_event( ).

* event handler
    create object lo_event_h.

* setting up the event handler
    set handler lo_event_h->on_user_command for lo_events.


*...Get Model Object ...............................................
    data: lo_alv_mod type ref to cl_salv_model.

*   Narrow casting
    lo_alv_mod ?= o_salv.

*   object for the local inherited class from the CL_SALV_MODEL_LIST
    create object o_salv_model.

*   grabe model to use it later
    call method o_salv_model->grabe_model
      exporting
        io_model = lo_alv_mod.

*...Generate ALV output ...............................................
    o_salv->display( ).


  endmethod.                    "generate_output

endclass.                    "lcl_report IMPLEMENTATION

*----------------------------------------------------------------------*
* LCL_SALV_MODEL implementation
*----------------------------------------------------------------------*
class lcl_salv_model implementation.

  method grabe_model.

*   save the model
    lo_model = io_model.

  endmethod.                    "grabe_model

  method grabe_controller.

*   save the controller
    o_control = lo_model->r_controller.

  endmethod.                    "grabe_controller

  method grabe_adapter.

*   save the adapter from controller
    o_adapter ?= lo_model->r_controller->r_adapter.

  endmethod.                    "grabe_adapter

endclass.                    "LCL_SALV_MODEL IMPLEMENTATION

*----------------------------------------------------------------------*
* Event Handler for the SALV
*----------------------------------------------------------------------*
class lcl_event_handler implementation.

  method on_user_command.

    data: lo_grid type ref to cl_gui_alv_grid,
          lo_full_adap type ref to cl_salv_fullscreen_adapter.

    data: ls_layout type lvc_s_layo.

    case e_salv_function.

*     Make ALV as Editable ALV
      when 'MYFUNCTION'.

*       Contorller
        call method lo_report->o_salv_model->grabe_controller.

*       Adapter
        call method lo_report->o_salv_model->grabe_adapter.

*       Fullscreen Adapter (Down Casting)
        lo_full_adap ?= lo_report->o_salv_model->o_adapter.

*       Get the Grid
        lo_grid = lo_full_adap->get_grid( ).

*       Got the Grid .. ?
        if lo_grid is bound.

*         Editable ALV
          ls_layout-edit = 'X'.

*         Set the front layout of ALV
          call method lo_grid->set_frontend_layout
            exporting
              is_layout = ls_layout.

*         refresh the table
          call method lo_grid->refresh_table_display.

        endif.

    endcase.

  endmethod.                    "on_user_command

endclass.                    "lcl_event_handler IMPLEMENTATION
번호 제목 글쓴이 날짜 조회 수
649 <b>ABAP SOURCE는 교재에 사용된 소스들입니다.</b> [1] sapjoy 2006.12.02 3618
648 REPORT z19_01. sapjoy 2012.08.01 3526
647 z_exception_test sapjoy 2010.10.10 3520
646 report zsalv_036 . sapjoy 2010.08.20 3472
645 REPORT ZSMARTFORMS_03. sapjoy 2008.11.28 3345
644 REPORT z18_04 . sapjoy 2012.08.01 3344
643 REPORT z18_05 sapjoy 2012.08.01 3328
642 Sub DOI_EXCEL_MACRO() sapjoy 2008.12.26 3312
641 REPORT z18_003 sapjoy 2007.03.05 3281
640 subroutine pool sapjoy 2013.11.15 3273
639 REPORT z19_004 sapjoy 2007.03.27 3230
638 REPORT Z_WHEREUSEDLIST [4] sapjoy 2011.03.28 3215
637 REPORT ZALVCOLOR sapjoy 2010.10.09 3212
636 REPORT ZSAPTIP_002. sapjoy 2009.02.20 3206
» zsalv_edit [1] sapjoy 2010.08.20 3205
634 REPORT Z06_001 MESSAGE-ID ZTEST . [1] sapjoy 2006.12.05 3205
633 REPORT z18_06. sapjoy 2012.08.01 3147
632 REPORT zsapdoi_001. [2] sapjoy 2008.12.20 3135
631 report zsalv_042 . sapjoy 2010.08.20 3132
630 REPORT z18_01. sapjoy 2012.08.01 3108