wait 还是不wait,这是个问题。
这是同步更新还是异步更新的问题;如果是只commit work,是异步更新,触发注册在当前SAP LUW中所有数据更新动作,数据更新动作由SAP的更新工作进程来执行,当前程序不等待更新动作结束,直接向下执行。
commit work and wait 是同步更新,此语句触发注册在当前SAP LUW所有数据更新动作,当前主程序等待SAP更新进程完成数据更新操作,然后向下执行。严格来说,commit work and wait也不是彻底的同步更新,此处等待数据更新操作完成,是指只等V1更新(优先级较高)完成,不等待其他优先级较低的V2更新等。
在调用BAPI更新标准对象时,除少数BAPI在函数内做commit之外,其他均需要调用一下function module完成提交
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X' "
* IMPORTING
* RETURN =
.
EXPORTING
WAIT = 'X' "
* IMPORTING
* RETURN =
.
单就更新来说,这个参数 WAIT = 'X' 和commit work and wait 功能一样的。
可以使用以下模式的代码来看看wait 和不wait的更新效果
1 DO 2 TIMES. 2 IF sy-index = 1. 3 lv_wait = 'X'. 4 ELSE. 5 lv_wait = ''. 6 ENDIF. 7 CALL FUNCTION 'BAPI_PO_CREATE1' 8 EXPORTING 9 poheader = gs_head 10 poheaderx = gs_headx 11 * POADDRVENDOR = 12 * TESTRUN = 13 * MEMORY_UNCOMPLETE = 14 * MEMORY_COMPLETE = 15 * POEXPIMPHEADER = 16 * POEXPIMPHEADERX = 17 * VERSIONS = 18 * NO_MESSAGING = 19 * NO_MESSAGE_REQ = 20 * NO_AUTHORITY = 21 * NO_PRICE_FROM_PO = 22 IMPORTING 23 exppurchaseorder = lv_po 24 TABLES 25 return = gt_return 26 poitem = gt_items 27 poitemx = gt_itemx. 28 IF lv_po IS NOT INITIAL . 29 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 30 EXPORTING 31 wait = lv_wait "'X' 32 * IMPORTING 33 * RETURN = 34 . 35 SELECT SINGLE * INTO wa 36 FROM ekko 37 WHERE ebeln = lv_po. 38 IF sy-subrc EQ 0. 39 WRITE: 'Oh Yes, the PO has been inserted into database now', /. 40 ELSE. 41 WRITE: 'Come on, The update process is running still', /. 42 ENDIF. 43 ENDIF. 44 CLEAR wa. 45 CLEAR lv_po. 46 ENDDO.