一,创建凭证的bapi:
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING: documentdata = ls_doc
IMPORTING: documenttype = lf_doctype
documentnumber = lf_docnumber
documentpart = lf_docpart
documentversion = lf_docversion
return = ls_return
TABLES: documentdescriptions = lt_drat
characteristicvalues = lt_class
classallocations = lt_class1
documentfiles = lt_files.
IF ls_return-type CA 'EA'.
ROLLBACK WORK.
ELSE.
COMMIT WORK. ENDIF.
如果是系统自动给号的话 要把 documentdata 中 文档号设置成 *
如:ls_doc-documentnumber
在 documentdescriptions 中设置文档描述
在 characteristicvalues 中设置分类特性
在 classallocations 中设置分类
在 documentfiles 中设置元件
2,修改文档的bapi
CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'
EXPORTING
documenttype = 'WOR'
documentnumber = it_tab-documentnumber1
documentpart = '000'
documentversion = it_tab-documentversion
documentdata = ls_doc
documentdatax = ls_docx
IMPORTING
return = ls_return
TABLES
characteristicvalues = lt_class
classallocations = lt_class1. documentfiles = lt_files.
objectlinks = gt_drad.
在 documentdata,documentdatax 中定义 基础属性的修改
在documentdata 中 必须设定 documenttype documentnumber documentversion documentpart
documentdatax 中把需要修改的属性设置为 X。
在 documentfiles 中设定 元件
元件的正常操作方式为新增。将 deletevalue 的值设为 X 则删除该元件。
没有替换原件的功能,如果要替换元件,请先删除 元件,在新增。
在 characteristicvalues classallocations 中设定分类特性
分类特性的正常操作方式为新增。将deletevalue 的值设为 X 则删除该分类特性(需要注意的是,要把 charvalue 的值也要正确维护,才能删除成功)。
没有替换分类特性的功能,如果要替换分类特性,请先删除分类特性,再新增。
在 objectlinks 中定义连接对象
3, 删除文档 的bapi
BAPI_DOCUMENT_DELETE
4, 查看文档的bapi
CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
EXPORTING
documenttype = gs_draw-dokar
documentnumber = gs_draw-doknr
documentpart = gs_draw-doktl
documentversion = gs_draw-dokvr
getactivefiles = 'X'
getdocdescriptions = 'X'
getdocfiles = 'X'
IMPORTING
return = return
TABLES
documentdescriptions = docdesc
documentfiles = docfiles.
5, 检出元件 的bapi
CALL FUNCTION 'BAPI_DOCUMENT_CHECKOUTVIEW2'
EXPORTING
documenttype = gs_draw-dokar
documentnumber = gs_draw-doknr
documentpart = gs_draw-doktl
documentversion = gs_draw-dokvr
documentfile = docfile1
getstructure = '1'
getcomponents = 'X'
getheader = 'X'
IMPORTING
return = return2
TABLES
documentstructure = docstrc
documentfiles = docfile
components = doccomp.
检出之前,我们通过 BAPI_DOCUMENT_GETDETAIL2先得到文档的元件列表到 documentfiles
然后在循环documentfiles的时候 逐一检出。
docfile1-docfile 是元件的原来路径
docfile-docfile 是元件的新路径
元件会根据同一个规则重新命名,一个执行作业内的程序名的编号都是从 1 开始 连续。并且会替换掉原有的重名文件。
6,文档操作的bapi 很多。通过 se37 进去,输入 bapi_document* 搜索,可以搜出很多文档操作的相关bapi。使用这些bapi可以对文档做几乎所有的操作:
创建文档,修改文档,删除文档,读取文档,检出元件,检入元件,文档的搜索等等
bapi 列表如下:
BAPI_DOCUMENT_CHANGE Change Document
BAPI_DOCUMENT_CHANGE2 Change Document
BAPI_DOCUMENT_CHECKIN Check in document
BAPI_DOCUMENT_CHECKIN2 Check in document
BAPI_DOCUMENT_CHECKIN_REPLACE Check in document (overwrite originals)
BAPI_DOCUMENT_CHECKIN_REPLACE2 Check in document (overwrite originals)
BAPI_DOCUMENT_CHECKOUTCANCEL Cancel Check Out
BAPI_DOCUMENT_CHECKOUTCANCEL2 Cancel Check Out
BAPI_DOCUMENT_CHECKOUTMODIFY Check out document for processing
BAPI_DOCUMENT_CHECKOUTMODIFY2 Check out document for processing
BAPI_DOCUMENT_CHECKOUTSET Set document to checked out
BAPI_DOCUMENT_CHECKOUTSET2 Set document to checked out
BAPI_DOCUMENT_CHECKOUTVIEW Check out document for display
BAPI_DOCUMENT_CHECKOUTVIEW2 Check out document for display
BAPI_DOCUMENT_CHECKOUTVIEWX Check out document for display
BAPI_DOCUMENT_CREATE Create Document
BAPI_DOCUMENT_CREATE2 Create Document
BAPI_DOCUMENT_CREATEFROMSOURCE Create Document with Template Source
BAPI_DOCUMENT_CREATEFROMSRC2 Create Document with Template Source
BAPI_DOCUMENT_CREATENEWVERSION Create new document version
BAPI_DOCUMENT_CREATENEWVRS2 Create new document version
BAPI_DOCUMENT_DELETE Delete document or set deletion indicator
BAPI_DOCUMENT_DELETE_DIRECT Delete Document or Set Deletion Indicator
BAPI_DOCUMENT_DEQUEUE Unlock document
BAPI_DOCUMENT_ENQUEUE Lock document
BAPI_DOCUMENT_EXISTENCECHECK Document Exists
BAPI_DOCUMENT_GETACTVERSION Determine Valid Version of a Document
BAPI_DOCUMENT_GETADMIN Read Management Data for Document
BAPI_DOCUMENT_GETAPPLICATION Determine Data for an Application
BAPI_DOCUMENT_GETDCDETAIL Determine Detail Data of Data Carrier
BAPI_DOCUMENT_GETDCLIST Determine List of Data Carriers
BAPI_DOCUMENT_GETDCLIST2 Determine List of Data Carriers
BAPI_DOCUMENT_GETDETAIL Determine Detail Data for a Document
BAPI_DOCUMENT_GETDETAIL2 Determine Detail Data for a Document
BAPI_DOCUMENT_GETDOCTYPEDETAIL Determine Data for a Document Type
BAPI_DOCUMENT_GETFRONTENDTYPE Determine Frontend Type for Computer
BAPI_DOCUMENT_GETLATEST Determines the Lastest Versions of a Document Structure
BAPI_DOCUMENT_GETLATEST2 Reads Document Structure with New Versions and Document Dat
BAPI_DOCUMENT_GETLIST Find Document
BAPI_DOCUMENT_GETLIST2 Extended Document Search
BAPI_DOCUMENT_GETLIST_OLD Find Documents
BAPI_DOCUMENT_GETMULTIDETAIL Mass Read Function Module for Documents
BAPI_DOCUMENT_GETOBJECTDOCS Determine Documents for an Object
BAPI_DOCUMENT_GETOBJECTLINKS Read Object Links
BAPI_DOCUMENT_GETSTATUS Read Document Status
BAPI_DOCUMENT_GETSTATUSLIST Determine Status List for a Document Type
BAPI_DOCUMENT_GETSTRUCTURE Determine document structure
BAPI_DOCUMENT_GETTEXTS Read Long Texts for Documents
BAPI_DOCUMENT_INIT Set general data for BAPIs
BAPI_DOCUMENT_LOAD Load Document Data (Data Transfer Workbench
BAPI_DOCUMENT_SAVEOBJECTLINKS Save object link
BAPI_DOCUMENT_SETCOMMITMODE
BAPI_DOCUMENT_SETFRONTENDTYPE Set frontend type for computer
BAPI_DOCUMENT_SETSTATUS Set Document Status
BAPI_DOCUMENT_WHEREUSED Where-Used List for Documents
7,如果要修改的文档的状态为 发布状态的话,首先将文档的状态改为可修改的状态在进行修改,然后再改为发布状态。