通过 Web 服务上传 DMS 文档
Uploading a DMS document via a web service
有人可以解释一下如何通过休息服务上传 DMS 文件吗?我像一些指南建议的那样使用 BAPI_DOCUMENT_CREATE2,但我不知道如何在服务器上获取文件。
如果您查看下面的指南 link,他会传递文件名,但不会传递内容。谁能解释一下他是如何获取内容的?
顺便说一句,我不能使用网关,所以我只能使用 SICF 服务。
https://blogs.sap.com/2016/08/22/upload-document-into-dms-server-using-net-weaver-gateway/
"Variables
DATA: LS_DOCDATA TYPE BAPI_DOC_DRAW2.
DATA: LS_OBJECTLINK TYPE BAPI_DOC_DRAD.
DATA: LT_OBJECTLINKS TYPE TABLE OF BAPI_DOC_DRAD.
DATA: LS_OBJECTDESCR TYPE BAPI_DOC_DRAT.
DATA: LT_OBJECTDESCR TYPE TABLE OF BAPI_DOC_DRAT.
DATA: LS_OBJECTFILE TYPE BAPI_DOC_FILES2.
DATA: LT_OBJECTFILES TYPE TABLE OF BAPI_DOC_FILES2.
DATA: LV_DOCTYPE TYPE DOKAR.
DATA: LV_DOCNUMBER TYPE DOKNR.
DATA: LV_DOCPART TYPE DOKTL_D.
DATA: LV_DOCVERSION TYPE DOKVR.
" SET VALUES
LS_DOCDATA-DOCUMENTTYPE = 'DRW'.
LS_DOCDATA-DOCUMENTVERSION = '00'.
LS_DOCDATA-DOCUMENTPART = '000'.
LS_DOCDATA-LABORATORY = '001'.
LS_OBJECTDESCR-DESCRIPTION = 'test dms doc'.
LS_OBJECTDESCR-LANGUAGE = 'E'.
LS_OBJECTDESCR-LANGUAGE_ISO = 'EN'.
APPEND LS_OBJECTDESCR TO LT_OBJECTDESCR.
LS_OBJECTFILE-ORIGINALTYPE = '1'.
LS_OBJECTFILE-SOURCEDATACARRIER = 'SAP-SYSTEM'.
LS_OBJECTFILE-CREATED_BY = SY-UNAME
LS_OBJECTFILE-DOCFILE = 'test'.
LS_OBJECTFILE-WSAPPLICATION = 'JPG'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
LS_OBJECTLINK-OBJECTTYPE = 'EQUI'.
LS_OBJECTLINK-OBJECTKEY = '000000000210100004'.
APPEND LS_OBJECTLINK TO LT_OBJECTLINKS.
" CREATE ATTACHMENT
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
DOCUMENTDATA = LS_DOCDATA
HOSTNAME = SY-HOST
PF_FTP_DEST = 'SAPFTPA'
PF_HTTP_DEST = 'SAPHTTP'
IMPORTING
DOCUMENTTYPE = LV_DOCTYPE
DOCUMENTNUMBER = LV_DOCNUMBER
DOCUMENTPART = LV_DOCPART
DOCUMENTVERSION = LV_DOCVERSION
RETURN = LT_RETURN
TABLES
DOCUMENTDESCRIPTIONS = LT_OBJECTDESCR
OBJECTLINKS = LT_OBJECTLINKS
DOCUMENTFILES = LT_OBJECTFILES.
IF SY-SUBRC <> 0.
MESSAGE 'Error uploading attachment' TYPE 'E'.
ENDIF.
" COMMIT
COMMIT WORK.
您应该提供文件路径和存储类别。这应该可以解决问题。
LS_OBJECTFILE-ORIGINALTYPE = '001'. "**
LS_OBJECTFILE-storagecategory = 'DMS_C1_ST'.. "**
LS_OBJECTFILE-CREATED_BY = SY-UNAME
LS_OBJECTFILE-DOCFILE = IV_SLUG. "path that comes from the OData service.
LS_OBJECTFILE-WSAPPLICATION = 'JPG'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
我居然用这段代码解决了。我在这里找到它:Solution
DATA LV_OUTPUT_LENGTH TYPE I.
DATA LS_SOLIX TYPE SOLIX-LINE.
DATA LT_SOLIX_TAB TYPE TABLE OF SOLIX-LINE.
DATA LV_FILENAME TYPE STRING.
DATA LV_DOCNUM TYPE DOKNR.
CONCATENATE '/usr/sap/' SY-SYSID SY-UNAME SY-DATUM INTO LV_FILENAME.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LV_FILESOURCE " this is the XSTRING of the file u want to upload
IMPORTING
OUTPUT_LENGTH = LV_OUTPUT_LENGTH
TABLES
BINARY_TAB = LT_SOLIX_TAB.
IF NOT LT_SOLIX_TAB IS INITIAL.
OPEN DATASET LV_FILENAME FOR OUTPUT IN BINARY MODE.
LOOP AT LT_SOLIX_TAB INTO LS_SOLIX.
TRANSFER LS_SOLIX TO LV_FILENAME.
ENDLOOP.
CLOSE DATASET LV_FILENAME.
ENDIF.
所以我将我之前的代码与上面的代码片段结合起来,它似乎有效。
"Variables
DATA: LS_DOCDATA TYPE BAPI_DOC_DRAW2.
DATA: LS_OBJECTLINK TYPE BAPI_DOC_DRAD.
DATA: LT_OBJECTLINKS TYPE TABLE OF BAPI_DOC_DRAD.
DATA: LS_OBJECTDESCR TYPE BAPI_DOC_DRAT.
DATA: LT_OBJECTDESCR TYPE TABLE OF BAPI_DOC_DRAT.
DATA: LS_OBJECTFILE TYPE BAPI_DOC_FILES2.
DATA: LT_OBJECTFILES TYPE TABLE OF BAPI_DOC_FILES2.
DATA: LV_DOCTYPE TYPE DOKAR.
DATA: LV_DOCNUMBER TYPE DOKNR.
DATA: LV_DOCPART TYPE DOKTL_D.
DATA: LV_DOCVERSION TYPE DOKVR.
" SET VALUES
LS_DOCDATA-DOCUMENTTYPE = 'DRW'.
LS_DOCDATA-DOCUMENTVERSION = '00'.
LS_DOCDATA-DOCUMENTPART = '000'.
LS_DOCDATA-LABORATORY = '001'.
LS_OBJECTDESCR-DESCRIPTION = 'test dms doc'.
LS_OBJECTDESCR-LANGUAGE = 'E'.
LS_OBJECTDESCR-LANGUAGE_ISO = 'EN'.
APPEND LS_OBJECTDESCR TO LT_OBJECTDESCR.
LS_OBJECTFILE-ORIGINALTYPE = '1'.
LS_OBJECTFILE-SOURCEDATACARRIER = 'SAP-SYSTEM'.
LS_OBJECTFILE-CREATED_BY = SY-UNAME.
LS_OBJECTFILE-DOCFILE = LV_FILENAME.
LS_OBJECTFILE-WSAPPLICATION = 'TXT'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
LS_OBJECTLINK-OBJECTTYPE = 'EQUI'.
LS_OBJECTLINK-OBJECTKEY = '000000000210100004'.
APPEND LS_OBJECTLINK TO LT_OBJECTLINKS.
" CREATE ATTACHMENT
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
DOCUMENTDATA = LS_DOCDATA
PF_FTP_DEST = 'SAPFTPA'
PF_HTTP_DEST = 'SAPHTTP'
IMPORTING
DOCUMENTTYPE = LV_DOCTYPE
DOCUMENTNUMBER = LV_DOCNUMBER
DOCUMENTPART = LV_DOCPART
DOCUMENTVERSION = LV_DOCVERSION
RETURN = LT_RETURN
TABLES
DOCUMENTDESCRIPTIONS = LT_OBJECTDESCR
OBJECTLINKS = LT_OBJECTLINKS
DOCUMENTFILES = LT_OBJECTFILES.
IF SY-SUBRC <> 0.
MESSAGE 'Error uploading attachment' TYPE 'E'.
ENDIF.
" COMMIT
COMMIT WORK.
有人可以解释一下如何通过休息服务上传 DMS 文件吗?我像一些指南建议的那样使用 BAPI_DOCUMENT_CREATE2,但我不知道如何在服务器上获取文件。
如果您查看下面的指南 link,他会传递文件名,但不会传递内容。谁能解释一下他是如何获取内容的?
顺便说一句,我不能使用网关,所以我只能使用 SICF 服务。
https://blogs.sap.com/2016/08/22/upload-document-into-dms-server-using-net-weaver-gateway/
"Variables
DATA: LS_DOCDATA TYPE BAPI_DOC_DRAW2.
DATA: LS_OBJECTLINK TYPE BAPI_DOC_DRAD.
DATA: LT_OBJECTLINKS TYPE TABLE OF BAPI_DOC_DRAD.
DATA: LS_OBJECTDESCR TYPE BAPI_DOC_DRAT.
DATA: LT_OBJECTDESCR TYPE TABLE OF BAPI_DOC_DRAT.
DATA: LS_OBJECTFILE TYPE BAPI_DOC_FILES2.
DATA: LT_OBJECTFILES TYPE TABLE OF BAPI_DOC_FILES2.
DATA: LV_DOCTYPE TYPE DOKAR.
DATA: LV_DOCNUMBER TYPE DOKNR.
DATA: LV_DOCPART TYPE DOKTL_D.
DATA: LV_DOCVERSION TYPE DOKVR.
" SET VALUES
LS_DOCDATA-DOCUMENTTYPE = 'DRW'.
LS_DOCDATA-DOCUMENTVERSION = '00'.
LS_DOCDATA-DOCUMENTPART = '000'.
LS_DOCDATA-LABORATORY = '001'.
LS_OBJECTDESCR-DESCRIPTION = 'test dms doc'.
LS_OBJECTDESCR-LANGUAGE = 'E'.
LS_OBJECTDESCR-LANGUAGE_ISO = 'EN'.
APPEND LS_OBJECTDESCR TO LT_OBJECTDESCR.
LS_OBJECTFILE-ORIGINALTYPE = '1'.
LS_OBJECTFILE-SOURCEDATACARRIER = 'SAP-SYSTEM'.
LS_OBJECTFILE-CREATED_BY = SY-UNAME
LS_OBJECTFILE-DOCFILE = 'test'.
LS_OBJECTFILE-WSAPPLICATION = 'JPG'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
LS_OBJECTLINK-OBJECTTYPE = 'EQUI'.
LS_OBJECTLINK-OBJECTKEY = '000000000210100004'.
APPEND LS_OBJECTLINK TO LT_OBJECTLINKS.
" CREATE ATTACHMENT
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
DOCUMENTDATA = LS_DOCDATA
HOSTNAME = SY-HOST
PF_FTP_DEST = 'SAPFTPA'
PF_HTTP_DEST = 'SAPHTTP'
IMPORTING
DOCUMENTTYPE = LV_DOCTYPE
DOCUMENTNUMBER = LV_DOCNUMBER
DOCUMENTPART = LV_DOCPART
DOCUMENTVERSION = LV_DOCVERSION
RETURN = LT_RETURN
TABLES
DOCUMENTDESCRIPTIONS = LT_OBJECTDESCR
OBJECTLINKS = LT_OBJECTLINKS
DOCUMENTFILES = LT_OBJECTFILES.
IF SY-SUBRC <> 0.
MESSAGE 'Error uploading attachment' TYPE 'E'.
ENDIF.
" COMMIT
COMMIT WORK.
您应该提供文件路径和存储类别。这应该可以解决问题。
LS_OBJECTFILE-ORIGINALTYPE = '001'. "**
LS_OBJECTFILE-storagecategory = 'DMS_C1_ST'.. "**
LS_OBJECTFILE-CREATED_BY = SY-UNAME
LS_OBJECTFILE-DOCFILE = IV_SLUG. "path that comes from the OData service.
LS_OBJECTFILE-WSAPPLICATION = 'JPG'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
我居然用这段代码解决了。我在这里找到它:Solution
DATA LV_OUTPUT_LENGTH TYPE I.
DATA LS_SOLIX TYPE SOLIX-LINE.
DATA LT_SOLIX_TAB TYPE TABLE OF SOLIX-LINE.
DATA LV_FILENAME TYPE STRING.
DATA LV_DOCNUM TYPE DOKNR.
CONCATENATE '/usr/sap/' SY-SYSID SY-UNAME SY-DATUM INTO LV_FILENAME.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LV_FILESOURCE " this is the XSTRING of the file u want to upload
IMPORTING
OUTPUT_LENGTH = LV_OUTPUT_LENGTH
TABLES
BINARY_TAB = LT_SOLIX_TAB.
IF NOT LT_SOLIX_TAB IS INITIAL.
OPEN DATASET LV_FILENAME FOR OUTPUT IN BINARY MODE.
LOOP AT LT_SOLIX_TAB INTO LS_SOLIX.
TRANSFER LS_SOLIX TO LV_FILENAME.
ENDLOOP.
CLOSE DATASET LV_FILENAME.
ENDIF.
所以我将我之前的代码与上面的代码片段结合起来,它似乎有效。
"Variables
DATA: LS_DOCDATA TYPE BAPI_DOC_DRAW2.
DATA: LS_OBJECTLINK TYPE BAPI_DOC_DRAD.
DATA: LT_OBJECTLINKS TYPE TABLE OF BAPI_DOC_DRAD.
DATA: LS_OBJECTDESCR TYPE BAPI_DOC_DRAT.
DATA: LT_OBJECTDESCR TYPE TABLE OF BAPI_DOC_DRAT.
DATA: LS_OBJECTFILE TYPE BAPI_DOC_FILES2.
DATA: LT_OBJECTFILES TYPE TABLE OF BAPI_DOC_FILES2.
DATA: LV_DOCTYPE TYPE DOKAR.
DATA: LV_DOCNUMBER TYPE DOKNR.
DATA: LV_DOCPART TYPE DOKTL_D.
DATA: LV_DOCVERSION TYPE DOKVR.
" SET VALUES
LS_DOCDATA-DOCUMENTTYPE = 'DRW'.
LS_DOCDATA-DOCUMENTVERSION = '00'.
LS_DOCDATA-DOCUMENTPART = '000'.
LS_DOCDATA-LABORATORY = '001'.
LS_OBJECTDESCR-DESCRIPTION = 'test dms doc'.
LS_OBJECTDESCR-LANGUAGE = 'E'.
LS_OBJECTDESCR-LANGUAGE_ISO = 'EN'.
APPEND LS_OBJECTDESCR TO LT_OBJECTDESCR.
LS_OBJECTFILE-ORIGINALTYPE = '1'.
LS_OBJECTFILE-SOURCEDATACARRIER = 'SAP-SYSTEM'.
LS_OBJECTFILE-CREATED_BY = SY-UNAME.
LS_OBJECTFILE-DOCFILE = LV_FILENAME.
LS_OBJECTFILE-WSAPPLICATION = 'TXT'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
LS_OBJECTLINK-OBJECTTYPE = 'EQUI'.
LS_OBJECTLINK-OBJECTKEY = '000000000210100004'.
APPEND LS_OBJECTLINK TO LT_OBJECTLINKS.
" CREATE ATTACHMENT
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
DOCUMENTDATA = LS_DOCDATA
PF_FTP_DEST = 'SAPFTPA'
PF_HTTP_DEST = 'SAPHTTP'
IMPORTING
DOCUMENTTYPE = LV_DOCTYPE
DOCUMENTNUMBER = LV_DOCNUMBER
DOCUMENTPART = LV_DOCPART
DOCUMENTVERSION = LV_DOCVERSION
RETURN = LT_RETURN
TABLES
DOCUMENTDESCRIPTIONS = LT_OBJECTDESCR
OBJECTLINKS = LT_OBJECTLINKS
DOCUMENTFILES = LT_OBJECTFILES.
IF SY-SUBRC <> 0.
MESSAGE 'Error uploading attachment' TYPE 'E'.
ENDIF.
" COMMIT
COMMIT WORK.