**************************修改,保存数据********************************BEGIN1
DATA: lt_spfli TYPE TABLE OF spfli.
DATA: lt_spfli_old TYPE TABLE OF spfli.
DATA: lt_spfli_upd TYPE TABLE OF spfli.
DATA: ls_spfli_old TYPE spfli.
DATA: ls_spfli_new TYPE spfli.
DATA: ls_layout TYPE slis_layout_alv.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.
START-OF-SELECTION.
PERFORM data_selection.
PERFORM build_layout.
PERFORM build_fieldcatalog.
PERFORM display_alv.
*&———————————————————————
*& Form DATA_SELECTION
*&———————————————————————*
FORM data_selection .
SELECT * FROM spfli INTO TABLE lt_spfli.
lt_spfli_old = lt_spfli.
ENDFORM. " DATA_SELECTION
*&———————————————————————
*& Form BUILD_LAYOUT
*&———————————————————————*
FORM build_layout.
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
ENDFORM. " BUILD_LAYOUT
*&———————————————————————
*& Form BUILD_FIELDCATALOG
*&———————————————————————*
FORM build_fieldcatalog .
DATA: ls_fieldcat LIKE LINE OF lt_fieldcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
"“i_internal_tabname =
i_structure_name = 'SPFLI'
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
LOOP AT lt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN 'COUNTRYFR' OR 'COUNTRYTO' OR 'CITYFROM' OR 'CITYTO'.
ls_fieldcat-edit = 'X'.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING edit.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDFORM. "” BUILD_FIELDCATALOG
*&———————————————————————
*& Form DISPLAY_ALV
*&———————————————————————*
FORM display_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_grid_title = '这是标题!!!!!!'
i_callback_user_command = 'EDIT_AND_SAVE' "” this has to be used to handle SAVE
i_callback_top_of_page = 'ALV_HEADER'
"i_structure_name = ‘SPFLI’
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = lt_spfli
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " DISPLAY_ALV
FORM edit_and_save USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&DATA_SAVE'.
LOOP AT lt_spfli INTO ls_spfli_new.
READ TABLE lt_spfli_old INTO ls_spfli_old INDEX sy-tabix.
CHECK sy-subrc IS INITIAL.
IF ls_spfli_old <> ls_spfli_new.
APPEND ls_spfli_new TO lt_spfli_upd.
CLEAR: ls_spfli_new, ls_spfli_old.
ENDIF.
ENDLOOP.
CHECK lt_spfli_upd IS NOT INITIAL.
UPDATE spfli FROM TABLE lt_spfli_upd.
IF sy-subrc IS INITIAL.
COMMIT WORK.
CLEAR: lt_spfli_upd.
lt_spfli_old = lt_spfli.
ELSE.
ROLLBACK WORK.
lt_spfli = lt_spfli_old.
ENDIF.
rs_selfield-refresh = abap_true.
WHEN OTHERS.
ENDCASE.
ENDFORM.
FORM alv_header.
DATA: lt_comment TYPE slis_t_listheader.
DATA: ls_comment TYPE LINE OF slis_t_listheader.
ls_comment-typ = 'H'.
ls_comment-info = 'Flight Information'.
APPEND ls_comment TO lt_comment.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_comment
i_logo = 'FLIGHT_ALV'."添加图片
ENDFORM.
**************************修改,保存数据********************************END
ALV报表修改保存,标题,图片(REUSE_ALV_GRID_DISPLAY)
于 2022-04-24 17:22:27 首次发布