sap 物料跨工厂移库abap实现代码
时间: 2023-09-02 19:14:15 浏览: 183
sap中abap编程资料
以下是一个简单的 SAP ABAP 代码示例,用于在两个工厂之间移动物料:
```
DATA: l_t_sto TYPE STANDARD TABLE OF stpo,
l_s_sto LIKE LINE OF l_t_sto,
l_vgtyp TYPE vgtyp,
l_lgnum TYPE lgnum,
l_t001l TYPE t001l-lifnr.
* 获取源工厂的数据
SELECT SINGLE lifnr
FROM t001l
INTO l_t001l
WHERE werks = 'source_works'.
* 获取目标工厂的数据
SELECT SINGLE vgtyp
FROM t001l
INTO l_vgtyp
WHERE werks = 'destination_works'.
* 获取移动类型
SELECT SINGLE lgnum
FROM t158g
INTO l_lgnum
WHERE vgtyp = l_vgtyp.
* 获取物料的库存数量
SELECT stpo~menge
FROM stpo
WHERE stpo~matnr = 'material_number'
AND stpo~werks = 'source_works'
AND stpo~lgort = 'source_storage_location'.
* 创建移动单
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_goodsmvt_header
TABLES
goodsmvt_item = lt_goodsmvt_item
EXCEPTIONS
error_message = 1
OTHERS = 2.
* 提交移动单
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
```
请注意,在实际的实现中,您需要根据您的具体业务需求进行更改和调整。此代码仅提供了一个基本的框架,供您参考。
阅读全文