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

时间: 2024-11-05 14:42:05

SD--批量删除订单的相关文章

Memcached如何实现高性能批量删除

Memcached的批量删除,向来是Memcached使用者很头疼的事情,因为Memcached采取的缓存方案是哈希表结构,所以没有办法实现delete from tablename where key like '%XX%'类似这样的批量删除功能.所以不得不自己采取一些策略实现批量删除.常见的删除方案主要有以下两种:第一种方案:通过记录KEY到DB然后循环删除.其实这也是最常规的删除方法,最容易想到,可能大部分人首先都会这么考虑.具体方法如下:1. 添加业务数据时,在向Memcached缓存s

mysq批量删除sleep进程

由于sleep进程比较多,就写个特简单的脚本,批量删除下,只保留5个即可 #!/bin/sh n=`/export/servers/mysql/bin/mysqladmin processlist -uroot -pxxxxx|grep -i sleep |wc -l` echo $n if [ "$n" -gt 10 ] then for i in `/export/servers/mysql/bin/mysqladmin processlist -uroot -pxxxxxx|gr

批量删除遇见的问题

做批量删除时遇见的问题: org.apache.ibatis.binding.BindingException: Parameter 'ids' not found. Available parameters are [array] 前台jsp页面的ajax请求可以进入: 但是点击批量删除的按钮时会报这个错误: 后来发现是Mapper中的collection定义错了: 把<foreach>标签中的collection="ids"改为collection="arra

利用yii2 gridview实现批量删除案例[转]

今天仍然继续探讨GridView的问题,昨天有个小伙伴留言说你用gridview给我去掉表头的链接?我想啊想,这用gridview确实不容易实现,至少我没想出来,会的下方可留言.但是呢,这根gridview有个毛线关联啊,明明是要设置ActiveDataProvider,你要我怎么用gridview实现嘛. 这个问题也是很简单的,我们来看看具体实现 $dataProvider = new ActiveDataProvider([ "query" => $query, ]); $d

【DRP】—【SQL】批量删除

1 /** 2 * 批量删除用户 3 * 4 * 采用一条语句完成删除 5 * 只提交一次 6 * 7 * 采用Statement拼串方式 8 * delete from t_user where user_id in ('aaaa', 'afff', 'eeee') 9 * @param userIds 10 */ 11 public void delUser(String[] userIds) { 12 StringBuilder sbStr = new StringBuilder(); 1

5月21 汽车查询及批量删除----php方法

---恢复内容开始--- 这个与之前不同是在php中实现了页面的查询,引用AJAX实现批量删除及弹窗的显示 作业要求: 页面显示数据代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.or

批处理 批量删除当前目录及子目录下多个指定的扩展名文件

批量删除当前目录及子目录下任意指定的扩展名文件 今编译DEV的语言文件,各种语言文件不需要,只保留中文的语言文件,写个批处理也方便以后使用 1 @echo off 2 set Path=%CD% 3 cd /d Path 4 del /f/s/q/a *.tlog 5 del /f/s/q/a *.cache 6 del /f/s/q/a *.txt 7 del /f/s/q/a *.pdb 8 del /f/s/q/a *.resources 9 del /f/s/q/a *.vspscc 1

如何禁止 Mac OS X 在外接设备上生成 .DS_Store 文件?以及如何批量删除 .DS_Store 文件?

如何禁止 Mac OS X 在外接设备上生成 .DS_Store 文件?以及如何批量删除 .DS_Store 文件?原文链接:http://www.java2class.net/bbs/viewthread.php?tid=254背景信息.DS_Store文件(Desktop Services Store)是一个隐藏的文件,在每一个目录下都有,它存放着这个文件目录的一些特定属性信息 Metadata,比如图标大小.位置.背景图片等属性:有点儿类似于 Windows 操作系统上的 Thumbs.d

批量删除本地指定扩展名文件工具

VC工具在编译时,会生成大量临时文件,占用很多空间,项目多了,手动删除就会很费力,所以我做了个小工具,可以批量删除指定目录,指定扩展名的文件. 此工具根据配置文件指定的扩展名删除文件,一般我删除VC的扩展名为:.ipch.pdb.pch.sdf.tlog.obj.idb.ilk.res.根据需要,自行配置. 下载地址:http://download.csdn.net/detail/yxstars/8201833 下面是一些vc扩展名的含义: .APS:存放二进制资源的中间文件,VC把当前资源文件