可以通过BAPI BAPI_MATERIAL_SAVEDATA为物料主数据创建/拓展 工厂视图(plant view).
例子代码如下:
实现功能很简单,就是将物料主数据拓展到新的工厂,也就是在MARC表中为新工厂创建一条记录。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
REPORT ztest_material_plant.
TABLES:mara.
* 数据声明
DATA: clidainp LIKE bapi_mara_ga, "客户端层次物料数据
clidaout LIKE bapi_mara, "客户端层次物料数据
clidaoutx LIKE bapi_marax, "BAPI_MARA 的复选框结构
headdata LIKE bapimathead, "带有控制信息的表头段
return LIKE bapiret2, "返回参数
lwa_plantdata TYPE bapi_marc,
lwa_plantdatax TYPE bapi_marcx,
returnmes LIKE bapi_matreturn2 OCCURS 0 WITH HEADER LINE.
* 取出要处理的物料编号
PARAMETERS: p_matnr LIKE marc-matnr,
p_werks LIKE marc-werks.
* 抬头数据 ,物料和视图维护
headdata-material = p_matnr.
headdata-storage_view = 'X'. "工厂视图
lwa_plantdata-plant = p_werks.
lwa_plantdatax-plant = p_werks.
* CallBAPI
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
plantdata = lwa_plantdata
plantdatax = lwa_plantdatax
IMPORTING
return = return
TABLES
returnmessages = returnmes.
IF return-type = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT returnmes.
WRITE: / returnmes-message.
ENDLOOP.
ELSEIF return-type = 'S'.
* Commit to release the locks
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WRITE: / '修改成功 ', p_matnr, 'OK'.
ENDIF.
|
程序运行成功后,会在MM03中查看到新创建的工厂视图
以上。