Code: Alles auswählen.
CALL METHOD re_alv->set_table_for_first_display
Code: Alles auswählen.
TYPES: BEGIN OF ty_output.
INCLUDE STRUCTURE zstruktur.
TYPES: celltab TYPE lvc_t_styl,
END OF ty_output.
data: gt_output type table of ty_output.
Code: Alles auswählen.
*§2.After selecting data, set edit status for each row in a loop
* according to field xy.
LOOP AT lt_ver INTO ls_ver.
l_index = sy-tabix.
REFRESH lt_celltab.
IF u_ucomm = 'Editierbutton'.
*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell
* to status "editable".
l_mode = cl_gui_alv_grid=>mc_style_enabled.
ELSE.
*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell
* to status "non-editable".
l_mode = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
ls_celltab-fieldname = 'VERARB_KZ'.
ls_celltab-style = l_mode.
INSERT ls_celltab INTO TABLE lt_celltab.
MOVE-CORRESPONDING ls_ver TO ls_output.
.......
*§2c.Copy your celltab to the celltab of the current row of gt_outtab.
insert lines of lt_celltab into table ls_output-celltab.
APPEND ls_output TO gt_output.
clear ls_output.
ENDLOOP.
Code: Alles auswählen.
ls_layout-stylefname = 'CELLTAB'.
Code: Alles auswählen.
* Aufruf der Methode für ALV-OO-Ausgabe
CALL METHOD re_alv->set_table_for_first_display
EXPORTING
is_variant = ls_variant
i_save = 'A'
is_layout = ls_layout
CHANGING
it_outtab = gt_output
it_fieldcatalog = lt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
.
* Dynpro für ALV-Ausgabe
CALL SCREEN 100.
Code: Alles auswählen.
REPORT zz_alv_edit LINE-SIZE 1000.
TABLES: sscrfields.
*** Variablen
DATA:
*** Pointer für CREATE DATA
gref TYPE REF TO data,
*** Name der Datenbanktabelle
gv_sname LIKE dd02l-tabname VALUE 'T005',
*** Feldkatalog
gt_fcat TYPE lvc_t_fcat.
*** Feld-Symbole
FIELD-SYMBOLS:
*** Feldkatalog
<fcat> TYPE lvc_s_fcat,
*** Feld der Struktur
<feld> TYPE ANY,
*** Arbeitsbereich der internen Tabelle
<wa> TYPE ANY,
*** Die interne Tabelle mit Struktur aus GV_SNAME
<itab> TYPE table.
SELECTION-SCREEN PUSHBUTTON 01(30) p_0200 USER-COMMAND 0200.
*----------------------------------------------------------------------*
* CLASS lcl_events DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed sender.
ENDCLASS. "lcl_events DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_rohr_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_events IMPLEMENTATION.
METHOD handle_data_changed.
******************************************
*** HandleDataChanged ***
******************************************
DATA: ls_good TYPE lvc_s_modi.
*** alle Inhalte der geänderten Zellen in die interne Tabelle schreiben
LOOP AT er_data_changed->mt_good_cells INTO ls_good.
*** Dazu auf die richtige Zeile in der ITAB positionieren:
READ TABLE <itab> ASSIGNING <wa> INDEX ls_good-row_id.
IF sy-subrc = 0.
*** Und das geänderte Feld dem Feldsymbol zuweisen
ASSIGN COMPONENT ls_good-fieldname OF STRUCTURE <wa> TO <feld>.
IF sy-subrc = 0.
*** Feldwert zuweisen
<feld> = ls_good-value.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_events IMPLEMENTATION
*** Variablen ALV
DATA:
ref_alv TYPE REF TO cl_gui_alv_grid,
ref_container TYPE REF TO cl_gui_custom_container,
ref_alv_events TYPE REF TO lcl_events.
INITIALIZATION.
MOVE 'zu Dynpro 0200' TO p_0200.
AT SELECTION-SCREEN.
IF sscrfields-ucomm = '0200'.
CALL SCREEN 0200.
ENDIF.
*** Programmstart
START-OF-SELECTION.
*** Aufruf des Dynpros
CALL SCREEN 4000.
*&---------------------------------------------------------------------*
*& Form init
*&---------------------------------------------------------------------*
FORM init.
*** Container erzeugen
* CHECK ref_alv IS INITIAL.
CREATE OBJECT ref_container
EXPORTING container_name = 'ALV'.
TRY.
*** Erzeugung der Datenstrukturen zur Laufzeit
CREATE DATA gref TYPE STANDARD TABLE OF (gv_sname).
ASSIGN gref->* TO <itab>.
*** Einlesen der Daten
SELECT * FROM (gv_sname)
INTO TABLE <itab>
UP TO 10 ROWS.
*** Fehler abfangen
CATCH cx_sy_create_data_error.
WRITE 'Wrong Database!'.
ENDTRY.
*** Feldkatalog einlesen
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = gv_sname
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
OTHERS = 3.
*** Alle Felder editierbar machen
* LOOP AT gt_fcat ASSIGNING <fcat>.
LOOP AT gt_fcat ASSIGNING <fcat> WHERE fieldname = 'LAND1'.
IF sy-ucomm = 'CMD_EDIT'.
<fcat>-edit = 'X'.
ELSE.
<fcat>-edit = ''.
ENDIF.
ENDLOOP.
*** ALV erzeugen
PERFORM create_alv.
ENDFORM. "init
*&---------------------------------------------------------------------*
*& Module STATUS_4000 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_4000 OUTPUT.
*** Status
SET TITLEBAR '4000'.
SET PF-STATUS 'STLI' OF PROGRAM 'SAPMSSY0'.
*** Clear
* CLEAR sy-ucomm.
*** Init ALV
PERFORM init.
ENDMODULE. " STATUS_4000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_4000 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_4000 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR '%EX' OR 'RW'.
*** Liste
LEAVE TO LIST-PROCESSING.
SET PF-STATUS space.
**** Tabelleninhalt ausgeben
* LOOP AT <itab> ASSIGNING <wa>.
* NEW-LINE.
* DO.
* ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <feld>.
* IF sy-subrc = 0.
**** Ausgabe des Feldes
* WRITE: <feld>.
* ELSE.
* EXIT. "from DO-LOOP
* ENDIF.
* ENDDO.
* ENDLOOP.
*** Exit
SET SCREEN 0. LEAVE SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_4000 INPUT
*&---------------------------------------------------------------------*
*& Form create_alv
*&---------------------------------------------------------------------*
FORM create_alv .
*** ALV anbinden
CREATE OBJECT ref_alv
EXPORTING
i_parent = ref_container
i_appl_events = 'X'
EXCEPTIONS
OTHERS = 5.
*** Edit-Event extra registrieren
CALL METHOD ref_alv->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*** Edit-Mode aktiv setzen
CALL METHOD ref_alv->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
*** ...und EventHandler zuweisen
CREATE OBJECT ref_alv_events.
SET HANDLER ref_alv_events->handle_data_changed FOR ref_alv.
*** First Display
CALL METHOD ref_alv->set_table_for_first_display
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = <itab>
EXCEPTIONS
OTHERS = 4.
*** Fokus auf das Grid setzen
CALL METHOD cl_gui_alv_grid=>set_focus
EXPORTING
control = ref_alv
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
*** Flush
CALL METHOD cl_gui_cfw=>flush.
ENDFORM. " create_alv
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0200 OUTPUT.
SET PF-STATUS 'STLI' OF PROGRAM 'SAPMSSY0'.
ENDMODULE. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR '%EX' OR 'RW'.
*** Liste
LEAVE TO LIST-PROCESSING.
SET PF-STATUS space.
**** Tabelleninhalt ausgeben
* LOOP AT <itab> ASSIGNING <wa>.
* NEW-LINE.
* DO.
* ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <feld>.
* IF sy-subrc = 0.
**** Ausgabe des Feldes
* WRITE: <feld>.
* ELSE.
* EXIT. "from DO-LOOP
* ENDIF.
* ENDDO.
* ENDLOOP.
*
*** Exit
SET SCREEN 0. LEAVE SCREEN.
WHEN 'CMD_SHOW' OR 'CMD_EDIT'.
CALL SCREEN 4000.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT