Code: Alles auswählen.
* erstellen einer internen tabelle mit Datenstruktur & Style-Tabelle
DATA: BEGIN OF gt_pricing_cond_alv OCCURS 0.
INCLUDE STRUCTURE /bshs/ci_s_conditions.
DATA: input_style TYPE lvc_t_styl.
DATA: END OF gt_pricing_cond_alv.
data: gt_pricing_cond type standard table of /bshs/ci_s_conditions.
* layout struktur
lwa_layout TYPE lvc_s_layo
...
* interne Tabelle mit daten füllen
LOOP AT gt_pricing_cond INTO lwa_pricing_cond.
MOVE-CORRESPONDING lwa_pricing_cond TO lwa_pricing_cond_alv.
IF lwa_pricing_cond-kmanu <> 'D'.
lwa_input_style-fieldname = 'KBETR'.
lwa_input_style-style = alv_grid_3->mc_style_enabled.
APPEND lwa_input_style TO lwa_pricing_cond_alv-input_style.
ENDIF.
APPEND lwa_pricing_cond_alv TO gt_pricing_cond_alv.
ENDLOOP.
* parameter setzen & alv grid aufrufen
lwa_layout-stylefname = 'INPUT_STYLE'.
CALL METHOD alv_grid_3->set_table_for_first_display
EXPORTING
i_structure_name = '/BSHS/CI_S_CONDITIONS'
is_variant = gs_variant
is_layout = lwa_layout
i_save = g_save
CHANGING
it_outtab = gt_pricing_cond_alv.
Code: Alles auswählen.
lwa_layout-edit = 'X'.
Code: Alles auswählen.
* Datendeklaration
DATA: BEGIN OF gt_outtab_alv OCCURS 0.
INCLUDE STRUCTURE <DDIC-Struktur>.
DATA: input_style TYPE lvc_t_styl.
DATA: END OF gt_outtab_alv.
DATA: lwa_input_style TYPE lvc_s_styl
,lwa_layout TYPE lvc_s_layo
,lwa_fieldinfo TYPE DFIES
.
* Erstellen der internen Tabelle GT_OUTTAB_ALV
PERFORM CREATE_OUTTAB.
* Vorbereiten der relevanten Strukturen fürs ALV-Grid
lwa_layout-stylefname = 'INPUT_STYLE'.
lwa_layout-edit = 'X'. " wichtiges Flag
* Aufruf Methode SET_TABLE_FIRST_DISPLAY & SET_READY_FOR_INPUT
CALL METHOD alv_grid_3->set_table_for_first_display
EXPORTING
i_structure_name = '<DDIC-Struktur>'
is_variant = gs_variant
is_layout = lwa_layout
i_save = g_save
CHANGING
it_outtab = gt_outtab_alv[].
CALL METHOD alv_grid_3->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
* Form CREATE_OUTTAB
FORM create_outtab
DATA: lv_index TYPE c,
lt_cellstyle TYPE lvc_t_styl.
LOOP AT gt_outtab INTO lwa_outtab.
MOVE-CORRESPONDING lwa_outtab TO lwa_outtab_alv.
APPEND lwa_outtab_alv TO gt_outtab_alv.
ENDLOOP.
LOOP AT gt_outtab_alv INTO lwa_outtab_alv.
lv_index = sy-tabix.
* IF-Bedingung nur Beispiel
IF lwa_outtab_alv-kmanu <> 'D'.
PERFORM set_input_alv_grid USING 'RW'
CHANGING lt_cellstyle.
ELSE.
PERFORM set_input_alv_grid USING 'RO'
CHANGING lt_cellstyle.
ENDIF.
INSERT LINES OF lt_cellstyle INTO TABLE
lwa_outtab_alv-input_style.
MODIFY gt_outtab_alv FROM lwa_outtab_alv INDEX lv_index.
CLEAR lt_cellstyle.
ENDLOOP.
ENDFORM.
* Form INPUT_ALV_GRID
FORM set_input_alv_grid_3 USING value(pa_mode)
CHANGING pt_celltab TYPE lvc_t_styl.
DATA: lwa_celltab TYPE lvc_s_styl,
lv_mode TYPE raw4.
IF pa_mode = 'RW'.
lv_mode = cl_gui_alv_grid=>mc_style_enabled.
ELSE.
lv_mode = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
* flexibler als hart codieren (Änderungen Struktur usw.)
IF gt_fieldinfo IS INITIAL.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = '<DDIC-Struktur>'
TABLES
dfies_tab = gt_fieldinfo.
ENDIF.
LOOP AT gt_fieldinfo INTO lwa_fieldinfo.
*IF-Bedingung nur Beispiel für ein eingabebereites Feld
IF lwa_fieldinfo-fieldname = 'KBETR'.
lwa_input_style-fieldname = lwa_fieldinfo-fieldname.
lwa_input_style-style = lv_mode.
ELSE.
lwa_input_style-fieldname = lwa_fieldinfo-fieldname.
lwa_input_style-style = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
INSERT lwa_input_style INTO TABLE pt_celltab.
ENDLOOP.
ENDFORM.