删除订单BOM的链接的文档(linked document)[BAPI_DOCUMENT_SAVEOBJECTLINKS]详解编程语言

1, 前台操作

Tcode:CSKB 输入销售订单号和行项目,点击start order browser展开订单BOM(order BOM).

2017-02-16_15-27-02

找到对应的物料,右键display

2017-02-16_15-28-06

可以看到链接的文档信息,

2017-02-16_15-28-36

2, 例子程序

可以通过函数BAPI_DOCUMENT_SAVEOBJECTLINKS删除order BOM中链接的文档。

逻辑如下:

删除order bom 行项目中链接的文档

1,STPO中读取objectkey,如果要删除订单BOM 头中的链接文档需要从STKO中读取

2,调用BAPI_DOCUMENT_GETOBJECTDOCS取得链接的文档信息

3,调用BAPI_DOCUMENT_SAVEOBJECTLINKS删除文档和订单BOM的链接关系

REPORT ztest_del_link. 
DATA:g_guidx         TYPE stpo-guidx, 
g_objectkey     TYPE bapi_doc_drad-objectkey, 
git_list        TYPE STANDARD TABLE OF bapi_doc_keys, 
gwa_list        TYPE bapi_doc_keys, 
git_objectlinks TYPE TABLE OF bapi_doc_drad, 
gwa_objectlinks TYPE bapi_doc_drad, 
gwa_return      TYPE bapiret2. 
* 测试,所以只取了1条,实际会有多条的情况 
SELECT SINGLE stpo~guidx 
INTO g_guidx 
FROM stpo 
INNER JOIN kdst ON stpo~stlnr = kdst~stlnr 
WHERE stpo~stlty = 'K' 
AND stpo~idnrk = 'B1-10'      "Material Number 
AND kdst~vbeln = '0690000318' "Sales Order Number 
AND kdst~vbpos = '200'        "Sales order Item 
AND kdst~werks = '8800'       "Plant 
       . 
g_objectkey = g_guidx. 
refresh:git_list. 
CALL FUNCTION 'BAPI_DOCUMENT_GETOBJECTDOCS' 
EXPORTING 
objecttype   = 'STPO_DOC'  "order bom 头用STKO_DOC 
objectkey    = g_objectkey 
*   CURRENTVERSIONSONLY       = 
date         = sy-datum 
*  IMPORTING 
*   RETURN       = 
TABLES 
documentlist = git_list[]. 
LOOP AT git_list INTO gwa_list. 
CLEAR   gwa_objectlinks. 
REFRESH:git_objectlinks. 
gwa_objectlinks-deletevalue = 'X'. 
gwa_objectlinks-objecttype  = 'STPO_DOC'. "Order BOM头用STKO_DOC 
gwa_objectlinks-objectkey   = g_guidx. 
APPEND gwa_objectlinks TO git_objectlinks. 
CALL FUNCTION 'BAPI_DOCUMENT_SAVEOBJECTLINKS' 
EXPORTING 
documenttype    = gwa_list-documenttype 
documentnumber  = gwa_list-documentnumber 
documentpart    = gwa_list-documentpart 
documentversion = gwa_list-documentversion 
IMPORTING 
return          = gwa_return 
TABLES 
objectlinks     = git_objectlinks. 
* Commit or Rollback 
IF gwa_return-type NA 'AE'. 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 
EXPORTING 
wait = 'X'. 
ELSE. 
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. 
ENDIF. 
ENDLOOP.

运行结果,订单BOM行项目上的链接的文档已删除,也就是文档与订单BOM没有链接关系了。

2017-02-16_16-08-14

以上。

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19213.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论