>아래 소스와 같이 수정 하고 싶은 필드에만 EDIT을 하였는데요 DATA CHANGE이벤트 같은거 해줘야 ITAB내용이 수정 될꺼 같더라구요 아래 소스같이만 하면 행삽입, 행삭제 , EDIT기능이용해서 ITAB내용 수정 했을시에 ITAB에 반영이 안되는거 같아요. 글구 추가로 행 선택시 마크에 X표시가 걸려야 되는데 아래 소스에서 엇게 처리 해야 하는지요.....
>혹시 아시는 분께선 소스나 참고 자료좀 추천 해주시면 감사하겠습니다. ( 아래 소스는 외국 사이트서 구한건데 연구중이라요 원래 EDIT기능 하기 위해 짠 소스가 아닌데 제가 그걸 해보려다 막혀서여 도와줍쇼~ ㅜㅜ)
>
>* 아래 소스에선 GT_MARA_ALL인터널 테이블러 ALV출력 하는것입니다.
>
> >
>report z_alv_grid_ctrl_refresh_2.
tables : mara.
types:
begin of ty_s_mara,
matnr like mara-matnr,
ernam like mara-ernam,
ersda like mara-ersda,
brgew like mara-brgew,
meins like mara-meins,
end of ty_s_mara.
class lcl_event_alv definition deferred.
data:
gt_mara type standard table of mara,
go_container type ref to cl_gui_docking_container,
go_alv_grid type ref to cl_gui_alv_grid,
go_events type ref to lcl_event_alv,
gt_mara_ftr type standard table of mara, " Data filtered
gt_mara_all type standard table of mara, " Data readfrom DB
okcode type syucomm,
gv_okcode type syucomm.
*---------------------------------------------------------------------*
* CLASS lcl_event_alv DEFINITION
*---------------------------------------------------------------------*
class lcl_event_alv definition.
public section.
methods:
h_user_command for event after_user_command of cl_gui_alv_grid
importing e_ucomm
sender.
endclass. " LCL_EVENT_ALV DEFINITION
*---------------------------------------------------------------------*
* Class (Implementation) lcl_event_alv
*---------------------------------------------------------------------*
class lcl_event_alv implementation.
method h_user_command.
case e_ucomm.
when '&SORT_ASC' or '&SORT_DSC'. " Sort
perform f_sort_big_table.
* PERFORM f_read_data USING c_first_page.
perform f_refresh_table.
when '&FILTER'. " Filter
perform f_filter_data.
* PERFORM f_read_data USING c_first_page.
perform f_refresh_table.
when '&DELETE_FILTER'. " Delete filter
* gt_mara_ftr[] = gt_mara_all[].
* PERFORM f_read_data USING c_first_page.
perform f_refresh_table.
endcase.
endmethod. " user_command
endclass. " LCL_EVENT_ALV
*---------------------------------------------------------------------*
*SELECTION-SCREEN :
*BEGIN OF LINE,COMMENT 10(20) v_1 FOR FIELD p_max. "#EC NEEDED
*PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY.
*SELECTION-SCREEN END OF LINE.
selection-screen : begin of block param with frame title text-t13.
selection-screen skip 1.
select-options : s_matnr for mara-matnr.
selection-screen skip 1.
selection-screen end of block param.
*---------------------------------------------------------------------*
initialization.
* v_1 = 'Lines per page'.
*---------------------------------------------------------------------*
start-of-selection.
select *
into corresponding fields of table gt_mara_all
from mara
where matnr in s_matnr.
loop at gt_mara_all into mara.
* APPEND mara TO gt_mara_ftr.
endloop.
* gt_mara_ftr = gt_mara_all.
call screen 100.
*---------------------------------------------------------------------*
* Module pbo_0100 OUTPUT
*---------------------------------------------------------------------*
module pbo_0100 output.
set pf-status 'MAIN'.
set titlebar 'MAIN1'.
perform create_and_init_alv.
endmodule. " PBO_0100 OUTPUT
*---------------------------------------------------------------------*
* Module user_command_0100 INPUT
*---------------------------------------------------------------------*
module user_command_0100 input.
gv_okcode = okcode.
clear okcode.
case gv_okcode.
when 'BACK'.
set screen 0.
when 'EXIT'.
leave program.
* WHEN c_first_page OR c_next_page OR c_last_page OR c_prev_page.
when 'REFRESH'.
call screen 200.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
*---------------------------------------------------------------------*
* Form create_and_init_alv
*---------------------------------------------------------------------*
form create_and_init_alv.
* Macro definition
define m_fieldcat.
ls_alv_cat-col_pos = 1.
ls_alv_cat-fieldname = 'ERNAM'.
ls_alv_cat-ref_table = 'MARA'.
ls_alv_cat-edit = ' '.
append ls_alv_cat to lt_alv_cat.
ls_alv_cat-col_pos = 2.
ls_alv_cat-fieldname = 'MATNR'.
ls_alv_cat-ref_table = 'MARA'.
ls_alv_cat-edit = ' '.
append ls_alv_cat to lt_alv_cat.
ls_alv_cat-col_pos = 3.
ls_alv_cat-fieldname = 'ERSDA'.
ls_alv_cat-ref_table = 'MARA'.
ls_alv_cat-edit = 'X'.
append ls_alv_cat to lt_alv_cat.
ls_alv_cat-col_pos = 4.
ls_alv_cat-fieldname = 'BRGEW'.
ls_alv_cat-ref_table = 'MARA'.
ls_alv_cat-edit = 'X'.
append ls_alv_cat to lt_alv_cat.
ls_alv_cat-col_pos = 5.
ls_alv_cat-fieldname = 'MEINS'.
ls_alv_cat-ref_table = 'MARA'.
ls_alv_cat-no_out = 'X'.
append ls_alv_cat to lt_alv_cat.
end-of-definition.
data:
ls_variant type disvariant,
lt_alv_cat type lvc_t_fcat,
ls_alv_cat type lvc_s_fcat,
ls_alv_lay type lvc_s_layo,
l_offline type char1.
check go_container is initial.
call method cl_gui_alv_grid=>offline
receiving
e_offline = l_offline.
if l_offline eq 0.
create object go_container
exporting
extension = 2000
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
if sy-subrc ne 0.
message e999(zmcmm) with 'The control could not be created'.
endif.
endif.
* Create an instance of alv control
create object go_alv_grid
exporting i_parent = go_container.
create object go_events.
set handler go_events->h_user_command for go_alv_grid.
* Build field catalog
m_fieldcat.
* m_fieldcat.
* m_fieldcat.
* m_fieldcat.
* Layout
clear ls_alv_lay.
ls_alv_lay-zebra = 'X'.
ls_alv_lay-cwidth_opt = 'X'.
ls_variant-report = sy-cprog.
* Display
call method go_alv_grid->set_table_for_first_display
exporting
is_variant = ls_variant
is_layout = ls_alv_lay
i_save = 'A'
changing
it_outtab = gt_mara_all
it_fieldcatalog = lt_alv_cat.
endform. " CREATE_AND_INIT_ALV
*---------------------------------------------------------------------*
* Form F_REFRESH_TABLE
*---------------------------------------------------------------------*
form f_refresh_table.
data: ls_layout type lvc_s_layo.
call method go_alv_grid->get_frontend_layout
importing
es_layout = ls_layout.
ls_layout-cwidth_opt = 'X'.
call method go_alv_grid->set_frontend_layout
exporting
is_layout = ls_layout.
call method go_alv_grid->refresh_table_display.
endform. " F_REFRESH_TABLE
*---------------------------------------------------------------------*
* Form F_SORT_BIG_TABLE
*---------------------------------------------------------------------*
form f_sort_big_table.
data:
lt_sort_kkblo type kkblo_t_sortinfo,
lt_sort type lvc_t_sort.
call method go_alv_grid->get_sort_criteria
importing
et_sort = lt_sort.
check not lt_sort[] is initial.
* Format LVC --> KKBLO
call function 'LVC_TRANSFER_TO_KKBLO'
exporting
it_sort_lvc = lt_sort
importing
et_sort_kkblo = lt_sort_kkblo.
* The big tables must be sorted like the small one
perform fb_outtab_sort(saplkkbl) tables gt_mara_ftr
lt_sort_kkblo
using 'X'
'X'.
perform fb_outtab_sort(saplkkbl) tables gt_mara_all
lt_sort_kkblo
using 'X'
'X'.
endform. " F_SORT_BIG_TABLE
*---------------------------------------------------------------------*
* Form f_filter_data
*---------------------------------------------------------------------*
form f_filter_data.
data:
lt_filter_lvc type lvc_t_filt,
lt_filter_index type lvc_t_fidx with header line.
call method go_alv_grid->get_filter_criteria
importing
et_filter = lt_filter_lvc.
* Find data to filter
call function 'LVC_FILTER_APPLY'
exporting
it_filter = lt_filter_lvc
importing
et_filter_index = lt_filter_index[]
tables
it_data = gt_mara_all.
sort lt_filter_index descending.
loop at lt_filter_index.
delete gt_mara_all index lt_filter_index.
endloop.
endform. " F_FILTER_DATA
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0200 output.
set pf-status 'ZKJK1'.
set titlebar 'xxx'.
endmodule. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0200 input.
gv_okcode = okcode.
clear okcode.
case gv_okcode.
when 'BACK'.
set screen 100.
when 'EXIT'.
leave program.
endcase.
endmodule. " USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*& Module ITAB_MODIFY INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module itab_modify input.
loop at screen.
modify screen.
endloop.
loop at gt_mara_all into mara.
modify gt_mara_all index sy-tabix from mara.
endloop.
* MODIFY gt_mara_all FROM mara-ernam.
* MODIFY gt_mara_all FROM mara-ersda.
* MODIFY gt_mara_all FROM mara-brgew.
* MODIFY gt_mara_all FROM mara-meins.
endmodule. " ITAB_MODIFY INPUT
*&---------------------------------------------------------------------*
*& Module ITAB_MODIFY0 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module itab_modify0 output.
loop at screen.
modify screen.
endloop.
loop at gt_mara_all into mara.
modify gt_mara_all index sy-tabix from mara.
endloop.
endmodule. " ITAB_MODIFY0 OUTPUT
*----------------------------------------------------------
1. EVENT HANDLER등록하시고
DATA : GV_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
*-- CELL 입력후 ENTER 발생한 경우 CATCH
CALL METHOD GV_ALV_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
*-- CELL 입력후 값이 변경 또는 입력되는 순간 CATCH
CALL METHOD GV_ALV_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
*---- EVENT 설정
CREATE OBJECT GO_EVENTS.
*>> DATA CHANGED 처리
SET HANDLER GO_EVENTS->HANDLE_DATA_CHANGED FOR PV_ALV_GRID.
2. EVENT정의하심될듯합니다
CLASS LCL_EVENT_ALV DEFINITION .
PUBLIC SECTION.
METHODS : HANDLE_DATA_CHANGED
FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
IMPORTING
ER_DATA_CHANGED.
*----------------------------------------------------------------
CLASS LCL_EVENT_ALV IMPLEMENTATION.
*>> 변경필드값처리
METHOD HANDLE_DATA_CHANGED.
PERFORM DATA_CHANGED USING ER_DATA_CHANGED.
ENDMETHOD. "HANDLE_DATA_CHANGED
*----------------------------------------------------------------
FORM DATA_CHANGED
USING PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
..해당로직구현...
ENDFORM. " DATA_CHANGED