728x90
반응형
버튼 위치가 일반적인 SET PF-STATUS 'M_0100'.
이런데 들어있는 것이 아니다.
툴바에 들어있는 것인데... 그럼 저건 어떻게 넣었을까..?
위 프로그램의 답은 Class 로 넣어준 것이다.
REPORT zo1erek060 MESSAGE-ID zo1emsg01.
*----------------------------------------------------------------------*
* INCLUDE
*----------------------------------------------------------------------*
INCLUDE zo1eicoalv. <- 이 부분이 범용적으로 내가쓰는 클래스 라이브러리이다
INCLUDE zo1erek060top.
INCLUDE zo1erek060evt.
INCLUDE zo1erek060o01.
INCLUDE zo1erek060i01.
INCLUDE zo1erek060f01.
여기 보면...
... 상략...
*----------------------------------------------------------------------*
* 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_repid) IF FOUND
USING e_ucomm.
ENDMETHOD. "handle_user_command
METHOD handle_data_changed.
PERFORM handle_data_changed IN PROGRAM (g_repid) IF FOUND
USING er_data_changed.
ENDMETHOD. "handle_data_changed
METHOD handle_data_changed_finished.
PERFORM handle_data_changed_finished IN PROGRAM (g_repid) IF FOUND
USING e_modified et_good_cells.
ENDMETHOD. "handle_data_changed_finished
METHOD handle_hotspot_click.
PERFORM handle_hotspot_click IN PROGRAM (g_repid) IF FOUND
USING e_row_id e_column_id.
ENDMETHOD. "handle_hotspot_click
METHOD handle_double_click.
PERFORM handle_double_click IN PROGRAM (g_repid) IF FOUND
USING e_row e_column es_row_no.
ENDMETHOD. "handle_double_click
METHOD handle_on_f4.
PERFORM handle_on_f4 IN PROGRAM (g_repid) IF 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_repid) IF FOUND
USING e_dyndoc_id.
ENDMETHOD. "handle_top_of_page
METHOD handle_before_user_command.
PERFORM handle_before_user_command IN PROGRAM (g_repid) IF FOUND
USING e_ucomm.
ENDMETHOD. "before_user_command
METHOD handle_after_user_command.
PERFORM handle_after_user_command IN PROGRAM (g_repid) IF 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_repid) IF FOUND
USING e_ucomm.
ENDMETHOD. "handle_user_command
METHOD handle_data_changed.
PERFORM handle_data_changed2 IN PROGRAM (g_repid) IF FOUND
USING er_data_changed.
ENDMETHOD. "handle_data_changed
METHOD handle_data_changed_finished.
PERFORM handle_data_changed_finished2 IN PROGRAM (g_repid) IF FOUND
USING e_modified et_good_cells.
ENDMETHOD. "handle_data_changed_finished
METHOD handle_hotspot_click.
PERFORM handle_hotspot_click2 IN PROGRAM (g_repid) IF FOUND
USING e_row_id e_column_id.
ENDMETHOD. "handle_hotspot_click
METHOD handle_double_click.
PERFORM handle_double_click2 IN PROGRAM (g_repid) IF 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_repid) IF 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_repid) IF FOUND
USING e_dyndoc_id.
ENDMETHOD. "handle_top_of_page
METHOD handle_before_user_command.
PERFORM handle_before_user_command2 IN PROGRAM (g_repid) IF FOUND
USING e_ucomm.
ENDMETHOD. "before_user_command
METHOD handle_after_user_command.
PERFORM handle_after_user_command2 IN PROGRAM (g_repid) IF 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.
뭐 나머지는 여러개 리시버 그냥 만들어 놓은거라 무시하고.. 한개만 잘 보면 된다..
저 구현한 부분을 더블클릭하면.. 소스부로 간다.
FORM handle_user_command USING p_ucomm TYPE sy-ucomm.
CASE p_ucomm.
WHEN 'TOGGLE'.
PERFORM switch_edit_mode USING go_grid.
WHEN 'SAVE'.
PERFORM save_data.
PERFORM refresh_grid_0100 USING go_grid gs_stable.
ENDCASE.
ENDFORM.
이런 부분이 들어있고.
스위치 에디트 모드는
*&---------------------------------------------------------------------*
*& 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( 1 ).
*-- lock edit enabled cells against input
WHEN 1. po_grid->set_ready_for_input( 0 ).
ENDCASE.
ENDFORM.
이런 로직으로 구현되어 있다.
세이브 데이터는
FORM save_data .
DATA:
ls_timestamp TYPE zoscm001,
lt_db TYPE STANDARD TABLE OF zo1tekh,
ls_db TYPE zo1tekh.
*-- Timestamp
ls_timestamp = zo1cco=>set_timestamp( i_type = 'C' ).
*... move data
LOOP AT gt_main
ASSIGNING <main>.
MOVE-CORRESPONDING <main> TO ls_db.
ls_db-ernam = ls_timestamp-ernam.
ls_db-erdat = ls_timestamp-erdat.
ls_db-erzet = ls_timestamp-erzet.
APPEND ls_db TO lt_db. CLEAR ls_db.
ENDLOOP.
*... save data
TRY.
MODIFY zo1tekh FROM TABLE lt_db.
CATCH cx_sy_open_sql_db.
ENDTRY.
IF sy-subrc = 0.
COMMIT WORK.
CLEAR g_changed.
MESSAGE s002 WITH ''(t02).
ELSE.
ROLLBACK WORK.
MESSAGE s002 WITH ''(t03).
ENDIF.
ENDFORM. " SAVE_DATA
리프레쉬 데이터는
*&---------------------------------------------------------------------*
*& 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. <- 이건 아래에 ..
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 HANDLE_TOOLBAR
*&---------------------------------------------------------------------*
FORM handle_toolbar USING po_object TYPE REF TO cl_alv_event_toolbar_set
p_interactive.
DATA:
ls_toolbar TYPE stb_button.
CHECK p_frmdb = abap_false.
*-- Save
ls_toolbar-function = 'SAVE'.
ls_toolbar-butn_type = 0.
ls_toolbar-icon = icon_system_save.
ls_toolbar-text = ''(b02).
ls_toolbar-quickinfo = ''(b02).
CASE g_changed.
WHEN abap_true. ls_toolbar-disabled = abap_false.
WHEN abap_false. ls_toolbar-disabled = abap_true.
ENDCASE.
INSERT ls_toolbar INTO po_object->mt_toolbar INDEX 1.
CLEAR ls_toolbar.
*-- Separate
ls_toolbar-butn_type = 3.
INSERT ls_toolbar INTO po_object->mt_toolbar INDEX 1.
CLEAR ls_toolbar.
*-- Toggle
ls_toolbar-function = 'TOGGLE'.
ls_toolbar-butn_type = 0.
ls_toolbar-icon = icon_toggle_display_change.
ls_toolbar-quickinfo = ''(b01).
INSERT ls_toolbar INTO po_object->mt_toolbar INDEX 1.
CLEAR ls_toolbar.
p_interactive = abap_true.
ENDFORM. " HANDLE_TOOLBAR
이렇게 구현되어 있다..
어렵다....
그래서 저 두 버튼이 생기는 것이다..
쥐지!
728x90
반응형
'ERP-SAP > ABAP' 카테고리의 다른 글
<ABAP> ABAP EDITER 를 부를 수 있는 소스코드(프로그램 강제 수정) (0) | 2011.12.08 |
---|---|
<ABAP> ALV 기본 선언 모음 (그냥 include 해서 쓸때 참 편한..) (0) | 2011.11.19 |
<ABAP> text중에 특정 문자열을 찾기 (finding character string, search char) (0) | 2011.11.10 |
<ABAP> 개발 프로그램 Binary down & Upload, (SAP 개발프로그램 다운 및 업로드) (0) | 2011.10.14 |
<ABAP> Mainternance View에 Event 넣기(유지보수뷰) (0) | 2011.09.15 |