Code: Alles auswählen.
data: lr_selections type ref to cl_salv_selections.
data: lt_rows type salv_t_row.
data: lv_row type i.
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
read table lt_rows into lv_row index 1.
read table gt_table into gs_tabel index lv_row.
* delete from DB
delete from dbtab
where lifnr = gs_tabel-lifnr
and linam = gs_tabel-linam
and kunnr = gs_tabel-kunnr
and kunam = gs_tabel-kunam.
* delete from ALV-Grid
delete gt_table index lv_row.
Code: Alles auswählen.
DATA: lwa_ref TYPE lvc_s_stbl.
call method gv_grid->refresh_table_display(
EXPORTING
is_stable = lwa_ref --> soll hier die interne Tabelle sein?
EXCEPTIONS
finished = 1
OTHERS = 2 ).
endcase.
endmethod.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag (Insgesamt 2):
DeathAndPain • ManMan
Code: Alles auswählen.
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.
ENDCLASS.
DATA: gr_event_handler TYPE REF TO lcl_handle_events.
class lcl_handle_events implementation.
method on_user_command.
case e_salv_function.
when 'EDIT'.
call screen 8000.
when 'DELETE'.
perform delete_data.
endcase.
endmethod.
endclass.
form save_data.
select single * from table where lifnr = gv_lifnr
and kunnr = gv_kunnr.
if sy-subrc = 4.
table-lifnr = gv_lifnr.
table-linam = p_linam.
table-kunnr = gv_kunnr.
table-kunam = p_kunam.
modify table
message text-005 type 'I'.
else.
message text-006 type 'I'.
endif.
form delete_data.
*Set up selections for the selected rows
data: lr_selections type ref to cl_salv_selections.
data: lt_rows type salv_t_row.
data: lv_row type i.
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
read table lt_rows into lv_row index 1.
read table gt_form delete_data.
* delete from DB
delete from table
where lifnr = gs_table-lifnr
and linam = gs_table-linam
and kunnr = gs_table-kunnr
and kunam = gs_table-kunam.
* delete from ALV-Grid
delete table index lv_row.
gr_table->refresh( ).
endform.
MODULE zuser_command_8000 INPUT.
case sy-ucomm."ok_code.
when 'SAVE'.
perform save_data.
when 'CANCEL'.
clear ok_code.
leave to screen 0.
when 'EXIT'.
clear ok_code.
leave to screen 0.
when 'BACK'.
clear ok_code.
leave to screen 0.
endcase.
ENDMODULE.
Code: Alles auswählen.
MODULE zstatus_8000 OUTPUT.
set pf-status '8000'
set titlebar '8000'
endmodule.
Code: Alles auswählen.
form display_data.
* ALV-Instanz erzeugen
try.
cl_salv_table=>factory(
importing r_salv_table = gr_table
changing t_table = gt_table ).
catch cx_salv_msg.
endtry.
* GUI-Status SALV_STANDARD setzen
gr_table->set_screen_status(
pfstatus = 'SALV_STANDARD'
report = sy-repid
set_functions = gr_table->c_functions_all ).
* Instanz für Spalten holen
gr_columns = gr_table->get_columns( ).
* Spaltenbreite optimieren
gr_columns->set_optimize( abap_true ).
* Register to the events of cl_salv_table
gr_events = gr_table->get_event( ).
CREATE OBJECT gr_event_handler.
* Register to the event USER_COMMAND
SET HANDLER gr_event_handler->on_user_command FOR gr_events.
**** Selection-Mode aktivieren ****
* Instanz des Selection-Objektes holen
* gr_selections = gr_salv->get_selections( ).
* Selektionsmodus setzen
* gr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
* Titel und/oder Streifenmuster
gr_display = gr_table->get_display_settings( ).
gr_display->set_list_header( value = 'Daten anlegen in table' ).
gr_display->set_striped_pattern( abap_true ).
try.
* Spalte "Mandant" holen
gr_column ?= gr_columns->get_column( 'MANDT' ).
* Spalte "Mandant" ausblenden
gr_column->set_visible( abap_false ).
* Den Namen für die Spalte LIFNR vergeben
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'LIFNR' ).
gr_column->set_long_text( 'Lieferant/Kunde' ).
gr_column->set_medium_text( '' ).
gr_column->set_short_text( '' ).
* Den Namen für die Spalte LINAM vergeben
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'LINAM' ).
gr_column->set_long_text( 'Lieferantenname' ).
gr_column->set_medium_text( '' ).
gr_column->set_short_text( '' ).
* Den Namen für die Spalte KUNNR vergeben
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'KUNNR' ).
gr_column->set_long_text( 'Lieferant/Kunde' ).
gr_column->set_medium_text( '' ).
gr_column->set_short_text( '' ).
* Den Namen für die Spalte KUNAM vergeben
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'KUNAM' ).
gr_column->set_long_text( 'Kundenname' ).
gr_column->set_medium_text( '' ).
gr_column->set_short_text( '' ).
catch cx_salv_not_found.
endtry.
* Liste anzeigen
gr_table->display( ).
endform.
Code: Alles auswählen.
START-OF-SELECTION.
* Call subroutine select_data
PERFORM select_data.
END-OF-SELECTION.
* Call subroutine select_data
PERFORM display_data.