如果有清楚删除销售订单BAPI的大佬,可以给我留言,谢谢
*&---------------------------------------------------------------------*
*& Report ZSD019
*&---------------------------------------------------------------------*
*& 抬头 : VA02销售订单删除 *
*& 模块 : SD *
*& 作者 : ZHANGS *
*& 创建日期 : 2019/04/09 *
*& 修改记录 : *
*& 日期 修改人 修改内容 *
*& YYYY/MM/DD 修改人员名 说明 *
*&---------------------------------------------------------------------*
REPORT zsd019.
TABLES:sscrfields.
TYPE-POOLS : slis.
DATA:functxt TYPE smp_dyntxt.
DATA:gv_temp TYPE wwwdatatab-objid VALUE 'ZSD019'."SMW0 对象名
DATA:gt_fcat TYPE lvc_t_fcat,
ga_fcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo,
gc_grid TYPE REF TO cl_gui_alv_grid.
DATA:g_check TYPE char01. "ALVA界面导入按钮控制标识
DEFINE alv_field.
CLEAR ga_fcat.
ga_fcat-fieldname = &1. "内表的字段名
ga_fcat-ref_table = &2. "输出数据的内表名
ga_fcat-ref_field = &3. "为key
ga_fcat-scrtext_l = &4. "字段描述
ga_fcat-colddictxt = 'L'.
ga_fcat-checkbox = &5. "字段描述
ga_fcat-edit = &6. "字段描述
APPEND ga_fcat TO gt_fcat.
END-OF-DEFINITION.
DATA: BEGIN OF gw_excel,
vbeln TYPE vbak-vbeln, "销售订单号
icon TYPE char04, "标识 : @EB@ 熄灯 ; @0A@ 红灯 ; @08@ 绿灯 ; @09@ 黄灯
msg TYPE string, "处理消息
END OF gw_excel.
DATA gt_excel LIKE gw_excel OCCURS 0 WITH HEADER LINE.
DATA:bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA:nodata_character VALUE '/'.
DATA: message_rfc LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,
bdc_ctu_params LIKE ctu_params,
g_subrc TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK blc_001 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_file TYPE rlgrap-filename MEMORY ID f04. "MEMORY ID不退出程序一直记住路径
PARAMETERS:p_mode TYPE c DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK blc_001.
SELECTION-SCREEN: FUNCTION KEY 1.
INITIALIZATION.
"下载模板按钮
functxt-icon_id = icon_xls.
functxt-icon_text = '下载模板'.
sscrfields-functxt_01 = functxt.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
"Help
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'FC01' .
DATA: g_file TYPE sapb-sappfad.
DATA: e_error TYPE char255.
CLEAR e_error.
PERFORM frm_download_excel_fromserver USING gv_temp g_file
CHANGING e_error.
IF e_error IS INITIAL.
MESSAGE '下载成功!' TYPE 'S'.
ELSE.
MESSAGE e_error TYPE 'E'.
ENDIF.
WHEN OTHERS.
ENDCASE.
AT SELECTION-SCREEN OUTPUT.
START-OF-SELECTION.
IF p_file IS INITIAL.
MESSAGE '请选择要导入的文件' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
PERFORM frm_get_data USING p_file.
PERFORM frm_display_alv.
ENDIF. "装运点
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
FORM bdc_field USING fnam fval.
IF fval <> nodata_character.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM.
FORM frm_bdc_delva02.
LOOP AT gt_excel.
PERFORM bdc_dynpro USING 'SAPMV45A' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VBAK-VBELN'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SUCH'.
PERFORM bdc_field USING 'VBAK-VBELN'
gt_excel-vbeln.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/ELOES'.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=YES'.
PERFORM bdc_transaction_rfc USING 'VA02' p_mode.
IF g_subrc = 0.
COMMIT WORK AND WAIT.
gt_excel-msg = '销售订单删除成功'.
ELSE.
ROLLBACK WORK.
READ TABLE message_rfc WITH KEY msgtyp = 'E'.
IF sy-subrc = 0.
ELSE.
READ TABLE message_rfc INDEX 1.
ENDIF.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = message_rfc-msgid
msgnr = message_rfc-msgnr
msgv1 = message_rfc-msgv1
msgv2 = message_rfc-msgv2
msgv3 = message_rfc-msgv3
msgv4 = message_rfc-msgv4
IMPORTING
message_text_output = gt_excel-msg.
ENDIF.
MODIFY gt_excel.
CLEAR:gt_excel,bdcdata[].
ENDLOOP.
ENDFORM.
FORM bdc_transaction_rfc USING tcode p_mode.
REFRESH message_rfc.
CLEAR message_rfc.
bdc_ctu_params-dismode = p_mode.
bdc_ctu_params-updmode = 'S'.
bdc_ctu_params-cattmode = ''.
bdc_ctu_params-defsize = ''.
bdc_ctu_params-racommit = ''.
bdc_ctu_params-nobinpt = 'X'.
bdc_ctu_params-nobiend = ''.
CALL TRANSACTION tcode USING bdcdata
* MODE p_mode "A-前台 N-后台 E-错误
* UPDATE 'S'
OPTIONS FROM bdc_ctu_params
MESSAGES INTO message_rfc.
g_subrc = sy-subrc.
CLEAR bdcdata[].
ENDFORM.
FORM frm_download_excel_fromserver USING p_objid LIKE wwwdatatab-objid
p_file LIKE sapb-sappfad
CHANGING e_error TYPE char255.
DATA:lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
CONCATENATE p_objid '.XLSX' INTO ls_objnam.
SELECT SINGLE relid objid FROM wwwdata
INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = p_objid.
IF sy-subrc NE 0 OR lo_objdata-objid EQ space.
CONCATENATE '不存在模板' ls_objnam ',请检查' INTO e_error.
RETURN.
ENDIF.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = 'VL02销售订单删除模板.xlsx'
mode = 'S'
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
ls_destination = p_file.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE 0.
CONCATENATE '下载模板' ls_objnam '失败,请检查!' INTO e_error.
ENDIF.
ENDFORM.
FORM frm_get_data USING p_file.
DATA: lt_data TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' "读取excel文件中的内容
EXPORTING
filename = p_file
i_begin_col = '1' "开始列
i_begin_row = '2' "开始行
i_end_col = '50'
i_end_row = '9999'
TABLES
intern = lt_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE s000(oo) WITH 'EXCEL导入失败' DISPLAY LIKE 'E'.
STOP.
ENDIF.
SORT lt_data BY row col value.
DATA: lv_index LIKE sy-index.
DATA:l_vbeln TYPE vbak-vbeln.
FIELD-SYMBOLS: <fs_excel> TYPE any.
LOOP AT lt_data.
CLEAR lv_index.
lv_index = lt_data-col+2(2).
ASSIGN COMPONENT lv_index OF STRUCTURE gw_excel TO <fs_excel>.
IF sy-subrc EQ 0.
<fs_excel> = lt_data-value.
ENDIF.
AT END OF row.
CLEAR l_vbeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gw_excel-vbeln
IMPORTING
output = l_vbeln.
SELECT SINGLE vbeln FROM vbak INTO l_vbeln WHERE vbeln = l_vbeln.
IF sy-subrc IS INITIAL.
gw_excel-icon = '@08@'.
ELSE.
gw_excel-icon = '@0A@'. "红灯
gw_excel-msg = 'VBAK表不存在销售订单,无法删除'. "红灯
g_check = 'X'.
ENDIF.
APPEND gw_excel TO gt_excel.
ENDAT.
ENDLOOP.
IF gt_excel[] IS INITIAL.
MESSAGE '上载数据为空' TYPE 'E'.
ELSE.
ENDIF.
ENDFORM.
FORM frm_display_alv .
CLEAR: gs_layout.
gs_layout-zebra = 'X'.
gs_layout-sel_mode = 'A'.
gs_layout-cwidth_opt = 'X'.
PERFORM frm_get_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_grid_title = lv_grid_title
* I_BUFFER_ACTIVE = 'X'
i_default = 'X'
i_save = 'X'
i_callback_user_command = 'FRM_USER_COMMAND'
i_callback_pf_status_set = 'FRM_SET_PF_STATUS'
it_fieldcat_lvc = gt_fcat[]
is_layout_lvc = gs_layout
* it_events = lt_event
TABLES
t_outtab = gt_excel[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM frm_get_fieldcat .
REFRESH gt_fcat.
alv_field: 'ICON' '' '' '信号灯' ' ' ''.
alv_field: 'MSG' '' '' '消息' ' ' ''.
alv_field: 'VBELN' 'VBAK' 'VBELN' '销售订单号' ' ' ''.
ENDFORM.
FORM frm_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* 获取自定义按钮的内表更新
DATA lr_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
CASE r_ucomm.
WHEN 'ZIMPORT'. "在GUI状态上维护
PERFORM frm_bdc_delva02.
ENDCASE.
rs_selfield-refresh = 'X'.
ENDFORM. "USER_COMMAND
FORM frm_set_pf_status USING rt_extab TYPE slis_t_extab.
"copy 程序SAPLKKBL的GUI状态STANDARD_FULLSCREEN
DATA: lv_ucomm TYPE sy-ucomm,
lt_ucomm TYPE TABLE OF sy-ucomm.
CLEAR:lv_ucomm,lt_ucomm[].
IF g_check = 'X'.
MOVE 'ZIMPORT' TO lv_ucomm.
APPEND lv_ucomm TO lt_ucomm.
ENDIF.
SET PF-STATUS 'ZSD019' EXCLUDING lt_ucomm.
ENDFORM.