SD--批量删除订单
SD--批量删除订单
在sap应用中常常会需要批量删除一些错误录入的单据,为此开发了一个小程序。该程序为了安全,程序做了一下控制
1、限制用户只能删除自己的订单,不能删除别人输入的订单,如果需要修改一下查询条件;
2、系统默认为“测试运行”,方便用户在删除订单前要核实一下订单,确认不要误操作;
程序代码如下,供大家参考!
REPORT zsde0099.
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
* data Declarations
*----------------------------------------------------------------------*
TABLES: vbak. " Sales Document: Header Data
*----------------------------------------------------------------------*
* table control Output Declarations
*----------------------------------------------------------------------*
TYPES: BEGIN OF tc_0100,
sel(1), " Check box
vbeln LIKE vbak-vbeln, " Sales Order Number
erdat LIKE vbak-erdat, " Sales order creation date
ernam LIKE vbak-ernam,
kunnr LIKE likp-kunag, " Sold-to Party
name1 LIKE kna1-name1, " Sold-to Company Name
text(200),
END OF tc_0100.
DATA: wa_tc_0100 TYPE tc_0100,
it_tc_0100 TYPE tc_0100 OCCURS 0 WITH HEADER LINE.
DATA g_fieldcat TYPE slis_t_fieldcat_alv.
*----------------------------------------------------------------------*
* Selection Screen
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK params1 WITH FRAME TITLE text-001.
PARAMETER: s_vkorg LIKE vbak-vkorg DEFAULT ‘6001‘ OBLIGATORY MODIF ID s1. " " Sales Org.
SELECT-OPTIONS:
s_vtweg FOR vbak-vtweg OBLIGATORY, " Distribution Channel
s_spart FOR vbak-spart OBLIGATORY DEFAULT ‘10‘, " Division
s_auart FOR vbak-auart OBLIGATORY, " Order type
s_erdat FOR vbak-erdat OBLIGATORY, " Sales order creation date
* s_ERNAM FOR vbak-ERNAM OBLIGATORY , " Sales order creation date
s_kunnr FOR vbak-kunnr , " Sold-to party
s_vbeln FOR vbak-vbeln . " Sales Order
PARAMETER p_test AS CHECKBOX DEFAULT ‘X‘.
SELECTION-SCREEN END OF BLOCK params1.
***********************************************************************
*INITIALIZATION.
***********************************************************************
INITIALIZATION.
s_auart-sign = ‘I‘.
s_auart-option = ‘EQ‘.
s_auart-low = ‘ZC01‘.
APPEND s_auart.
s_auart-low = ‘ZC03‘.
APPEND s_auart.
s_auart-low = ‘ZC06‘.
APPEND s_auart.
s_auart-low = ‘ZC20‘.
APPEND s_auart.
s_vtweg-sign = ‘I‘.
s_vtweg-option = ‘EQ‘.
s_vtweg-low = ‘10‘.
APPEND s_vtweg.
s_vtweg-low = ‘20‘.
APPEND s_vtweg.
s_vtweg-low = ‘30‘.
APPEND s_vtweg.
s_vtweg-low = ‘40‘.
APPEND s_vtweg.
*----------------------------------------------------------------------*
* Selection Events Processing
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
PERFORM screen_check.
AT SELECTION-SCREEN.
CLEAR: it_tc_0100, wa_tc_0100.
REFRESH: it_tc_0100.
START-OF-SELECTION.
PERFORM extract_data.
END-OF-SELECTION.
PERFORM change_sales_orders.
PERFORM display_mes.
*&---------------------------------------------------------------------*
*& Form SCREEN_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM screen_check.
DATA: l_line TYPE i .
DESCRIBE TABLE s_erdat LINES l_line.
IF l_line EQ 0.
s_erdat-sign = ‘I‘.
s_erdat-option = ‘BT‘.
s_erdat-high = sy-datum.
s_erdat-low = sy-datum.
APPEND s_erdat.
ENDIF.
DESCRIBE TABLE s_vtweg LINES l_line.
IF l_line EQ 0.
ENDIF.
ENDFORM. "SCREEN_CHECK
*&---------------------------------------------------------------------*
*& Form extract_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM extract_data.
DATA: lt_it1 LIKE it_tc_0100 OCCURS 0 WITH HEADER LINE,
l_chk(1). " for exclude incomplete SO
SELECT a~vbeln a~erdat a~ernam a~kunnr INTO CORRESPONDING FIELDS OF TABLE lt_it1
FROM vbak AS a
WHERE a~vbeln IN s_vbeln
AND a~auart IN s_auart
AND a~vkorg EQ s_vkorg
AND a~vtweg IN s_vtweg
AND a~spart IN s_spart
AND a~erdat IN s_erdat
AND a~ernam = sy-uname
AND a~kunnr IN s_kunnr.
LOOP AT lt_it1.
* get sold-to party company name
PERFORM get_customer_company_name USING lt_it1-kunnr CHANGING lt_it1-name1.
MODIFY lt_it1.
ENDLOOP.
it_tc_0100[] = lt_it1[].
ENDFORM. "extract_data
*&---------------------------------------------------------------------*
*& Form GET_CUSTOMER_COMPANY_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->F_KUNNR text
* -->F_NAME text
*----------------------------------------------------------------------*
FORM get_customer_company_name USING f_kunnr CHANGING f_name.
CLEAR f_name.
SELECT SINGLE name1 INTO f_name
FROM kna1
WHERE kunnr = f_kunnr.
ENDFORM. "GET_CUSTOMER_COMPANY_NAME
*&---------------------------------------------------------------------*
*& Form change_sales_orders
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM change_sales_orders.
DATA: lt_order_header_in LIKE bapisdh1,
lt_order_header_inx LIKE bapisdh1x,
lt_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
lt_order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE,
lt_order_item_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,
cp_eind(1).
SORT it_tc_0100 BY vbeln.
DELETE ADJACENT DUPLICATES FROM it_tc_0100.
LOOP AT it_tc_0100.
CLEAR: lt_order_header_inx,lt_order_item_in, lt_order_item_inx, lt_return,cp_eind.
REFRESH: lt_order_item_in, lt_order_item_inx, lt_return.
lt_order_header_inx-updateflag = ‘D‘.
IF p_test NE ‘X‘.
CALL FUNCTION ‘BAPI_SALESORDER_CHANGE‘
EXPORTING
salesdocument = it_tc_0100-vbeln
* ORDER_HEADER_IN = LT_ORDER_HEADER_IN
order_header_inx = lt_order_header_inx
TABLES
return = lt_return.
* 处理错误消息:通过判断消息的类型,来判断BAPI是否成功
LOOP AT lt_return .
IF lt_return-type EQ ‘E‘ OR
lt_return-type = ‘A‘ OR
lt_return = ‘X‘.
cp_eind = ‘X‘. "失败
it_tc_0100-text = lt_return-message.
ENDIF.
ENDLOOP.
IF cp_eind NE ‘X‘.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
EXPORTING
wait = ‘X‘.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
ENDIF.
ENDIF.
IF cp_eind NE ‘X‘ AND sy-subrc = 0.
IF p_test = ‘X‘.
it_tc_0100-text = ‘Test successfully.‘.
ELSE.
it_tc_0100-text = ‘Delete successfully.‘.
ENDIF.
ELSE.
CONCATENATE it_tc_0100-text ‘---‘ ‘Delete error.‘ into it_tc_0100-text.
ENDIF.
MODIFY it_tc_0100.
ENDLOOP.
ENDFORM. "change_sales_orders
*&---------------------------------------------------------------------*
*& Form init_fieldedi
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FIELDTAB text
*----------------------------------------------------------------------*
FORM init_fieldedi USING p_p_fieldtab TYPE slis_t_fieldcat_alv.
DATA: l_fieldcat TYPE slis_fieldcat_alv.
REFRESH p_p_fieldtab.
CLEAR l_fieldcat.
l_fieldcat-fieldname = ‘VBELN‘.
l_fieldcat-seltext_m = ‘ORDER NUMBER‘.
l_fieldcat-outputlen = 10.
APPEND l_fieldcat TO p_p_fieldtab.
CLEAR l_fieldcat.
l_fieldcat-fieldname = ‘ERDAT‘.
l_fieldcat-seltext_m = ‘Create Date‘.
l_fieldcat-ref_fieldname = ‘ERDAT‘.
l_fieldcat-ref_tabname = ‘VBAK‘.
l_fieldcat-outputlen = 10.
APPEND l_fieldcat TO p_p_fieldtab.
CLEAR l_fieldcat.
l_fieldcat-fieldname = ‘ERNAM‘.
l_fieldcat-seltext_m = ‘Input Person‘.
l_fieldcat-ref_fieldname = ‘ERDAT‘.
l_fieldcat-ref_tabname = ‘VBAK‘.
l_fieldcat-outputlen = 10.
APPEND l_fieldcat TO p_p_fieldtab.
CLEAR l_fieldcat.
l_fieldcat-fieldname = ‘KUNNR‘.
l_fieldcat-seltext_m = ‘Sold Code‘.
l_fieldcat-ref_fieldname = ‘KUNNR‘.
l_fieldcat-ref_tabname = ‘VBAK‘.
l_fieldcat-outputlen = 10.
APPEND l_fieldcat TO p_p_fieldtab.
CLEAR l_fieldcat.
l_fieldcat-fieldname = ‘NAME1‘.
l_fieldcat-seltext_m = ‘Sold Name1‘.
l_fieldcat-outputlen = 35.
APPEND l_fieldcat TO p_p_fieldtab.
CLEAR l_fieldcat.
l_fieldcat-fieldname = ‘TEXT‘.
l_fieldcat-seltext_m = ‘Message‘.
l_fieldcat-outputlen = 120.
APPEND l_fieldcat TO p_p_fieldtab.
ENDFORM. " INITIALIZE_FIELDEDI
*&---------------------------------------------------------------------*
*& Form display_mes
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_mes .
PERFORM init_fieldedi USING g_fieldcat[].
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
EXPORTING
i_callback_program = sy-repid
it_fieldcat = g_fieldcat[]
i_save = ‘A‘
i_default = ‘A‘
TABLES
t_outtab = it_tc_0100.
ENDFORM. " display_mes
原文:http://blog.csdn.net/sap_jack/article/details/46505343
SD--批量删除订单的更多相关文章
- Thinkphp 全选、反选 批量删除
完整案例 前台 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- Memcached的批量删除方案总结
Memcached的批量删除,向来是Memcached使用者很头疼的事情,因为Memcached采取的缓存方案是哈希表结构,所以没有办法实现delete from tablename where ke ...
- tp5 ajax批量删除(自写)
html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- php批量删除
php批量删除可以实现多条或者全部数据一起删除 新建php文件 显示数据库中内容: <table width="100%" border="1" cell ...
- confirm对话框取消后阻止ajax操作、ajax做批量删除
在做批量删除的时候,需要用confirm弹出一个提示框让用户确认是否删除,点击确定,执行操作,点击取消,取消操作.但是如果使用ajax把选中项的主键值传到处理页面处理时,如果使用下面的方法将confi ...
- mybatis批量删除提示类型错误
一. 这里主要考虑两种参数类型:数组或者集合. 而这点区别主要体现在EmpMapper.xml文件中标签的collection属性: 当collection="array"时,表名 ...
- php链接数据库 批量删除 和 注册审核
理解 : hiden value session name="a[]" 1. form 表单上传的 value=" "值 ...
- StackExchange.Redis加载Lua脚本进行模糊查询的批量删除和修改
前言 使用StackExchange.Redis没有直接相关的方法进行模糊查询的批量删除和修改操作,虽然可以通过Scan相关的方法进行模糊查询,例如:HashScan("hashkey&qu ...
- Ado.net[登录,增删改查,Get传值,全选,不选,批量删除,批量更新]
[虽然说,开发的时候,我们可以使用各种框架,ado.net作为底层的东西,作为一个合格的程序员,在出问题的时候我们还是要知道如何调试] 一.增删改查 cmd.ExecuteReader();执行查询, ...
随机推荐
- Axure RP Extension for Chrome修复
Axure RP Extension for Chrome安装之前一直用 Firefox 浏览器浏览原型文件,一直用不惯,而且用 Firefox 的唯一目的就是看原型.其他都是用 Chrome 浏览器 ...
- python中函数嵌套、函数作为变量以及闭包的原理
嵌套函数: python允许创建嵌套函数.也就是说我们可以在函数里面定义函数,而且现有的作用域和变量生存周期依旧不变. 例子: #encoding=utf-8 def outer(): name ...
- eclipse的svn插件添加代理访问svn
1.首先找到插件配置文件 C:\Users\Administrator\AppData\Roaming\Subversion这个目录下的servers文件 打开找到 # http-proxy-host ...
- IntelliJ IDEA. Debug模式
资料收集: https://www.bilibili.com/video/av6749471/?p=16 eclipse debug模式. 基础 Intellij Idea--Debug使用 Inte ...
- Sort aborted Error in MySQL Error Log
现象 [ERROR] lines containing "Sort aborted" are present in the MySQL error log file. [Warni ...
- strpos 的正确使用方式
首先简单介绍下strpos函数: strpos函数是查找某个字符在字符串中的位置:这里需要明确这个函数的作用: 这个函数得到的是位置:如果存在:返回数字:否则返回的是false: 而很多时候我们拿这个 ...
- 搭建一个简单的svn服务器(旧)
cenos 6.5,svnserver 1.6.11 默认可能已经安装,没有的话就: yum install svn -ysvnserver --version 创建一个svn仓库: svnadmin ...
- 零基础Python爬虫实现(爬取最新电影排行)
提示:本学习来自Ehco前辈的文章, 经过实现得出的笔记. 目标网站 http://dianying.2345.com/top/ 网站结构 要爬的部分,在ul标签下(包括li标签), 大致来说迭代li ...
- 20145311王亦徐 《网络对抗技术》 MSF基础应用
20145311王亦徐 <网络对抗技术> MSF基础应用 实验内容 掌握metasploit的基本应用方式以及常用的三种攻击方式的思路 主动攻击,即对系统的攻击,不需要被攻击方配合,以ms ...
- day 26 元类
一.isinstance issubclass class Person: passclass Student(Person): passstu1=Student()#判断是不是实例print(isi ...