04-17-2008 8:41 AM
Hi Gurus,
I am using Two containers,
In Screen 0100 When 'DELETE'/'ADD' it will Delete/Insert records to DB Table at First Time.
But If I go forward to the next screen 0101 and then back the the 0100, at that time When I press 'DELETE'/'ADD' the functionality is not working.
In my Pgm flow
When 'DEL'.
CALL METHOD oref_alv_grid->check_changed_data
IMPORTING
e_valid = l_valid. - > +Filled +
CALL METHOD oref_alv_grid->get_selected_rows
IMPORTING
et_index_rows = lt_rows -> Not Filled, Even I dont have Debugg insite the method
..................
..................
..................
..................
Please give me a solution.
Thanks for your valuable reply.
Kanagaraja L
04-17-2008 9:21 AM
Hello Kanagaraja
I assume that your ALV grid does not allow multiple selection (LVC_S_LAYO-SEL_MODE). If you do not see a "mark" column at the left border of the ALV list then this is the case.
Without multiple selection allowed the method go_grid->GET_SELECTED_ROWS will not return anything.
Regards
Uwe
04-17-2008 9:21 AM
Hello Kanagaraja
I assume that your ALV grid does not allow multiple selection (LVC_S_LAYO-SEL_MODE). If you do not see a "mark" column at the left border of the ALV list then this is the case.
Without multiple selection allowed the method go_grid->GET_SELECTED_ROWS will not return anything.
Regards
Uwe
04-17-2008 9:30 AM
Hi Uwe,
In my Grid, 'Mark' is available In the Left border of the ALV .
Even I can Detele/Add Multiple Lines in the First time in the screen 0100.
My case when I go forward to second screen and then Back to the First screen, at that time I can't Delete/Add a lines.
Can you give any other solution.
Thanks in advance.
Kanagaraja L
04-17-2008 9:35 AM
Hello Kanagaraja
In this case the problem is clear. When you call the second screen and then come back to the first screen PAI and PBO of the first screen have passed and therefore the selected rows should be gone.
Thus, when you call the second screen call method GET_SELECTED_ROWS and store them in a variable (e.g. GT_SEL_ROWS).
When you return from the second screen call method SET_SELECTED_ROWS in order to reset the selection on the first ALV grid.
Now you should be able to delete the selected rows from the first ALV when calling the DELETE button.
Regards
Uwe
04-17-2008 12:26 PM
Hi Uwe,
I Confused you, So I have Paste the Part of Code Here.
MODULE user_command_0100 INPUT.
WHEN 'REMOVE'.
PERFORM f_remove_data.
ENDMODULE. " USER_COMMAND_0100 INPU
FORM f_remove_data .
CALL METHOD oref_alv_grid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid IS INITIAL.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-i06
txt1 = text-i07
txt2 = text-i08
txt3 = text-i09.
ELSE.
PERFORM delete_database_add.
MESSAGE s000(0k) WITH text-s01.
ENDIF.
ENDFORM. " F_REMOVE_DATA
FORM delete_database_add .
DATA: lt_rows TYPE lvc_t_row,
wa_rows TYPE lvc_s_row.
DATA: lt_rows1 TYPE lvc_t_row.
DATA:t_row_no TYPE LVC_t_ROID.
CALL METHOD oref_alv_grid->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.
CALL METHOD oref_alv_grid->get_selected_rows
IMPORTING
et_index_rows = lt_rows1[].
IF NOT lt_rows1 IS INITIAL.
CLEAR wa_rows.
LOOP AT lt_rows1 INTO wa_rows.
READ TABLE t_pctable INTO wa_pctable INDEX wa_rows-index.
IF sy-subrc EQ 0.
+Lock the table +
IF sy-subrc EQ 0.
+ DELETE <DBtable> FROM <Workarea>.+
IF sy-subrc EQ 0.
Unlock DB Table
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ELSE.
MESSAGE e002.
ENDIF.
ENDFORM. " DELETE_DATABASE_ADD
When I go to any other screen and Come back to the 0100 screen Now I select the Rows it is not working.
Waiting for Your Reply.
Kanagarja L
04-17-2008 7:52 PM
Hello Kanagaraja
You have made a mistake when calling the REFRESH method.
FORM delete_database_add .
DATA: lt_rows TYPE lvc_t_row,
wa_rows TYPE lvc_s_row.
DATA: lt_rows1 TYPE lvc_t_row.
DATA:t_row_no TYPE LVC_t_ROID.
* CALL METHOD oref_alv_grid->refresh_table_display
* EXCEPTIONS
* finished = 1
* OTHERS = 2.
" NOTE: Refresh clears all selections. Thus, LT_ROWS1 will always be empty !!!
CALL METHOD oref_alv_grid->get_selected_rows
IMPORTING
et_index_rows = lt_rows1[].
...
You may have a look at my sample report ZUS_SDN_TWO_ALV_GRIDS_2SCR. Display the first ALV list, select some rows and enter 'DETAIL' in the command window. This will lead you to the second screen from which you return via F3.
Back on the first ALV list enter 'DELETE' and all marked rows will be deleted from the list.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_TWO_ALV_GRIDS
*&
*&---------------------------------------------------------------------*
*& Thread: CL_GUI_ALV_GRID-GET_SELECTED_ROWS Parameter ET_INDEX_ROWS not filled.
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="826287"></a>
*&---------------------------------------------------------------------*
*& Screen '0100' contains no elements.
*& ok_code -> assigned to GD_OKCODE
*&
*& Flow logic:
* PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
* PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
*&
*& Screen '0200': copy of screen '0100' (for the sake of simplicity)
*&---------------------------------------------------------------------*
REPORT zus_sdn_two_alv_grids_2scr.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syrepid,
*
go_docking1 TYPE REF TO cl_gui_docking_container,
go_docking2 TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo.
DATA:
gt_outtab1 TYPE STANDARD TABLE OF knb1,
gt_outtab2 TYPE STANDARD TABLE OF knvv.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
** READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
** CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
**
** CALL METHOD go_grid1->set_current_cell_via_id
** EXPORTING
*** IS_ROW_ID =
*** IS_COLUMN_ID =
** is_row_no = es_row_no.
**
**
*** Triggers PAI of the dynpro with the specified ok-code
** CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_outtab1
WHERE bukrs = '1000'.
PERFORM init_controls.
* Display data
gs_layout-grid_title = 'Customers'.
gs_layout-sel_mode = 'D'. " multiple row selection
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNB1'
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab1
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.
gs_layout-grid_title = 'Customers Details (Sales Areas)'.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'KNVV'
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab2 " empty !!!
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.
gd_repid = syst-repid.
* Link the docking container to the target dynpro
CALL METHOD go_docking1->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.
* Link the docking container to the target dynpro
CALL METHOD go_docking2->link
EXPORTING
repid = gd_repid
dynnr = '0200'
* 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.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro '0100' (does not contain any dynpro elements):
*
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking1
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 grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking1
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.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid1.
* Create docking container
CREATE OBJECT go_docking2
EXPORTING
parent = go_docking2
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 grids
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_docking2
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.
ENDFORM. " INIT_CONTROLS
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid2->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
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.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
CASE syst-dynnr.
WHEN '0100'.
SET SCREEN 0. LEAVE SCREEN.
WHEN '0200'.
SET SCREEN '0100'.
LEAVE SCREEN.
ENDCASE.
* User has pushed button "Display Details"
WHEN 'DETAIL'.
PERFORM entry_show_details.
CALL SCREEN '0200'.
WHEN 'DELETE'.
perform DELETE_ENTRIES.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM entry_show_details .
* define local data
DATA:
ls_row TYPE lvc_s_row,
lt_rows type lvc_t_row,
ls_knb1 TYPE knb1,
lt_knb1 TYPE STANDARD TABLE OF knb1.
CALL METHOD go_grid1->get_selected_rows
IMPORTING
et_index_rows = lt_rows
* et_row_no =
.
LOOP AT lt_rows INTO ls_row.
READ TABLE gt_outtab1 INTO ls_knb1 INDEX ls_row-index.
APPEND ls_knb1 TO lt_knb1.
ENDLOOP.
IF ( lt_rows IS INITIAL ).
REFRESH: gt_outtab2.
ELSE.
SELECT * FROM knvv INTO TABLE gt_outtab2
FOR ALL ENTRIES IN lt_knb1
WHERE kunnr = lt_knb1-kunnr.
ENDIF.
ENDFORM. " ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
*& Form DELETE_ENTRIES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form DELETE_ENTRIES .
* define local data
DATA:
ls_row TYPE lvc_s_row,
lt_rows type lvc_t_row.
CALL METHOD go_grid1->get_selected_rows
IMPORTING
et_index_rows = lt_rows
* et_row_no =
.
LOOP AT lt_rows INTO ls_row.
delete gt_outtab1 INDEX ls_row-index.
ENDLOOP.
go_grid1->refresh_table_display( ). " Mandatory !!!
endform. " DELETE_ENTRIES
Regards
Uwe