본문 바로가기
ERP-SAP/ABAP

<ABAP> ALV 기본 선언 모음 (그냥 include 해서 쓸때 참 편한..)

by 행복한워니의 기록 2011. 11. 19.
728x90
반응형

해당 로직 구상자는 Thx to Ziin 과장님의 소스임을 밝힙니다. ㅋㅋㅋㅋㅋ

  INCLUDE zo1eicoalv. <- 늘 요렇게 선언하고 있다. 아래는 그 긴~ 내용들이다. 

alv 선언하고 class 기본적인 선언들이 모두 다 들어가 있다. 

*&---------------------------------------------------------------------*
*&  Include           ZO1EICOALV
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* ALV 관련 공통 variables/class/Forms
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* ALV 관련 Variables
*----------------------------------------------------------------------*
*-----/// INCLUDES
INCLUDE <cl_alv_control>.


*-----/// Class Definition Notification
CLASS lcl_def_grid DEFINITION DEFERRED.


TYPES:
  BEGIN OF t_containers,
    top    TYPE REF TO cl_gui_container,
    bottom TYPE REF TO cl_gui_container,
    left   TYPE REF TO cl_gui_container,
    right  TYPE REF TO cl_gui_container,
  END OF t_containers.


DATA:
*-----/// Global Variables
  g_repid      LIKE sy-repid,            " 프로그램 ID
  g_ok_code    LIKE sy-ucomm,            " ok code
  g_focus_row  TYPE lvc_s_roid-row_id,   " 포커스 rowid
  g_focus_row2 TYPE lvc_s_roid-row_id,   " 포커스 rowid
  g_focus_col  TYPE lvc_s_col-fieldname. " 포커스 컬럼명.


DATA:
*-----///Containers
  go_container          TYPE REF TO cl_gui_container,
  go_container2         TYPE REF TO cl_gui_container,
  go_container3         TYPE REF TO cl_gui_container,
  go_containers         TYPE t_containers,

*-- custom
  go_custom_container   TYPE REF TO cl_gui_custom_container,
  go_custom_container2  TYPE REF TO cl_gui_custom_container,
  go_custom_container3  TYPE REF TO cl_gui_custom_container,

*-- docking
  go_docking_container  TYPE REF TO cl_gui_docking_container,
  go_docking_container2 TYPE REF TO cl_gui_docking_container,
  go_docking_container3 TYPE REF TO cl_gui_docking_container,

*-- splitter
  go_splitter           TYPE REF TO cl_gui_splitter_container,
  go_splitter2          TYPE REF TO cl_gui_splitter_container,
  go_splitter3          TYPE REF TO cl_gui_splitter_container,

*-- HTML Document Viewer
  go_document           TYPE REF TO cl_dd_document,
  go_document2          TYPE REF TO cl_dd_document,
  go_document3          TYPE REF TO cl_dd_document,
  go_html_viewer        TYPE REF TO cl_gui_html_viewer,
  go_html_viewer2       TYPE REF TO cl_gui_html_viewer,
  go_html_viewer3       TYPE REF TO cl_gui_html_viewer.


DATA:
*-----/// Structures, internal tables
  gs_cell     TYPE lvc_s_styl,
  gs_sort     TYPE lvc_s_sort,
  gs_fieldcat TYPE lvc_s_fcat,
  gs_f4       TYPE lvc_s_f4,
  gs_rows     TYPE lvc_s_row,
  gs_cols     TYPE lvc_s_col,
  gs_dropdown TYPE lvc_s_drop,
  gs_rowno    TYPE lvc_s_roid,
  gs_good     TYPE lvc_s_modi,
  gt_cell     TYPE lvc_t_styl.


DATA:
*-----/// 하나의 ALV 에 대한 관련 variables
  go_grid           TYPE REF TO cl_gui_alv_grid,
  g_container_name  TYPE scrfname VALUE 'MY_CONT',
  g_grid_title      TYPE lvc_title,
  gs_variant        TYPE disvariant,
  gs_layout         TYPE lvc_s_layo,
  gs_stable         TYPE lvc_s_stbl,
  gt_fieldcat       TYPE lvc_t_fcat,
  gt_sort           TYPE lvc_t_sort,
  gt_exclude        TYPE ui_functions,
  gt_f4             TYPE lvc_t_f4,
  gt_rows           TYPE lvc_t_row,
  gt_cols           TYPE lvc_t_col,
  gt_dropdown       TYPE lvc_t_drop,
  go_grid_c         TYPE REF TO lcl_def_grid.


DATA:
*-----/// ALV2 에 대한 관련 variables
  go_grid2          TYPE REF TO cl_gui_alv_grid,
  g_container_name2 TYPE scrfname VALUE 'MY_CONT2',
  g_grid_title2     TYPE lvc_title,
  gs_variant2       TYPE disvariant,
  gs_layout2        TYPE lvc_s_layo,
  gs_stable2        TYPE lvc_s_stbl,
  gt_fieldcat2      TYPE lvc_t_fcat,
  gt_sort2          TYPE lvc_t_sort,
  gt_exclude2       TYPE ui_functions,
  gt_f4_2           TYPE lvc_t_f4,
  gt_rows2          TYPE lvc_t_row,
  gt_cols2          TYPE lvc_t_col,
  gt_dropdown2      TYPE lvc_t_drop,
  go_grid_c2        TYPE REF TO lcl_def_grid.


DATA:
*-----/// ALV3 에 대한 관련 variables
  go_grid3          TYPE REF TO cl_gui_alv_grid,
  g_container_name3 TYPE scrfname VALUE 'MY_CONT3',
  g_grid_title3     TYPE lvc_title,
  gs_variant3       TYPE disvariant,
  gs_layout3        TYPE lvc_s_layo,
  gs_stable3        TYPE lvc_s_stbl,
  gt_fieldcat3      TYPE lvc_t_fcat,
  gt_sort3          TYPE lvc_t_sort,
  gt_exclude3       TYPE ui_functions,
  gt_f4_3           TYPE lvc_t_f4,
  gt_rows3          TYPE lvc_t_row,
  gt_cols3          TYPE lvc_t_col,
  gt_dropdown3      TYPE lvc_t_drop,
  go_grid_c3        TYPE REF TO lcl_def_grid.



*----------------------------------------------------------------------*
* ALV 관련 CLASS
*----------------------------------------------------------------------*
*-- LOCAL ALV GRID CLASS DEFINITION ----------------------------------*
*----------------------------------------------------------------------*
*       CLASS lcl_def_grid1 DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_def_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
  PUBLIC SECTION.

    METHODS:
      m_set_fixed_rows,

      m_set_resize_cols,

      m_scroll_to_bottom,

      m_optimize_all_cols,

      m_set_current_cell_base
        IMPORTING
          row TYPE i
          col TYPE i.

ENDCLASS. "lcl_def_grid DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_def_grid IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_def_grid IMPLEMENTATION.

  METHOD  m_set_fixed_rows.
    CALL METHOD me->set_fixed_rows
      EXPORTING
        rows 1.
  ENDMETHOD.                    " M_SET_FIXED_ROWS

  METHOD  m_set_resize_cols.
    CALL METHOD me->set_resize_cols
      EXPORTING
        enable 1.   " NO
  ENDMETHOD.                    " M_SET_RESIZE_COLS

  METHOD  m_scroll_to_bottom.
    CALL METHOD me->scroll_to_bottom.
  ENDMETHOD.                    " M_SCROLL_TO_BOTTOM

  METHOD  m_set_current_cell_base.
    CALL METHOD me->set_current_cell_base
      EXPORTING
        row row
        col col.
  ENDMETHOD.                    " M_SET_CURRENT_CELL_BASE

  METHOD m_optimize_all_cols.
    CALL METHOD me->optimize_all_cols
      EXPORTING
        include_header 1.
  ENDMETHOD.                    " m_optimize_all_cols

ENDCLASS. " lcl_def_grid IMPLEMENTATION

*&---------------------------------------------------------------------*
*  CL_GUI_RESOURCES DEFINITION LOAD
*&---------------------------------------------------------------------*
CLASS cl_gui_object DEFINITION LOAD.
CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA: go_event_rcvr TYPE REF TO lcl_event_receiver.
*----------------------------------------------------------------------*
*       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.
    METHODS : handle_user_command
                 FOR EVENT user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.
    METHODS : handle_data_changed
                 FOR EVENT data_changed OF cl_gui_alv_grid
                 IMPORTING er_data_changed.
    METHODS : handle_data_changed_finished
                 FOR EVENT data_changed_finished OF cl_gui_alv_grid
                 IMPORTING e_modified et_good_cells.
    METHODS : handle_hotspot_click
                 FOR EVENT hotspot_click OF cl_gui_alv_grid
                 IMPORTING e_row_id
                           e_column_id.
    METHODS : handle_double_click
                 FOR EVENT double_click OF cl_gui_alv_grid
                 IMPORTING e_row
                           e_column
                           es_row_no.
    METHODS : handle_on_f4
                 FOR EVENT onf4 OF cl_gui_alv_grid
                 IMPORTING sender
                           e_fieldname
                           e_fieldvalue
                           es_row_no
                           er_event_data
                           et_bad_cells
                           e_display.
    METHODS : handle_top_of_page
                 FOR EVENT top_of_page OF cl_gui_alv_grid
                 IMPORTING e_dyndoc_id.
    METHODS : handle_before_user_command
                 FOR EVENT before_user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.
    METHODS : handle_after_user_command
                 FOR EVENT after_user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm
                           e_not_processed
                           e_saved.

ENDCLASS. "lcl_event_receiver DEFINITION

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

  METHOD handle_toolbar.
    PERFORM handle_toolbar IN PROGRAM (g_repid)  IF FOUND
                        USING e_object e_interactive.
  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
    PERFORM handle_user_command IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm.
  ENDMETHOD.                    "handle_user_command
  METHOD handle_data_changed.
    PERFORM handle_data_changed IN PROGRAM (g_repidIF FOUND
                        USING er_data_changed.
  ENDMETHOD.                    "handle_data_changed
  METHOD handle_data_changed_finished.
    PERFORM handle_data_changed_finished IN PROGRAM (g_repidIF FOUND
                        USING  e_modified et_good_cells.
  ENDMETHOD.                    "handle_data_changed_finished
  METHOD handle_hotspot_click.
    PERFORM handle_hotspot_click IN PROGRAM (g_repidIF FOUND
                        USING e_row_id e_column_id.
  ENDMETHOD.                    "handle_hotspot_click
  METHOD handle_double_click.
    PERFORM handle_double_click IN PROGRAM (g_repidIF FOUND
                        USING e_row e_column es_row_no.
  ENDMETHOD.                    "handle_double_click
  METHOD handle_on_f4.
    PERFORM handle_on_f4 IN PROGRAM (g_repidIF FOUND
                        USING sender
                              e_fieldname
                              e_fieldvalue
                              es_row_no
                              er_event_data
                              et_bad_cells
                              e_display.
  ENDMETHOD.                    "handle_on_f4
  METHOD handle_top_of_page.
    PERFORM handle_top_of_page IN PROGRAM (g_repidIF FOUND
                        USING e_dyndoc_id.
  ENDMETHOD.                    "handle_top_of_page
  METHOD handle_before_user_command.
    PERFORM handle_before_user_command IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm.
  ENDMETHOD.                    "before_user_command
  METHOD handle_after_user_command.
    PERFORM handle_after_user_command IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm
                              e_not_processed
                              e_saved.
  ENDMETHOD.                    "after_user_command

ENDCLASS. "lcl_event_receiver IMPLEMENTATION


CLASS lcl_event_receiver2 DEFINITION DEFERRED.
DATA: go_event_rcvr2 TYPE REF TO lcl_event_receiver2.
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER2 DEFINITION
*----------------------------------------------------------------------*
*       ........                                                       *
*----------------------------------------------------------------------*
CLASS lcl_event_receiver2 DEFINITION.
  PUBLIC SECTION.

    METHODS : handle_toolbar
                 FOR EVENT toolbar OF cl_gui_alv_grid
                 IMPORTING e_object
                           e_interactive.
    METHODS : handle_user_command
                 FOR EVENT user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.
    METHODS : handle_data_changed
                 FOR EVENT data_changed OF cl_gui_alv_grid
                 IMPORTING er_data_changed.
    METHODS : handle_data_changed_finished
                 FOR EVENT data_changed_finished OF cl_gui_alv_grid
                 IMPORTING e_modified et_good_cells.
    METHODS : handle_hotspot_click
                 FOR EVENT hotspot_click OF cl_gui_alv_grid
                 IMPORTING e_row_id
                           e_column_id.
    METHODS : handle_double_click
                 FOR EVENT double_click OF cl_gui_alv_grid
                 IMPORTING e_row
                           e_column
                           es_row_no.
    METHODS : handle_on_f4
                 FOR EVENT onf4 OF cl_gui_alv_grid
                 IMPORTING sender
                           e_fieldname
                           e_fieldvalue
                           es_row_no
                           er_event_data
                           et_bad_cells
                           e_display.
    METHODS : handle_top_of_page
                 FOR EVENT top_of_page OF cl_gui_alv_grid
                 IMPORTING e_dyndoc_id.
    METHODS : handle_before_user_command
                 FOR EVENT before_user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.
    METHODS : handle_after_user_command
                 FOR EVENT after_user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm
                           e_not_processed
                           e_saved.

ENDCLASS. "lcl_event_receiver2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver2 IMPLEMENTATION
*----------------------------------------------------------------------*
*       ........                                                       *
*----------------------------------------------------------------------*
CLASS lcl_event_receiver2 IMPLEMENTATION.

  METHOD handle_toolbar.
    PERFORM handle_toolbar2 IN PROGRAM (g_repid)  IF FOUND
                        USING e_object e_interactive.
  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
    PERFORM handle_user_command2 IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm.
  ENDMETHOD.                    "handle_user_command
  METHOD handle_data_changed.
    PERFORM handle_data_changed2 IN PROGRAM (g_repidIF FOUND
                        USING er_data_changed.
  ENDMETHOD.                    "handle_data_changed
  METHOD handle_data_changed_finished.
    PERFORM handle_data_changed_finished2 IN PROGRAM (g_repidIF FOUND
                        USING  e_modified et_good_cells.
  ENDMETHOD.                    "handle_data_changed_finished
  METHOD handle_hotspot_click.
    PERFORM handle_hotspot_click2 IN PROGRAM (g_repidIF FOUND
                        USING e_row_id e_column_id.
  ENDMETHOD.                    "handle_hotspot_click
  METHOD handle_double_click.
    PERFORM handle_double_click2 IN PROGRAM (g_repidIF FOUND
                        USING e_row e_column es_row_no.
  ENDMETHOD.                    "handle_double_click
  METHOD handle_on_f4.
    PERFORM handle_on_f4_2 IN PROGRAM (g_repidIF FOUND
                        USING sender
                              e_fieldname
                              e_fieldvalue
                              es_row_no
                              er_event_data
                              et_bad_cells
                              e_display.
  ENDMETHOD.                    "handle_on_f4
  METHOD handle_top_of_page.
    PERFORM handle_top_of_page2 IN PROGRAM (g_repidIF FOUND
                        USING e_dyndoc_id.
  ENDMETHOD.                    "handle_top_of_page
  METHOD handle_before_user_command.
    PERFORM handle_before_user_command2 IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm.
  ENDMETHOD.                    "before_user_command
  METHOD handle_after_user_command.
    PERFORM handle_after_user_command2 IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm
                              e_not_processed
                              e_saved.
  ENDMETHOD.                    "after_user_command

ENDCLASS. "lcl_event_receiver2 IMPLEMENTATION


CLASS lcl_event_receiver3 DEFINITION DEFERRED.
DATA: go_event_rcvr3 TYPE REF TO lcl_event_receiver3.
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER3 DEFINITION
*----------------------------------------------------------------------*
*       ........                                                       *
*----------------------------------------------------------------------*
CLASS lcl_event_receiver3 DEFINITION.
  PUBLIC SECTION.

    METHODS : handle_toolbar
                 FOR EVENT toolbar OF cl_gui_alv_grid
                 IMPORTING e_object
                           e_interactive.
    METHODS : handle_user_command
                 FOR EVENT user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.
    METHODS : handle_data_changed
                 FOR EVENT data_changed OF cl_gui_alv_grid
                 IMPORTING er_data_changed.
    METHODS : handle_data_changed_finished
                 FOR EVENT data_changed_finished OF cl_gui_alv_grid
                 IMPORTING e_modified et_good_cells.
    METHODS : handle_hotspot_click
                 FOR EVENT hotspot_click OF cl_gui_alv_grid
                 IMPORTING e_row_id
                           e_column_id.
    METHODS : handle_double_click
                 FOR EVENT double_click OF cl_gui_alv_grid
                 IMPORTING e_row
                           e_column
                           es_row_no.
    METHODS : handle_on_f4
                 FOR EVENT onf4 OF cl_gui_alv_grid
                 IMPORTING sender
                           e_fieldname
                           e_fieldvalue
                           es_row_no
                           er_event_data
                           et_bad_cells
                           e_display.
    METHODS : handle_top_of_page
                 FOR EVENT top_of_page OF cl_gui_alv_grid
                 IMPORTING e_dyndoc_id.
    METHODS : handle_before_user_command
                 FOR EVENT before_user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm.
    METHODS : handle_after_user_command
                 FOR EVENT after_user_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm
                           e_not_processed
                           e_saved.

ENDCLASS. "lcl_event_receiver3 DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver3 IMPLEMENTATION
*----------------------------------------------------------------------*
*       ........                                                       *
*----------------------------------------------------------------------*
CLASS lcl_event_receiver3 IMPLEMENTATION.

  METHOD handle_toolbar.
    PERFORM handle_toolbar3 IN PROGRAM (g_repid)  IF FOUND
                        USING e_object e_interactive.
  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
    PERFORM handle_user_command3 IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm.
  ENDMETHOD.                    "handle_user_command
  METHOD handle_data_changed.
    PERFORM handle_data_changed3 IN PROGRAM (g_repidIF FOUND
                        USING er_data_changed.
  ENDMETHOD.                    "handle_data_changed
  METHOD handle_data_changed_finished.
    PERFORM handle_data_changed_finished3 IN PROGRAM (g_repidIF FOUND
                        USING  e_modified et_good_cells.
  ENDMETHOD.                    "handle_data_changed_finished
  METHOD handle_hotspot_click.
    PERFORM handle_hotspot_click3 IN PROGRAM (g_repidIF FOUND
                        USING e_row_id e_column_id.
  ENDMETHOD.                    "handle_hotspot_click
  METHOD handle_double_click.
    PERFORM handle_double_click3 IN PROGRAM (g_repidIF FOUND
                        USING e_row e_column es_row_no.
  ENDMETHOD.                    "handle_double_click
  METHOD handle_on_f4.
    PERFORM handle_on_f4_3 IN PROGRAM (g_repidIF FOUND
                        USING sender
                              e_fieldname
                              e_fieldvalue
                              es_row_no
                              er_event_data
                              et_bad_cells
                              e_display.
  ENDMETHOD.                    "handle_on_f4
  METHOD handle_top_of_page.
    PERFORM handle_top_of_page3 IN PROGRAM (g_repidIF FOUND
                        USING e_dyndoc_id.
  ENDMETHOD.                    "handle_top_of_page
  METHOD handle_before_user_command.
    PERFORM handle_before_user_command3 IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm.
  ENDMETHOD.                    "before_user_command
  METHOD handle_after_user_command.
    PERFORM handle_after_user_command3 IN PROGRAM (g_repidIF FOUND
                        USING e_ucomm
                              e_not_processed
                              e_saved.
  ENDMETHOD.                    "after_user_command

ENDCLASS. "lcl_event_receiver3 IMPLEMENTATION


*----------------------------------------------------------------------*
* ALV 관련 Forms
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CREATE_GRID_CONTAINER
*&---------------------------------------------------------------------*
FORM create_grid_container  USING  p_parent
                                   po_grid  TYPE REF TO cl_gui_alv_grid
                                   p_appl.

  CHECK po_grid IS INITIAL.
  CREATE OBJECT po_grid
    EXPORTING
      i_parent      p_parent
      i_appl_events p_appl.

ENDFORM.                    "create_grid_container

*&---------------------------------------------------------------------*
*&      Form  SET_GRID_VARI
*&---------------------------------------------------------------------*
FORM set_grid_vari  USING    p_handle    TYPE slis_handl
                             p_log_group TYPE slis_loggr
                             p_variant   TYPE slis_vari
                    CHANGING cs_vari     TYPE disvariant.

  cs_vari-report      sy-repid.
  cs_vari-handle      p_handle.
  cs_vari-log_group   p_log_group.
  cs_vari-username    sy-uname.
  cs_vari-variant     p_variant.
  cs_vari-text        space.
  cs_vari-dependvars  space.

ENDFORM.                    " SET_GRID_VARI

*&---------------------------------------------------------------------*
*&      Form  SET_GRID_LAYOUT
*&---------------------------------------------------------------------*
FORM set_grid_layout USING   p_opt
                             p_zebra
                             p_box
                             p_sel_mode
                             p_celltab
                             p_title
                             p_smalltitle
                             p_no_toolbar
                             p_info_fname
                             p_ctab_fname
                    CHANGING ps_layout TYPE lvc_s_layo.

  CLEAR ps_layout.
  ps_layout-cwidth_opt  p_opt.
  ps_layout-zebra       p_zebra.
  ps_layout-sel_mode    p_sel_mode.
  ps_layout-box_fname   p_box.
  ps_layout-stylefname  p_celltab.
  ps_layout-grid_title  p_title.
  ps_layout-smalltitle  p_smalltitle.
  ps_layout-no_toolbar  p_no_toolbar.
  ps_layout-info_fname  p_info_fname.
  ps_layout-ctab_fname  p_ctab_fname.

ENDFORM.                    " SET_GRID_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  append_grid_fieldcat
*&---------------------------------------------------------------------*
FORM append_grid_fieldcat TABLES   pt_fieldcat TYPE lvc_t_fcat
                          USING    p_key
                                   p_fieldname
                                   p_ref_table
                                   p_ref_field
                                   p_scrtext
                                   p_outputlen
                                   p_col_opt
                                   p_edit
                                   p_f4availabl
                                   p_sum
                                   p_cfieldname
                                   p_no_out
                                   p_color
                          CHANGING p_pos.

  p_pos p_pos + 1.
  CLEAR gs_fieldcat.
  gs_fieldcat-col_pos    p_pos.
  gs_fieldcat-key        p_key.
  gs_fieldcat-fieldname  p_fieldname.
  gs_fieldcat-ref_table  p_ref_table.
  gs_fieldcat-ref_field  p_ref_field.
  gs_fieldcat-outputlen  p_outputlen.
  gs_fieldcat-col_opt    p_col_opt.
  gs_fieldcat-edit       p_edit.
  gs_fieldcat-f4availabl p_f4availabl.
  gs_fieldcat-cfieldname p_cfieldname.
  gs_fieldcat-do_sum     p_sum.
  gs_fieldcat-no_out     p_no_out.
  gs_fieldcat-emphasize  p_color.
  gs_fieldcat-reptext    p_scrtext.
  gs_fieldcat-coltext    p_scrtext.
  gs_fieldcat-scrtext_l  p_scrtext.
  gs_fieldcat-scrtext_m  p_scrtext.
  gs_fieldcat-scrtext_s  p_scrtext.
  gs_fieldcat-colddictxt 'M'.
  APPEND gs_fieldcat TO  pt_fieldcat.

ENDFORM.                    "append_grid_fieldcat

*&---------------------------------------------------------------------*
*&      Form  register_event_handler
*&---------------------------------------------------------------------*
FORM register_event_handler
  USING  po_grid           TYPE REF TO cl_gui_alv_grid
         po_event_receiver TYPE REF TO lcl_event_receiver
         p_toolbar
         p_user_command
         p_data_changed
         p_data_changed_finished
         p_hotspot_click
         p_double_click
         p_on_f4
         p_top_of_page
         p_before_user_command
         p_after_user_command.

  DEFINE %set_handler.
    if &1 eq abap_true.
      set handler po_event_receiver->&2 for po_grid.
    endif.
  END-OF-DEFINITION.

* create event receiver
  po_grid->register_edit_eventcl_gui_alv_grid=>mc_evt_enter ).
  po_grid->register_edit_eventcl_gui_alv_grid=>mc_evt_modified ).
  CREATE OBJECT po_event_receiver.

* register handler
  %set_handler:
    p_toolbar               handle_toolbar,
    p_user_command          handle_user_command,
    p_data_changed          handle_data_changed,
    p_data_changed_finished handle_data_changed_finished,
    p_hotspot_click         handle_hotspot_click,
    p_double_click          handle_double_click,
    p_on_f4                 handle_on_f4,
    p_top_of_page           handle_top_of_page,
    p_before_user_command   handle_before_user_command,
    p_after_user_command    handle_after_user_command.

ENDFORM.                    "register_event_handler

*&---------------------------------------------------------------------*
*&      Form  append_exclude_functions
*&---------------------------------------------------------------------*
FORM append_exclude_functions  TABLES p_table
                                USING p_value.

  DATA:
    ls_exclude TYPE ui_func.

  ls_exclude p_value.
  APPEND ls_exclude TO p_table.

ENDFORM.                    "append_exclude_functions

*&---------------------------------------------------------------------*
*&      Form  display_alv_grid
*&---------------------------------------------------------------------*
FORM display_alv_grid  USING p_table
                             po_grid     TYPE REF TO cl_gui_alv_grid
                             p_variant   TYPE disvariant
                             p_layout    TYPE lvc_s_layo
                             pt_exclude  TYPE ui_functions
                             pt_fieldcat TYPE lvc_t_fcat
                             pt_sort     TYPE lvc_t_sort.

  DATA:
    l_table LIKE feld-name.

  FIELD-SYMBOLS <fs_table> TYPE STANDARD TABLE.
  CONCATENATE p_table '[]' INTO l_table.
  ASSIGN (l_tableTO <fs_table>.

  CALL METHOD po_grid->set_table_for_first_display
    EXPORTING
      i_buffer_active      'X'
      i_bypassing_buffer   ' '
      i_save               'A'
      is_variant           p_variant
      is_layout            p_layout
      it_toolbar_excluding pt_exclude
    CHANGING
      it_fieldcatalog      pt_fieldcat
      it_sort              pt_sort
      it_outtab            <fs_table>.

ENDFORM.                    "display_alv_grid

*&---------------------------------------------------------------------*
*&      Form  switch_edit_mode
*&---------------------------------------------------------------------*
FORM switch_edit_mode   USING  po_grid  TYPE REF TO cl_gui_alv_grid.

  CASE po_grid->is_ready_for_input).
*-- set edit enabled cells ready for input
    WHEN 0. po_grid->set_ready_for_input).
*-- lock edit enabled cells against input
    WHEN 1. po_grid->set_ready_for_input).
  ENDCASE.

ENDFORM.                    "switch_edit_mode
*&---------------------------------------------------------------------*
*&      Form  refresh_grid_table
*&---------------------------------------------------------------------*
*  ALV GRID 내용을 REFRESH 한다
*&---------------------------------------------------------------------*
FORM refresh_grid_table USING po_grid   TYPE REF TO cl_gui_alv_grid
                              ps_stable TYPE lvc_s_stbl.

  CALL METHOD po_grid->refresh_table_display
    EXPORTING
      is_stable ps_stable
    EXCEPTIONS
      finished  1
      OTHERS    2.

ENDFORM.                    "refresh_grid_table

*&---------------------------------------------------------------------*
*&      Form  REFRESH_GRID_TABLE_WITH_FCAT
*&---------------------------------------------------------------------*
*  ALV GRID 내용을 REFRESH 한다 (WITH FIELDCATALOG)
*----------------------------------------------------------------------*
FORM refresh_grid_table_with_fcat
  USING po_grid   TYPE REF TO cl_gui_alv_grid
        pt_fcat   TYPE lvc_t_fcat
        ps_stable TYPE lvc_s_stbl.

  PERFORM set_grid_frontend_fcat USING po_grid pt_fcat[].

  CALL METHOD po_grid->refresh_table_display
    EXPORTING
      is_stable ps_stable
    EXCEPTIONS
      finished  1
      OTHERS    2.

ENDFORM.                    "refresh_grid_table_with_fcat

*&---------------------------------------------------------------------*
*&      Form  set_grid_frontend_fcat
*&---------------------------------------------------------------------*
FORM set_grid_frontend_fcat USING po_grid TYPE REF TO cl_gui_alv_grid
                                  pt_fcat TYPE lvc_t_fcat.

  CALL METHOD po_grid->set_frontend_fieldcatalog
    EXPORTING
      it_fieldcatalog pt_fcat[].

ENDFORM.                    "set_grid_frontend_fcat

*&---------------------------------------------------------------------*
*&      Form  get_grid_frontend_fcat
*&---------------------------------------------------------------------*
FORM get_grid_frontend_fcat USING    po_grid TYPE REF TO cl_gui_alv_grid
                            CHANGING pt_fcat TYPE lvc_t_fcat.

  CALL METHOD po_grid->get_frontend_fieldcatalog
    IMPORTING
      et_fieldcatalog pt_fcat[].

ENDFORM.                    "get_grid_frontend_fcat

*&---------------------------------------------------------------------*
*&      Form  SET_DROP_DOWN_TABLE
*&---------------------------------------------------------------------*
FORM set_drop_down_table USING po_grid     TYPE REF TO cl_gui_alv_grid
                               pt_dropdown TYPE lvc_t_drop
                               pt_draldown TYPE lvc_t_dral .

  CALL METHOD po_grid->set_drop_down_table
    EXPORTING
      it_drop_down       pt_dropdown[]
      it_drop_down_alias pt_draldown[].

ENDFORM.                    "set_drop_down_table

*&---------------------------------------------------------------------*
*&      Form  CREATE_DOCKING_CONTAINER
*&---------------------------------------------------------------------*
FORM create_docking_container
  USING  po_docking TYPE REF TO cl_gui_docking_container
         p_side
         p_extension.

  IF NOT po_docking IS INITIAL.
    CALL METHOD po_docking->free.
  ENDIF.

  CREATE OBJECT po_docking
    EXPORTING
      repid     sy-repid
      dynnr     sy-dynnr
      side      p_side
      extension p_extension.

ENDFORM.                    "create_docking_container

*&---------------------------------------------------------------------*
*&      Form  CREATE_CUSTOM_CONTAINER
*&---------------------------------------------------------------------*
*   Custom Conainer 생성
*&---------------------------------------------------------------------*
FORM create_custom_container
  USING  po_custom   TYPE REF TO cl_gui_custom_container
         p_container TYPE scrfname.

  IF NOT po_custom IS INITIAL.
    CALL METHOD po_custom->free.
  ENDIF.
  CREATE OBJECT po_custom
    EXPORTING
      container_name              p_container
    EXCEPTIONS
      cntl_error                  1
      cntl_system_error           2
      create_error                3
      lifetime_error              4
      lifetime_dynpro_dynpro_link 5.

ENDFORM.                    "create_custom_container

*&---------------------------------------------------------------------*
*&      Form  ADD_DOC_TEXT
*&---------------------------------------------------------------------*
FORM add_doc_text USING po_doc TYPE REF TO cl_dd_document
                        p_text TYPE sdydo_text_element.

  CALL METHOD po_doc->add_text
    EXPORTING
      text         p_text
      sap_fontsize cl_dd_document=>small.

ENDFORM.                    "add_doc_text

*&---------------------------------------------------------------------*
*&      Form  ADD_DOC_TEXT
*&---------------------------------------------------------------------*
FORM add_doc_text_label USING po_doc TYPE REF TO cl_dd_document
                              p_text TYPE sdydo_text_element.

  CALL METHOD po_doc->add_text
    EXPORTING
      text         p_text
      sap_fontsize cl_dd_document=>small
      sap_emphasis cl_dd_document=>strong.

ENDFORM.                    "add_doc_text_label

*&---------------------------------------------------------------------*
*&      Form  ADD_changed_alv_MSG
*&---------------------------------------------------------------------*
FORM add_changed_alv_msg
  USING  po_data_changed  TYPE REF TO cl_alv_changed_data_protocol
         ps_good          TYPE lvc_s_modi
         p_msgid
         p_msgno
         p_msgty
         p_msgv1
         p_msgv2
         p_msgv3
         p_msgv4.

  CALL METHOD po_data_changed->add_protocol_entry
    EXPORTING
      i_msgid     p_msgid
      i_msgno     p_msgno
      i_msgty     p_msgty
      i_msgv1     p_msgv1
      i_msgv2     p_msgv2
      i_msgv3     p_msgv3
      i_msgv4     p_msgv4
      i_fieldname ps_good-fieldname
      i_row_id    ps_good-row_id.

ENDFORM.                    "add_changed_alv_msg

*&---------------------------------------------------------------------*
*&      Form  LVC_FIELDCATALOG_MERGE
*&---------------------------------------------------------------------*
FORM lvc_fieldcatalog_merge TABLES pt_fcat TYPE lvc_t_fcat
                            USING  p_type
                                   p_tabnm.

  DATA:
    lt_fieldcat_slis   TYPE slis_t_fieldcat_alv,
    lt_fieldcat_kkblo  TYPE kkblo_t_fieldcat,
    l_structure_name   TYPE dd02l-tabname,
    l_internal_tabname TYPE dd02l-tabname.

  REFRESH pt_fcat.

  CASE p_type.
    WHEN 'S'.
      l_structure_name   p_tabnm.

      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       l_structure_name
        CHANGING
          ct_fieldcat            pt_fcat[]
        EXCEPTIONS
          inconsistent_interface 1
          program_error          2
          OTHERS                 3.

    WHEN 'I'.
      l_internal_tabname p_tabnm.

      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         g_repid
          i_internal_tabname     l_internal_tabname
          i_inclname             g_repid
        CHANGING
          ct_fieldcat            lt_fieldcat_slis
        EXCEPTIONS
          inconsistent_interface 1
          program_error          2.

      CALL FUNCTION 'REUSE_ALV_TRANSFER_DATA'
        EXPORTING
          it_fieldcat lt_fieldcat_slis
        IMPORTING
          et_fieldcat lt_fieldcat_kkblo.

      CALL FUNCTION 'LVC_TRANSFER_FROM_KKBLO'
        EXPORTING
          it_fieldcat_kkblo lt_fieldcat_kkblo
        IMPORTING
          et_fieldcat_lvc   pt_fcat[]
        EXCEPTIONS
          it_data_missing   1
          OTHERS            2.
  ENDCASE.

ENDFORM.                    "lvc_fieldcatalog_merge

*&---------------------------------------------------------------------*
*&      Form  HTML
*&---------------------------------------------------------------------*
FORM show_document_as_html
  USING po_parent
        po_html_viewer TYPE REF TO cl_gui_html_viewer
        po_document    TYPE REF TO cl_dd_document.

  DATA:
    l_length        TYPE i,                           " Length
    l_background_id TYPE sdydo_key VALUE space.       " Background_id

* Create HTML Viewer
  IF po_html_viewer IS INITIAL.
    CREATE OBJECT po_html_viewer
      EXPORTING
        parent po_parent.
  ENDIF.

* Set ALV Grid Commentary
  CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
    EXPORTING
      document po_document
      bottom   space
    IMPORTING
      length   l_length.
  CALL METHOD po_document->merge_document.

* Display Document
  po_document->html_control po_html_viewer.
  CALL METHOD po_document->display_document
    EXPORTING
      reuse_control      'X'
      parent             po_parent
    EXCEPTIONS
      html_display_error 1.

ENDFORM.                    "show_document_as_html

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_PROTOCOL
*&---------------------------------------------------------------------*
FORM display_protocol
  USING pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

  pr_data_changed->display_protocol).

ENDFORM.                    "display_protocol

*&---------------------------------------------------------------------*
*&      Form  SET_ALV_FOCUS
*&---------------------------------------------------------------------*
FORM set_alv_focus USING po_grid TYPE REF TO cl_gui_alv_grid
                         p_row.

  CHECK p_row <> 0.
  gs_rowno-row_id p_row.
  CALL METHOD cl_gui_control=>set_focus
    EXPORTING
      control po_grid.
  CALL METHOD po_grid->set_current_cell_via_id
    EXPORTING
      is_row_no gs_rowno.
  CLEAR p_row.

ENDFORM.                    "set_alv_focus

*&---------------------------------------------------------------------*
*&      Form  SET_ALV_FOCUS_CELL
*&---------------------------------------------------------------------*
FORM set_alv_focus_cell USING po_grid TYPE REF TO cl_gui_alv_grid
                              p_row
                              p_colname.

  CHECK p_row NE 0.
  gs_rowno-row_id   p_row.
  gs_cols-fieldname p_colname.
  CALL METHOD cl_gui_control=>set_focus
    EXPORTING
      control po_grid.
  CALL METHOD po_grid->set_current_cell_via_id
    EXPORTING
      is_column_id gs_cols
      is_row_no    gs_rowno.
  CLEAR p_row.

ENDFORM.                    "set_alv_focus_cell

*&---------------------------------------------------------------------*
*&      Form  SET_GRID_F4_FLD
*&---------------------------------------------------------------------*
FORM set_grid_f4_fld USING    p_fieldname
                     CHANGING pt_f4 TYPE lvc_t_f4.

  CLEAR: gs_f4.
  gs_f4-fieldname  p_fieldname.
  gs_f4-register   'X'.
  gs_f4-getbefore  space.
  gs_f4-chngeafter space.
  APPEND gs_f4 TO pt_f4.

ENDFORM.                    "set_grid_f4_fld

*&---------------------------------------------------------------------*
*&      Form  CREATE_TABLE
*&---------------------------------------------------------------------*
* 헤더에 텍스트를 출력하기 위한 테이블 생성.
*----------------------------------------------------------------------*
FORM create_table USING po_doc     TYPE REF TO cl_dd_document
                        po_text    TYPE REF TO cl_dd_table_element
                        po_column1 TYPE REF TO cl_dd_area
                        po_column2 TYPE REF TO cl_dd_area
                        po_column3 TYPE REF TO cl_dd_area.

*-- 텍스트 테이블 추가.
  CALL METHOD po_doc->add_table
    EXPORTING
      no_of_columns      3
      border             '0'
    IMPORTING
      table              po_text
    EXCEPTIONS
      table_already_used 1
      OTHERS             2.

*-- 컬럼 추가
*-- column1 - label
  CALL METHOD po_text->add_column
    IMPORTING
      column              po_column1
    EXCEPTIONS
      column_already_used 1
      OTHERS              2.

*-- column2 - 여유공간
  CALL METHOD po_text->add_column
    EXPORTING
      width               '20'
    IMPORTING
      column              po_column2
    EXCEPTIONS
      column_already_used 1
      OTHERS              2.

*-- column3 - text
  CALL METHOD po_text->add_column
    IMPORTING
      column              po_column3
    EXCEPTIONS
      column_already_used 1
      OTHERS              2.

ENDFORM.                    "create_table

*&---------------------------------------------------------------------*
*&      Form  NEW_LINE_WITH_TABLE
*&---------------------------------------------------------------------*
* 텍스트 테이블을 가지고, label과 text를 한 줄씩 추가한다.
*----------------------------------------------------------------------*
FORM new_line_with_table
  USING po_doc     TYPE REF TO cl_dd_document
        po_text    TYPE REF TO cl_dd_table_element
        po_column1 TYPE REF TO cl_dd_area
        po_column2 TYPE REF TO cl_dd_area
        po_column3 TYPE REF TO cl_dd_area
        p_label    TYPE sdydo_text_element
        p_text     TYPE sdydo_text_element.

*-- label
  CALL METHOD po_column1->add_text
    EXPORTING
      text         p_label
      sap_fontsize cl_dd_document=>small
      sap_emphasis cl_dd_document=>strong.

*-- 여유공간
  CALL METHOD po_column2->add_text
    EXPORTING
      text         ' '
      sap_fontsize cl_dd_document=>small
      sap_emphasis cl_dd_document=>strong.

*-- text
  CALL METHOD po_column3->add_text
    EXPORTING
      text         p_text
      sap_fontsize cl_dd_document=>small.

*-- 신규 row
  CALL METHOD po_text->new_row).

ENDFORM.                    "new_line_with_table

*&---------------------------------------------------------------------*
*&      Form  CREATE_GRID_CONTAINER
*&---------------------------------------------------------------------*
*   특정 상위 container안에 Custom Container 생성
*           with Local Grid Class
*&---------------------------------------------------------------------*
FORM create_grid_container_c
  USING  p_parent
         po_grid_c  TYPE REF TO lcl_def_grid
         po_grid    TYPE REF TO cl_gui_alv_grid
         p_appl.

  CHECK po_grid IS INITIAL.
  IF po_grid_c IS NOT INITIAL.
    po_grid_c->free).
  ENDIF.
  CREATE OBJECT po_grid_c
    EXPORTING
      i_parent      p_parent
      i_appl_events p_appl.
  po_grid ?= po_grid_c.

ENDFORM.                    "create_grid_container_c

*&---------------------------------------------------------------------*
*&      Form  GET_MODIFIED_ALV_CELL
*&---------------------------------------------------------------------*
FORM get_modified_alv_cell
  USING    pr_data_changed TYPE REF TO cl_alv_changed_data_protocol
           ps_good         TYPE lvc_s_modi
           p_fname
  CHANGING p_value.

  DATA:
    ls_fcat TYPE lvc_s_fcat,
    ls_cell TYPE lvc_s_modi.

  FIELD-SYMBOLS:
    <lfs_it> TYPE table,
    <lfs_wa>,
    <lfs_val>.

  ASSIGN pr_data_changed->mp_mod_rows->TO <lfs_it>.
  READ TABLE <lfs_it> ASSIGNING <lfs_wa> INDEX ps_good-tabix.
  ASSIGN COMPONENT p_fname OF STRUCTURE <lfs_wa> TO <lfs_val>.

*-- 이미 수정된 값인지 체크
  IF <lfs_val> IS NOT INITIAL.
    p_value <lfs_val>.
  ELSE.

*-- 수정될 값으로 읽음
    READ TABLE pr_data_changed->mt_fieldcatalog INTO ls_fcat
                           WITH KEY fieldname p_fname.
    IF ls_fcat-edit EQ abap_true.
      READ TABLE pr_data_changed->mt_mod_cells INTO ls_cell
                           WITH KEY row_id    ps_good-row_id
                                    fieldname p_fname.
      IF sy-subrc EQ 0.
        p_value ls_cell-value.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    "get_modified_alv_cell

*&---------------------------------------------------------------------*
*&      Form  MODIFY_MODIFIED_ALV_CELL
*&---------------------------------------------------------------------*
FORM modify_modified_alv_cell
  USING pr_data_changed TYPE REF TO cl_alv_changed_data_protocol
        ps_good         TYPE lvc_s_modi
        p_fname
        p_value.

  CALL METHOD pr_data_changed->modify_cell
    EXPORTING
      i_row_id    ps_good-row_id
      i_fieldname p_fname
      i_value     p_value.

ENDFORM.                    "modify_modified_alv_cell

*&---------------------------------------------------------------------*
*&      Form  DELETE_ALV_INSERTED_ROWS
*&---------------------------------------------------------------------*
FORM delete_alv_inserted_rows
  USING pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

  FIELD-SYMBOLS:
    <outtab> TYPE table.

  CHECK pr_data_changed->mt_inserted_rows[] IS NOT INITIAL.

  ASSIGN pr_data_changed->mp_mod_rows->TO <outtab>.
  DELETE <outtab>                          FROM 1.
  DELETE pr_data_changed->mt_good_cells    FROM 1.
  DELETE pr_data_changed->mt_mod_cells     FROM 1.
  DELETE pr_data_changed->mt_roid_front    FROM 1.
  DELETE pr_data_changed->mt_inserted_rows FROM 1.

ENDFORM.                    "delete_alv_inserted_rows




자 그럼.. 실제 구현부분을 보자.. 스크린에서 alv 부를때..

100번 스크린에 이렇게 구현해놨다.

  PROCESS BEFORE OUTPUT.
  MODULE status_0100.
  MODULE set_alv_grid_0100.  <- 이 부분만 보자.. 특별히 뭐 이벤트를 쓰진 않아서 PAI는 간단하다..
  거의 템플릿 처럼 생각해도 된다. 구현이 쉽게 만들어진 로직이다.
PROCESS AFTER INPUT.
  MODULE exit AT EXIT-COMMAND.
 



*&---------------------------------------------------------------------*
*&      Module  SET_ALV_GRID_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_alv_grid_0100 OUTPUT.

  PERFORM set_alv_grid_0100.  <-여기를 들어가보니.. 아래와 같다.

ENDMODULE.         
 



*&---------------------------------------------------------------------*
*&      Form  SET_ALV_GRID_0100
*&---------------------------------------------------------------------*
FORM set_alv_grid_0100 .

*-- container를 처음 생성하는 경우
  IF go_docking_container IS INITIAL.
*-- create docking container(super container)
    PERFORM create_docking_container  <- 이거 이미 탑선언 부분에 붙여넣었놓은 거다.
                                          보기만 해도 된다
      USING go_docking_container         그래도 하단에 하나하나씩 넣어주꾸마~
            cl_gui_docking_container=>dock_at_top
            900.

*-- create ALV grid container
    PERFORM create_grid_container USING go_docking_container  <- 2.
                                        go_grid ''.

*-- set gird variants
    PERFORM set_grid_vari USING    'A1' 'GR1' ''    <- 3
                          CHANGING gs_variant.

*-- set title
    PERFORM set_grid_title CHANGING g_grid_title.   <- 4. 이건 만들어줘야 되. 하단 꼭 봐

*-- set grid Layout
    PERFORM set_grid_layout USING    '' 'X' 'MARK' 'D' ''  <- 5.
                                     g_grid_title 'X' '' '' ''
                            CHANGING gs_layout.

*-- exclude toolbar functions
    PERFORM exclude_tb_functions CHANGING gt_exclude.     <- 6.

*-- set fieldcatalog
    PERFORM set_grid_fieldcatalog TABLES gt_fieldcat[].

*-- regiseter event handler
    PERFORM register_event_handler
      USING go_grid
            go_event_rcvr
            '' '' '' '' '' 'X' '' '' '' ''.

*-- display
    PERFORM display_alv_grid USING 'GT_COLIST'
                                    go_grid
                                    gs_variant
                                    gs_layout
                                    gt_exclude[]
                                    gt_fieldcat[]
                                    gt_sort[].
  ELSE.
*-- refresh
    PERFORM refresh_grid_0100 USING go_grid gs_stable.
  ENDIF.

  CALL METHOD cl_gui_cfw=>flush.

ENDFORM.                    " SET_ALV_GRID_0100
 


*&---------------------------------------------------------------------*
*&  1.    Form  CREATE_DOCKING_CONTAINER
*&---------------------------------------------------------------------*
FORM create_docking_container
  USING  po_docking TYPE REF TO cl_gui_docking_container
         p_side
         p_extension.

  IF NOT po_docking IS INITIAL.
    CALL METHOD po_docking->free.
  ENDIF.

  CREATE OBJECT po_docking
    EXPORTING
      repid     sy-repid
      dynnr     sy-dynnr
      side      p_side
      extension p_extension.

ENDFORM.                    "create_docking_container
 

*----------------------------------------------------------------------*
* ALV 관련 Forms
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&   2.   Form  CREATE_GRID_CONTAINER
*&---------------------------------------------------------------------*
FORM create_grid_container  USING  p_parent
                                   po_grid  TYPE REF TO cl_gui_alv_grid
                                   p_appl.

  CHECK po_grid IS INITIAL.
  CREATE OBJECT po_grid
    EXPORTING
      i_parent      p_parent
      i_appl_events p_appl.

ENDFORM.                    "create_grid_container
 

*&---------------------------------------------------------------------*
*&    3.  Form  SET_GRID_VARI
*&---------------------------------------------------------------------*
FORM set_grid_vari  USING    p_handle    TYPE slis_handl
                             p_log_group TYPE slis_loggr
                             p_variant   TYPE slis_vari
                    CHANGING cs_vari     TYPE disvariant.

  cs_vari-report      sy-repid.
  cs_vari-handle      p_handle.
  cs_vari-log_group   p_log_group.
  cs_vari-username    sy-uname.
  cs_vari-variant     p_variant.
  cs_vari-text        space.
  cs_vari-dependvars  space.

ENDFORM.                    " SET_GRID_VARI
 

*&---------------------------------------------------------------------*
*&   4.   Form  SET_GRID_TITLE
*&---------------------------------------------------------------------*
FORM set_grid_title  CHANGING p_grid_title TYPE lvc_title.

  DATA:
    l_entry TYPE i.

  l_entry LINESgt_colist[] ).
  WRITE l_entry TO p_grid_title.
  CONDENSE p_grid_title.

  CONCATENATE p_grid_title ` Entries`
         INTO p_grid_title.

ENDFORM.                    " SET_GRID_TITLE
 

*&---------------------------------------------------------------------*
*&     5.  Form  SET_GRID_LAYOUT
*&---------------------------------------------------------------------*
FORM set_grid_layout USING   p_opt
                             p_zebra
                             p_box
                             p_sel_mode
                             p_celltab
                             p_title
                             p_smalltitle
                             p_no_toolbar
                             p_info_fname
                             p_ctab_fname
                    CHANGING ps_layout TYPE lvc_s_layo.

  CLEAR ps_layout.
  ps_layout-cwidth_opt  p_opt.
  ps_layout-zebra       p_zebra.
  ps_layout-sel_mode    p_sel_mode.
  ps_layout-box_fname   p_box.
  ps_layout-stylefname  p_celltab.
  ps_layout-grid_title  p_title.
  ps_layout-smalltitle  p_smalltitle.
  ps_layout-no_toolbar  p_no_toolbar.
  ps_layout-info_fname  p_info_fname.
  ps_layout-ctab_fname  p_ctab_fname.

ENDFORM.                    " SET_GRID_LAYOUT
 


*&---------------------------------------------------------------------*
*&      Form  exclude_tb_functions
*&---------------------------------------------------------------------*
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.

*  CLEAR:
*    pt_exclude[].
*
*  PERFORM append_exclude_functions TABLES pt_exclude
*    USING:  cl_gui_alv_grid=>mc_fc_excl_all,
*            cl_gui_alv_grid=>mc_mb_subtot,
*            cl_gui_alv_grid=>mc_mb_sum,
*            cl_gui_alv_grid=>mc_fc_refresh,
*            cl_gui_alv_grid=>mc_fc_detail,
*            cl_gui_alv_grid=>mc_fc_views,
*            cl_gui_alv_grid=>mc_fc_find,
*            cl_gui_alv_grid=>mc_fc_filter,
*            cl_gui_alv_grid=>mc_fc_auf,
*            cl_gui_alv_grid=>mc_fc_loc_cut,
*            cl_gui_alv_grid=>mc_fc_loc_append_row,
*            cl_gui_alv_grid=>mc_fc_loc_copy,
*            cl_gui_alv_grid=>mc_fc_loc_copy_row,
*            cl_gui_alv_grid=>mc_fc_loc_undo,
*            cl_gui_alv_grid=>mc_fc_loc_paste,
*            cl_gui_alv_grid=>mc_fc_loc_paste_new_row,
*            cl_gui_alv_grid=>mc_fc_loc_insert_row,
*            cl_gui_alv_grid=>mc_fc_graph,
*            cl_gui_alv_grid=>mc_fc_help,
*            cl_gui_alv_grid=>mc_fc_info,
*            cl_gui_alv_grid=>mc_fc_average,
*            cl_gui_alv_grid=>mc_fc_expcrdata,
*            cl_gui_alv_grid=>mc_fc_loc_copy_row,
*            cl_gui_alv_grid=>mc_fc_loc_delete_row.

ENDFORM.                    " EXCLUDE_TB_FUNCTIONS
 

*&---------------------------------------------------------------------*
*&      Form  SET_GRID_FIELDCATALOG
*&---------------------------------------------------------------------*
FORM set_grid_fieldcatalog TABLES pt_fieldcat TYPE lvc_t_fcat.

  FIELD-SYMBOLS:
    <fieldcat> TYPE lvc_s_fcat.

  PERFORM lvc_fieldcatalog_merge TABLES pt_fieldcat  <- 이 부분이 포인트여!
                                 USING  'I' 'GS_COLIST'. top에 선언되어 있지만 넣어주지.

  LOOP AT pt_fieldcat
    ASSIGNING <fieldcat>.

    <fieldcat>-key     abap_false.
    <fieldcat>-col_opt abap_true.

    CASE <fieldcat>-fieldname.
      WHEN 'ZOFDBDTJ'.
        <fieldcat>-key       abap_true.
        <fieldcat>-tech      abap_true.

      WHEN 'ZOFDPOPR'.
        <fieldcat>-key       abap_true.
        <fieldcat>-tech      abap_true.

      WHEN 'ZOF0CONR'.
        <fieldcat>-key       abap_true.

      WHEN 'KUNNR'.
        <fieldcat>-key       abap_true.

      WHEN 'MATNR'.
        <fieldcat>-key       abap_true.

      WHEN 'WERKS'.
        <fieldcat>-key       abap_true.

      WHEN 'ZOF0AGNR'.
        <fieldcat>-key       abap_true.

      WHEN 'LAND1'.
        <fieldcat>-key       abap_true.

      WHEN 'ZOFORIGN'.
*        <fieldcat>-key       = abap_true.
*        <fieldcat>-no_out    = abap_true.
        <fieldcat>-seltext    <fieldcat>-coltext '당월 판정'.
        <fieldcat>-emphasize 'C310'.

      WHEN 'ZOFORIGN_E'.
*        <fieldcat>-key       = abap_true.
*        <fieldcat>-no_out    = abap_true.
        <fieldcat>-seltext    <fieldcat>-coltext '전월 판정'.

      WHEN 'ZOFCTH_E'.
        <fieldcat>-seltext    <fieldcat>-coltext '전월CTH충족'.

      WHEN  'ZOFCTH'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월CTH충족'.
        <fieldcat>-emphasize 'C310'.

      WHEN 'ZOFRVCBDC_E'.
        <fieldcat>-seltext    <fieldcat>-coltext '전월BD충족'.

      WHEN 'ZOFRVCBD'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월BD%'.
        <fieldcat>-emphasize 'C310'.

      WHEN 'ZOFRVCBDC'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월BD충족'.
        <fieldcat>-emphasize 'C310'.

      WHEN  'ZOFRVCBU_E'.
        <fieldcat>-seltext    <fieldcat>-coltext '전월BU%'.

      WHEN  'ZOFRVCBUC_E'.
        <fieldcat>-seltext    <fieldcat>-coltext '전월BU충족'.

      WHEN  'ZOFRVCBU'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월BU%'.
        <fieldcat>-emphasize 'C310'.

      WHEN  'ZOFRVCBUC'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월BU충족'.
        <fieldcat>-emphasize 'C310'.

      WHEN  'ZOFRVCNC_E'.
        <fieldcat>-seltext    <fieldcat>-coltext '전월NC%'.

      WHEN  'ZOFRVCNCC_E'.
        <fieldcat>-seltext    <fieldcat>-coltext '전월NC충족'.

      WHEN  'ZOFRVCNC'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월NC%'.
        <fieldcat>-emphasize 'C310'.

      WHEN  'ZOFRVCNCC'.
        <fieldcat>-seltext    <fieldcat>-coltext '당월NC충족'.
        <fieldcat>-emphasize 'C310'.

    ENDCASE.
  ENDLOOP.
ENDFORM.                    " SET_GRID_FIELDCATALOG
 

*&---------------------------------------------------------------------*
*&      Form  register_event_handler
*&---------------------------------------------------------------------*
FORM register_event_handler
  USING  po_grid           TYPE REF TO cl_gui_alv_grid
         po_event_receiver TYPE REF TO lcl_event_receiver
         p_toolbar
         p_user_command
         p_data_changed
         p_data_changed_finished
         p_hotspot_click
         p_double_click
         p_on_f4
         p_top_of_page
         p_before_user_command
         p_after_user_command.

  DEFINE %set_handler.
    if &1 eq abap_true.
      set handler po_event_receiver->&2 for po_grid.
    endif.
  END-OF-DEFINITION.

* create event receiver
  po_grid->register_edit_eventcl_gui_alv_grid=>mc_evt_enter ).
  po_grid->register_edit_eventcl_gui_alv_grid=>mc_evt_modified ).
  CREATE OBJECT po_event_receiver.

* register handler
  %set_handler:
    p_toolbar               handle_toolbar,
    p_user_command          handle_user_command,
    p_data_changed          handle_data_changed,
    p_data_changed_finished handle_data_changed_finished,
    p_hotspot_click         handle_hotspot_click,
    p_double_click          handle_double_click,
    p_on_f4                 handle_on_f4,
    p_top_of_page           handle_top_of_page,
    p_before_user_command   handle_before_user_command,
    p_after_user_command    handle_after_user_command.

ENDFORM.                    "register_event_handler
 

*&---------------------------------------------------------------------*
*&      Form  display_alv_grid
*&---------------------------------------------------------------------*
FORM display_alv_grid  USING p_table
                             po_grid     TYPE REF TO cl_gui_alv_grid
                             p_variant   TYPE disvariant
                             p_layout    TYPE lvc_s_layo
                             pt_exclude  TYPE ui_functions
                             pt_fieldcat TYPE lvc_t_fcat
                             pt_sort     TYPE lvc_t_sort.

  DATA:
    l_table LIKE feld-name.

  FIELD-SYMBOLS <fs_table> TYPE STANDARD TABLE.
  CONCATENATE p_table '[]' INTO l_table.
  ASSIGN (l_tableTO <fs_table>.

  CALL METHOD po_grid->set_table_for_first_display
    EXPORTING
      i_buffer_active      'X'
      i_bypassing_buffer   ' '
      i_save               'A'
      is_variant           p_variant
      is_layout            p_layout
      it_toolbar_excluding pt_exclude
    CHANGING
      it_fieldcatalog      pt_fieldcat
      it_sort              pt_sort
      it_outtab            <fs_table>.

ENDFORM.                    "display_alv_grid
 

*&---------------------------------------------------------------------*
*&      Form  REFRESH_GRID_0100
*&---------------------------------------------------------------------*
FORM refresh_grid_0100 USING po_grid   TYPE REF TO cl_gui_alv_grid
                             ps_stable TYPE lvc_s_stbl.

  ps_stable-row abap_true.
  ps_stable-col abap_true.

  PERFORM refresh_grid_table USING po_grid ps_stable.  <- top에 있다만 아래 붙임..

ENDFORM.                    " REFRESH_GRID_0100
 

*&---------------------------------------------------------------------*
*&      Form  refresh_grid_table
*&---------------------------------------------------------------------*
*  ALV GRID 내용을 REFRESH 한다
*&---------------------------------------------------------------------*
FORM refresh_grid_table USING po_grid   TYPE REF TO cl_gui_alv_grid
                              ps_stable TYPE lvc_s_stbl.

  CALL METHOD po_grid->refresh_table_display
    EXPORTING
      is_stable ps_stable
    EXCEPTIONS
      finished  1
      OTHERS    2.

ENDFORM.                    "refresh_grid_table
 



*&---------------------------------------------------------------------*
*&      Form  LVC_FIELDCATALOG_MERGE
*&---------------------------------------------------------------------*
FORM lvc_fieldcatalog_merge TABLES pt_fcat TYPE lvc_t_fcat
                            USING  p_type
                                   p_tabnm.

  DATA:
    lt_fieldcat_slis   TYPE slis_t_fieldcat_alv,
    lt_fieldcat_kkblo  TYPE kkblo_t_fieldcat,
    l_structure_name   TYPE dd02l-tabname,
    l_internal_tabname TYPE dd02l-tabname.

  REFRESH pt_fcat.

  CASE p_type.
    WHEN 'S'.
      l_structure_name   p_tabnm.

      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       l_structure_name
        CHANGING
          ct_fieldcat            pt_fcat[]
        EXCEPTIONS
          inconsistent_interface 1
          program_error          2
          OTHERS                 3.

    WHEN 'I'.
      l_internal_tabname p_tabnm.

      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         g_repid
          i_internal_tabname     l_internal_tabname
          i_inclname             g_repid
        CHANGING
          ct_fieldcat            lt_fieldcat_slis
        EXCEPTIONS
          inconsistent_interface 1
          program_error          2.

      CALL FUNCTION 'REUSE_ALV_TRANSFER_DATA'
        EXPORTING
          it_fieldcat lt_fieldcat_slis
        IMPORTING
          et_fieldcat lt_fieldcat_kkblo.

      CALL FUNCTION 'LVC_TRANSFER_FROM_KKBLO'
        EXPORTING
          it_fieldcat_kkblo lt_fieldcat_kkblo
        IMPORTING
          et_fieldcat_lvc   pt_fcat[]
        EXCEPTIONS
          it_data_missing   1
          OTHERS            2.
  ENDCASE.

ENDFORM.                    "lvc_fieldcatalog_merge

 

 

 

 

 

 

-----------handle double click event

 

  *&---------------------------------------------------------------------*
*&      Form  HANDLE_DOUBLE_CLICK
*&---------------------------------------------------------------------*
FORM handle_double_click  USING  p_row      TYPE lvc_s_row
                                 p_column   TYPE lvc_s_col
                                 ps_row_no  TYPE lvc_s_roid.

  CASE p_column.
    WHEN 'ZOF0CONR'.
      CLEAR gs_colist.
      READ TABLE gt_colist INDEX p_row-index INTO gs_colist.
      IF sy-subrc EQ AND gs_colist-zof0conr IS NOT INITIAL.
        SET PARAMETER ID 'ZOPMCONR'  FIELD gs_colist-zof0conr,
                           'BUK'   FIELD gs_colist-bukrs,
                           'BDTJ' FIELD gs_colist-zofdbdtj.

        CALL TRANSACTION 'ZOR000613' AND SKIP FIRST SCREEN.


      ELSE.
        RETURN.
      ENDIF.

    WHEN OTHERS.
      RETURN.
  ENDCASE.

ENDFORM.                    " HANDLE_DOUBLE_CLICK


728x90
반응형