REPORT ZFITESTH_18027 message-id ok .
DATA : con1_ref TYPE REF TO cl_gui_custom_container.
DATA : grid1 TYPE REF TO cl_gui_alv_grid,
gs_variant LIKE disvariant,
gs_cs_variant LIKE disvariant,
gs_layout TYPE lvc_s_layo,
gs_toolbar TYPE ui_functions,
gt_sort TYPE lvc_t_sort,
gt_fieldcat TYPE lvc_t_fcat.
DATA: BEGIN OF gt_sflight OCCURS 0. "with header line
INCLUDE STRUCTURE sflight.
DATA: END OF gt_sflight.
data : gt_modified_rows TYPE STANDARD TABLE OF sflight.
DATA: g_carrid LIKE sflight-carrid,
g_connid LIKE sflight-connid.
TYPE-POOLS: icon.
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS.
**---------------------------------------------------------
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_data_changed.
DATA:
ls_sflight TYPE sflight,
ls_outtab LIKE LINE OF gt_sflight.
FIELD-SYMBOLS: <fs> TYPE table.
ASSIGN er_data_changed->mp_mod_rows->* TO <fs>.
LOOP AT <fs> INTO ls_outtab.
MOVE-CORRESPONDING ls_outtab TO ls_sflight.
APPEND ls_sflight TO gt_modified_rows.
ENDLOOP.
ENDMETHOD. "handle_data_changed
endclass.
*-----------------------------------------------------------------------
*-------------------------------------------------------
DATA : event_receiver TYPE REF TO lcl_event_receiver.
DATA: g_verifier TYPE REF TO lcl_event_receiver.
START-OF-SELECTION.
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE init_con OUTPUT
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
MODULE init_con OUTPUT.
IF con1_ref IS INITIAL.
CREATE OBJECT con1_ref
EXPORTING container_name = 'CON1'.
CREATE OBJECT grid1
EXPORTING
i_parent = con1_ref.
CREATE OBJECT g_verifier.
SET HANDLER g_verifier->handle_data_changed FOR grid1.
PERFORM setting_layout.
PERFORM setting_catalog.
PERFORM setting_toolbar.
PERFORM setting_sort.
PERFORM setting_event.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
i_save = 'A'
is_variant = gs_variant " variant display
i_default = ' '
is_layout = gs_layout
it_toolbar_excluding = gs_toolbar
CHANGING
it_outtab = gt_sflight[]
it_fieldcatalog = gt_fieldcat[]
it_sort = gt_sort.
CALL METHOD GRID1->SET_READY_FOR_INPUT
EXPORTING I_READY_FOR_INPUT = 0.
ENDIF.
ENDMODULE. " init_con OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'G100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CANC'.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
DATA: l_valid TYPE c.
CALL METHOD grid1->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid IS NOT INITIAL.
PERFORM update_database.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form setting_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_LAYOCAT text
*----------------------------------------------------------------------*
FORM setting_layout .
*- General display options
gs_layout-cwidth_opt = 'X'.
* TITLE BAR
gs_layout-grid_title = 'ALV GRID EDIT TEST'.
* gs_layout-edit = 'X'.
* Selection modes for SEL_MODE
gs_layout-sel_mode = 'D'.
* Grid pattern
* gs_layout-zebra = 'X'.
ENDFORM. " setting_layout
*&---------------------------------------------------------------------*
*& Form setting_toolbar
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_TOOLBAR text
*----------------------------------------------------------------------*
FORM setting_toolbar.
DATA: l_exclude TYPE ui_func.
l_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
APPEND l_exclude TO gs_toolbar.
l_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND l_exclude TO gs_toolbar.
ENDFORM. " setting_toolbar
*&---------------------------------------------------------------------*
*& Form setting_sort
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_sort .
DATA : ls_sort TYPE lvc_s_sort.
ls_sort-spos = '1'.
ls_sort-fieldname = 'CARRID'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO gt_sort.
ENDFORM. " setting_sort
*&---------------------------------------------------------------------*
*& Form setting_event
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_event .
CREATE OBJECT event_receiver.
ENDFORM. " setting_event
*&---------------------------------------------------------------------*
*& Form setting_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_catalog .
DATA ls_fieldcat TYPE lvc_s_fcat.
ls_fieldcat-fieldname = 'CARRID'.
ls_fieldcat-coltext = 'Carrid ID'.
ls_fieldcat-just = 'L'.
ls_fieldcat-key = 'X'.
ls_fieldcat-edit = ''.
ls_fieldcat-outputlen = '2'.
APPEND ls_fieldcat TO gt_fieldcat.
ls_fieldcat-fieldname = 'CONNID'.
ls_fieldcat-coltext = 'Flight Number'.
ls_fieldcat-just = 'C'.
* ls_fieldcat-key = ''.
ls_fieldcat-edit = 'X'.
ls_fieldcat-outputlen = '4'.
APPEND ls_fieldcat TO gt_fieldcat.
ls_fieldcat-fieldname = 'PRICE'.
ls_fieldcat-coltext = 'Airfare'.
ls_fieldcat-just = 'R'.
ls_fieldcat-key = 'X'.
ls_fieldcat-edit = 'X'.
ls_fieldcat-outputlen = '15'.
APPEND ls_fieldcat TO gt_fieldcat.
ENDFORM. " setting_catalog
*&---------------------------------------------------------------------*
*& Form update_database
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM update_database .
MODIFY SFLIGHT FROM TABLE GT_MODIFIED_ROWS.
IF SY-SUBRC EQ 0.
MESSAGE s000(0k) WITH 'SAVE OK'.
ENDIF.
ENDFORM. " update_database
댓글 3
-
e-abap
2008.06.16 20:03
-
피크민
2008.06.16 20:20
<P>감사합니다..잘 변경되네요.. 전에는 미니샙으로 연습해보고..이번에 실 서버에서 로컬로 해서 연습좀하고있는데요..</P>
<P>책보고 공부중이에요..클래스좀 익혀볼라고 연습중입니다..^^* 감사합니다..e-abap님..</P> -
피크민
2008.06.16 20:38
<P>CALL METHOD GRID1->SET_READY_FOR_INPUT<BR> EXPORTING I_READY_FOR_INPUT = 0.</P>
<P>이게 문제였네요..주석처리했더니 입력이 됩니다..</P>
<P>저걸쓰면 입력이 안되는군요..</P>
책을 보고 따라하신건가요? 아니면 소스만 그냥 테스트 해보시는건지요?
소스를 다음과 같이 수정하고 해보세요.
REPORT Z18_037_2.
DATA : con1_ref TYPE REF TO cl_gui_custom_container.
DATA : grid1 TYPE REF TO cl_gui_alv_grid,
gs_variant LIKE disvariant,
gs_cs_variant LIKE disvariant,
gs_layout TYPE lvc_s_layo,
gs_toolbar TYPE ui_functions,
gt_sort TYPE lvc_t_sort,
gt_fieldcat TYPE lvc_t_fcat.
DATA: BEGIN OF gt_sflight OCCURS 0. "with header line
INCLUDE STRUCTURE sflight.
DATA: END OF gt_sflight.
data : gt_modified_rows TYPE STANDARD TABLE OF sflight.
DATA: g_carrid LIKE sflight-carrid,
g_connid LIKE sflight-connid.
TYPE-POOLS: icon.
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS.
**---------------------------------------------------------
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_data_changed.
DATA:
ls_sflight TYPE sflight,
ls_outtab LIKE LINE OF gt_sflight.
FIELD-SYMBOLS: <fs> TYPE table.
ASSIGN er_data_changed->mp_mod_rows->* TO <fs>.
LOOP AT <fs> INTO ls_outtab.
MOVE-CORRESPONDING ls_outtab TO ls_sflight.
APPEND ls_sflight TO gt_modified_rows.
ENDLOOP.
ENDMETHOD. "handle_data_changed
endclass.
*-----------------------------------------------------------------------
*-------------------------------------------------------
DATA : event_receiver TYPE REF TO lcl_event_receiver.
DATA: g_verifier TYPE REF TO lcl_event_receiver.
START-OF-SELECTION.
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE init_con OUTPUT
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
MODULE init_con OUTPUT.
IF con1_ref IS INITIAL.
CREATE OBJECT con1_ref
EXPORTING container_name = 'CON1'.
CREATE OBJECT grid1
EXPORTING
i_parent = con1_ref.
CREATE OBJECT g_verifier.
SET HANDLER g_verifier->handle_data_changed FOR grid1.
PERFORM setting_layout.
PERFORM setting_catalog.
PERFORM setting_toolbar.
PERFORM setting_sort.
PERFORM setting_event.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
i_save = 'A'
is_variant = gs_variant " variant display
i_default = ' '
is_layout = gs_layout
it_toolbar_excluding = gs_toolbar
CHANGING
it_outtab = gt_sflight[]
it_fieldcatalog = gt_fieldcat[]
it_sort = gt_sort.
*CALL METHOD GRID1->SET_READY_FOR_INPUT
* EXPORTING I_READY_FOR_INPUT = 0.
ENDIF.
ENDMODULE. " init_con OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'G100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CANC'.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
DATA: l_valid TYPE c.
CALL METHOD grid1->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid IS NOT INITIAL.
PERFORM update_database.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form setting_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_LAYOCAT text
*----------------------------------------------------------------------*
FORM setting_layout .
*- General display options
gs_layout-cwidth_opt = 'X'.
* TITLE BAR
gs_layout-grid_title = 'ALV GRID EDIT TEST'.
gs_layout-edit = 'X'.
* Selection modes for SEL_MODE
gs_layout-sel_mode = 'D'.
* Grid pattern
* gs_layout-zebra = 'X'.
ENDFORM. " setting_layout
*&---------------------------------------------------------------------*
*& Form setting_toolbar
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_TOOLBAR text
*----------------------------------------------------------------------*
FORM setting_toolbar.
DATA: l_exclude TYPE ui_func.
l_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
APPEND l_exclude TO gs_toolbar.
l_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND l_exclude TO gs_toolbar.
ENDFORM. " setting_toolbar
*&---------------------------------------------------------------------*
*& Form setting_sort
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_sort .
DATA : ls_sort TYPE lvc_s_sort.
ls_sort-spos = '1'.
ls_sort-fieldname = 'CARRID'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO gt_sort.
ENDFORM. " setting_sort
*&---------------------------------------------------------------------*
*& Form setting_event
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_event .
CREATE OBJECT event_receiver.
ENDFORM. " setting_event
*&---------------------------------------------------------------------*
*& Form setting_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_catalog .
DATA ls_fieldcat TYPE lvc_s_fcat.
ls_fieldcat-fieldname = 'CARRID'.
ls_fieldcat-coltext = 'Carrid ID'.
ls_fieldcat-just = 'L'.
ls_fieldcat-key = 'X'.
ls_fieldcat-edit = ''.
ls_fieldcat-outputlen = '2'.
APPEND ls_fieldcat TO gt_fieldcat.
ls_fieldcat-fieldname = 'CONNID'.
ls_fieldcat-coltext = 'Flight Number'.
ls_fieldcat-just = 'C'.
* ls_fieldcat-key = ''.
ls_fieldcat-edit = 'X'.
ls_fieldcat-outputlen = '4'.
APPEND ls_fieldcat TO gt_fieldcat.
ls_fieldcat-fieldname = 'PRICE'.
ls_fieldcat-coltext = 'Airfare'.
ls_fieldcat-just = 'R'.
ls_fieldcat-key = 'X'.
ls_fieldcat-edit = 'X'.
ls_fieldcat-outputlen = '15'.
APPEND ls_fieldcat TO gt_fieldcat.
ENDFORM. " setting_catalog
*&---------------------------------------------------------------------*
*& Form update_database
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM update_database .
MODIFY SFLIGHT FROM TABLE GT_MODIFIED_ROWS.
IF SY-SUBRC EQ 0.
MESSAGE s000(0k) WITH 'SAVE OK'.
ENDIF.
ENDFORM. " update_database