ALV中添加按钮 进行修改、创建、删除、添加、导入、保存等操作

&———————————————————————
*& Form FRM_CHANGE_FUNCTION
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_change_function .
DATA:lw_layout TYPE slis_layout_alv.
CLEAR: lw_layout.”它用来定义ALV报表的整体属性
lw_layout-edit = ‘X’.
CALL FUNCTION ‘REUSE_ALV_GRID_LAYOUT_INFO_SET’
EXPORTING
is_layout = lw_layout.
ENDFORM.
&———————————————————————
*& Form FRM_DELETE_FUNCTION
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_delete_function .
DATA: l_answer(1) TYPE c.
READ TABLE gt_out WITH KEY sel = ‘X’.
IF sy-subrc <> 0.
MESSAGE ‘请选择要删除的行!’ TYPE ‘E’.
ELSE.
CALL FUNCTION ‘POPUP_TO_CONFIRM’
EXPORTING
titlebar = ‘删除’
text_question = ‘是否要删除该内容?’
default_button = ‘2’
display_cancel_button = ‘X’
IMPORTING
answer = l_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF l_answer = ‘1’.
LOOP AT gt_out WHERE sel = ‘X’.
DELETE gt_out.
DELETE FROM zpm003 WHERE swerk = gt_out-swerk AND zzfgs = gt_out-zzfgs.
IF sy-subrc = 0.
MESSAGE ‘删除成功!’ TYPE ‘S’.
ELSE.
MESSAGE ‘删除失败!’ TYPE ‘E’.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM.
&———————————————————————
*& Form FRM_CREATE_FUNCTION
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_create_function .
APPEND INITIAL LINE TO gt_out.
ENDFORM.
&———————————————————————
*& Form FRM_SAVE_FUNCTION
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_save_function .
DATA: lv_valid TYPE char01.
DATA:lv_mes TYPE string.
DATA lt_save TYPE TABLE OF zpm003 WITH HEADER LINE.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = g_grid.
CALL METHOD g_grid->check_changed_data
IMPORTING
e_valid = lv_valid.
IF lv_valid IS INITIAL.
EXIT.
ENDIF.
REFRESH lt_save.
LOOP AT gt_out.
lt_save-swerk = gt_out-swerk.
lt_save-name1 = gt_out-name1.
lt_save-zzfgs = gt_out-zzfgs.
lt_save-butxt = gt_out-butxt.
lt_save-bukrs = gt_out-bukrs.
lt_save-butxt_d = gt_out-butxt_d.
APPEND lt_save.
CLEAR lt_save.
ENDLOOP.
MODIFY zpm003 FROM TABLE lt_save.
COMMIT WORK.
IF sy-subrc = 0.
MESSAGE ‘保存成功!’ TYPE ‘I’.
ELSE.
MESSAGE ‘保存失败!’ TYPE ‘E’.
ENDIF.
ENDFORM.
&———————————————————————
*& Form FRM_IMPORT_FUNCTION
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_import_function .
PERFORM frm_get_fiel_name.
PERFORM frm_excel_upload.
PERFORM frm_data_get.
ENDFORM.
&———————————————————————
*& Form FRM_GET_FIEL_NAME
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_get_fiel_name .
CALL FUNCTION ‘WS_FILENAME_GET’
EXPORTING
mode = ‘O’
title = ‘选取路径’
IMPORTING
filename = gv_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.

ENDFORM.
&———————————————————————
*& Form FRM_EXCEL_UPLOAD
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_excel_upload .
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
EXPORTING
filename = gv_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 4
i_end_row = 5000
TABLES
intern = gt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH gt_upload.
SORT gt_excel BY row.
LOOP AT gt_excel INTO gw_excel.
CASE gw_excel-col.
WHEN ‘001’.
gt_upload-swerk = gw_excel-value.
WHEN ‘002’.
gt_upload-name1 = gw_excel-value.
WHEN ‘003’.
gt_upload-zzfgs = gw_excel-value.
WHEN ‘004’.
gt_upload-butxt = gw_excel-value.
WHEN ‘005’.
gt_upload-bukrs = gw_excel-value.
WHEN ‘006’.
gt_upload-butxt_d = gw_excel-value.
WHEN OTHERS.
ENDCASE.
AT END OF row.
APPEND gt_upload.
CLEAR gt_upload.
ENDAT.
ENDLOOP.
ENDFORM.
&———————————————————————
*& Form FRM_DATA_GET
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_data_get .
DATA:lt_import LIKE TABLE OF zpm003 WITH HEADER LINE.
LOOP AT gt_upload.
MOVE-CORRESPONDING gt_upload TO gt_out.
APPEND gt_out.
CLEAR gt_out.
ENDLOOP.
REFRESH lt_import.
LOOP AT gt_out.
MOVE-CORRESPONDING gt_out TO lt_import.
APPEND lt_import.
CLEAR lt_import.
ENDLOOP.
MODIFY zpm003 FROM TABLE lt_import.
COMMIT WORK.
IF sy-subrc = 0.
MESSAGE ‘导入成功!’ TYPE ‘S’.
ELSE.
MESSAGE ‘导入失败’ TYPE ‘E’.
ENDIF.
ENDFORM.

你可能感兴趣的:(功能按钮,ALV)