有人可以解释如何通过休息服务上传DMS文件。我正在使用BAPI_DOCUMENT_CREATE2,就像一些指南建议的那样,但我没有看到如何在服务器上获取该文件。
如果您查看我在下面链接的指南,他会传递文件名,但不会传递内容。任何人都可以解释一下他是如何获得内容的吗?
顺便说一下,我无法使用网关所以我只是使用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.
答案 0 :(得分:0)
您应该提供文件路径和存储类别。这应该可以解决问题。
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.
答案 1 :(得分:0)
我实际上用这段代码来解决它。我在这里找到了它:CSRF in token based authentication
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.