09-22-2008 9:08 PM
I han an OOP ALV Grid app.
The CL_GUI_ALV_GRID object is set to allow the user to edit values.
The user is allowed to "duplicate rows" using the default standard toolbar icon.
One of the fields on the record is a guid value, which points to supplemental information.
While I want to duplicate all the other values, I want to reset this guid pointer to initial.
I have a clue, but just slightly, Somewhere, I guess I have to register the duplicate row event (whatever it is) , create a local handler for it, find the source and target values of the copy, set my pointer to null on the new record, and probably know that the data has changed.
Can someone give me specifics ?
Thanks...
...Mike
09-22-2008 9:12 PM
You can register the Event DATA_CHANGED of the Class CL_GUI_ALV_GRID using the Local class handler.
Here you can check if the duplicate record is there in your ALV, if it is than blank out the pointer.
Check report BCALV_TEST_GRID_EVENTS for more information on how to implement the Evnets.
Regards,
Naimesh Patel
09-22-2008 9:26 PM
Hello Michael
I have adjusted my previous sample report to accomodate your requirements. Perhaps you find it useful.
The major point is to redefine the ok-code for duplicating rows.
*&---------------------------------------------------------------------*
*& ZUS_SDN_ALVGRID_EDITABLE_8A
*&
*&---------------------------------------------------------------------*
*& Thread: Blanking values on ALV Grid Row Duplicate
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1057161"></a>
*&
*& Thread: Delete line event in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="945471"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_alvgrid_editable_8a.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
*
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gt_outtab TYPE ty_t_outtab.
*----------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
mt_sel_rows TYPE lvc_t_row.
CLASS-METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
sender,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_toolbar.
* define local data
DATA: ls_button TYPE stb_button.
LOOP AT e_object->mt_toolbar INTO ls_button.
CASE ls_button-function.
WHEN cl_gui_alv_grid=>mc_fc_loc_delete_row.
ls_button-function = 'DELETE_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
WHEN cl_gui_alv_grid=>mc_fc_loc_copy_row OR
cl_gui_alv_grid=>mc_fc_loc_copy.
ls_button-function = 'COPY_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ENDLOOP.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
* define local data
DATA: lt_rows TYPE lvc_t_row,
ls_row TYPE lvc_s_row.
REFRESH: mt_sel_rows.
CASE e_ucomm.
WHEN 'DELETE_ROW'.
WHEN 'COPY_ROW'.
WHEN OTHERS.
RETURN.
ENDCASE.
" User wants to delete or copy rows => store them in class attribute
" and trigger PAI afterwards where we actually delete /copy the rows
" and do the recalculations (in case of deletion)
CALL METHOD sender->get_selected_rows
IMPORTING
et_index_rows = mt_sel_rows
* et_row_no =
.
* Trigger PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = e_ucomm
* IMPORTING
* rc =
.
ENDMETHOD. "user_command
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '2000' OBLIGATORY.
START-OF-SELECTION.
SELECT * FROM knb1 INTO CORRESPONDING FIELDS OF TABLE gt_outtab
UP TO 100 ROWS
WHERE bukrs = p_bukrs.
PERFORM init_controls.
SET HANDLER:
lcl_eventhandler=>handle_toolbar FOR go_grid,
lcl_eventhandler=>handle_user_command FOR go_grid.
" Used to replace standard toolbar function code with custom FC
go_grid->set_toolbar_interactive( ).
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
** CALL METHOD go_grid1->refresh_table_display
*** EXPORTING
*** IS_STABLE =
*** I_SOFT_REFRESH =
** EXCEPTIONS
** FINISHED = 1
** others = 2
** .
** IF sy-subrc <> 0.
*** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
** ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'DELETE_ROW'.
PERFORM delete_rows.
WHEN 'COPY_ROW'.
PERFORM copy_rows.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
CALL METHOD go_grid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog_knb1 .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Only non-key fields are editable
ls_fcat-edit = 'X'.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE 'X' ).
ENDFORM. " BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
* Display data
CALL METHOD go_grid->set_table_for_first_display
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " INIT_CONTROLS
*&---------------------------------------------------------------------*
*& Form delete_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM delete_rows .
* define local data
DATA: ls_row TYPE lvc_s_row.
SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
DELETE gt_outtab INDEX ls_row-index.
ENDLOOP.
" After deleting rows do RE-CALCULATION
* perform RECALCULATION.
ENDFORM. " delete_rows
*&---------------------------------------------------------------------*
*& Form COPY_ROWS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM copy_rows .
* define local data
DATA: ld_next TYPE i,
ls_row TYPE lvc_s_row,
ls_outtab TYPE ty_s_outtab.
SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.
CLEAR: ls_outtab-akont. " In your case: clear GUID
ld_next = ls_row-index + 1.
INSERT ls_outtab INTO gt_outtab INDEX ld_next.
ENDLOOP.
ENDFORM. " COPY_ROWS
Regards
Uwe
03-08-2010 7:59 PM