为质量通知创建 HEX 附件
Create HEX attachment for Quality Notification
我有这段代码可以下载带有导入参数文件 ID 的文件的十六进制内容。我想为通知插入一个新附件,但我不知道如何开始。
METHOD GET_SINGLE_ATTACHMENT_CONTENT.
" VARIABLES
DATA: HEXCONT TYPE TABLE OF SOLIX.
DATA: DOCDATA TYPE SOFOLENTI1.
DATA: LV_LENGTH TYPE I.
" CHECK TO CONTINUE FUNCTION MODULE
IF FILE_ID IS INITIAL. "type = SOFOLENTI1-DOC_ID.
MESSAGE 'Document ID is empty.' TYPE 'E' RAISING DOC_ID_EMPTY.
ENDIF.
" GET BINARY CONTENT OF FILE
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
DOCUMENT_ID = FILE_ID
IMPORTING
DOCUMENT_DATA = DOCDATA
TABLES
CONTENTS_HEX = HEXCONT.
IF SY-SUBRC <> 0.
MESSAGE 'Error downloading file.' TYPE 'E' RAISING FILE_DOWNLOAD_ERROR.
ENDIF.
" CONVERT TO XSTRING
LV_LENGTH = DOCDATA-DOC_SIZE.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = LV_LENGTH
IMPORTING
BUFFER = EV_RETURN "type XSTRING
TABLES
BINARY_TAB = HEXCONT.
IF SY-SUBRC <> 0.
MESSAGE 'Error downloading file.' TYPE 'E' RAISING FILE_DOWNLOAD_ERROR.
ENDIF.
ENDMETHOD.
我读过像'SO_DOCUMENT_INSERT_API1'这样的功能模块,它有文件信息但没有文件内容(最好是十六进制内容)。知道如何开始吗?
是否需要将内容打开为十六进制?
您可能只想读/写一个文件。尝试打开 OPEN DATASET
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapset_dataset.htm
也许你可以用我使用的方法做点什么。检查下面的这个例子。
- 首先将数据解析为十六进制
- 插入带有so_document_insert_api1
的文档
Link 通过 fm binary_relation_create
通知您
" TYPES
TYPES: BEGIN OF TYPE_FILE,
NAME TYPE STRING,
TYPE TYPE STRING,
QMNUM TYPE QMNUM,
USER TYPE CHAR64,
HEXCONT TYPE XSTRING,
END OF TYPE_FILE.
" VARIABLES AND OBJECTS
DATA: LT_RETURN TYPE TABLE OF BAPIRET2.
DATA: LT_HEXCONT TYPE TABLE OF SOLIX.
DATA: LS_DOCDATA TYPE SODOCCHGI1.
DATA: LS_DOCINFO TYPE SOFOLENTI1.
DATA: LS_FILE TYPE TYPE_FILE.
DATA: LV_DOCTYPE TYPE SOODK-OBJTP.
DATA: LV_FOLDER_ID TYPE SOOBJINFI1-OBJECT_ID.
DATA: LV_LENGTH TYPE I.
DATA: OBJ_NOTIF TYPE BORIDENT.
DATA: OBJ_ATTACH TYPE BORIDENT.
DATA: P_QMNUM TYPE QMNUM.
LV_FOLDER_ID = 'FOL40000000000004'.
" CONVERT HEX CONTENT TO BINARY
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LS_FILE-HEXCONT
IMPORTING
OUTPUT_LENGTH = LV_LENGTH
TABLES
BINARY_TAB = LT_HEXCONT.
" SET VALUES
LS_DOCDATA-OBJ_DESCR = LS_FILE-NAME.
LS_DOCDATA-OBJ_LANGU = 'E'.
LS_DOCDATA-OBJ_NAME = 'MESSAGE'.
LS_DOCDATA-DOC_SIZE = XSTRLEN( LS_FILE-HEXCONT ).
LV_DOCTYPE = LS_FILE-TYPE.
UNPACK LS_FILE-QMNUM TO P_QMNUM.
" CREATE ATTACHMENT
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
FOLDER_ID = LV_FOLDER_ID
DOCUMENT_DATA = LS_DOCDATA
DOCUMENT_TYPE = LV_DOCTYPE
IMPORTING
DOCUMENT_INFO = LS_DOCINFO
TABLES
CONTENTS_HEX = LT_HEXCONT.
" CREATE LINK TO OBJECT (Notification)
OBJ_NOTIF-OBJKEY = P_QMNUM.
OBJ_NOTIF-OBJTYPE = 'BUS2038'.
OBJ_ATTACH-OBJKEY = LS_DOCINFO-DOC_ID.
OBJ_ATTACH-OBJTYPE = 'MESSAGE'.
CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
OBJ_ROLEA = OBJ_NOTIF
OBJ_ROLEB = OBJ_ATTACH
RELATIONTYPE = 'ATTA'.
" COMMIT
COMMIT WORK.
我有这段代码可以下载带有导入参数文件 ID 的文件的十六进制内容。我想为通知插入一个新附件,但我不知道如何开始。
METHOD GET_SINGLE_ATTACHMENT_CONTENT.
" VARIABLES
DATA: HEXCONT TYPE TABLE OF SOLIX.
DATA: DOCDATA TYPE SOFOLENTI1.
DATA: LV_LENGTH TYPE I.
" CHECK TO CONTINUE FUNCTION MODULE
IF FILE_ID IS INITIAL. "type = SOFOLENTI1-DOC_ID.
MESSAGE 'Document ID is empty.' TYPE 'E' RAISING DOC_ID_EMPTY.
ENDIF.
" GET BINARY CONTENT OF FILE
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
DOCUMENT_ID = FILE_ID
IMPORTING
DOCUMENT_DATA = DOCDATA
TABLES
CONTENTS_HEX = HEXCONT.
IF SY-SUBRC <> 0.
MESSAGE 'Error downloading file.' TYPE 'E' RAISING FILE_DOWNLOAD_ERROR.
ENDIF.
" CONVERT TO XSTRING
LV_LENGTH = DOCDATA-DOC_SIZE.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = LV_LENGTH
IMPORTING
BUFFER = EV_RETURN "type XSTRING
TABLES
BINARY_TAB = HEXCONT.
IF SY-SUBRC <> 0.
MESSAGE 'Error downloading file.' TYPE 'E' RAISING FILE_DOWNLOAD_ERROR.
ENDIF.
ENDMETHOD.
我读过像'SO_DOCUMENT_INSERT_API1'这样的功能模块,它有文件信息但没有文件内容(最好是十六进制内容)。知道如何开始吗?
是否需要将内容打开为十六进制?
您可能只想读/写一个文件。尝试打开 OPEN DATASET
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapset_dataset.htm
也许你可以用我使用的方法做点什么。检查下面的这个例子。
- 首先将数据解析为十六进制
- 插入带有so_document_insert_api1 的文档
Link 通过 fm binary_relation_create
通知您
" TYPES TYPES: BEGIN OF TYPE_FILE, NAME TYPE STRING, TYPE TYPE STRING, QMNUM TYPE QMNUM, USER TYPE CHAR64, HEXCONT TYPE XSTRING, END OF TYPE_FILE. " VARIABLES AND OBJECTS DATA: LT_RETURN TYPE TABLE OF BAPIRET2. DATA: LT_HEXCONT TYPE TABLE OF SOLIX. DATA: LS_DOCDATA TYPE SODOCCHGI1. DATA: LS_DOCINFO TYPE SOFOLENTI1. DATA: LS_FILE TYPE TYPE_FILE. DATA: LV_DOCTYPE TYPE SOODK-OBJTP. DATA: LV_FOLDER_ID TYPE SOOBJINFI1-OBJECT_ID. DATA: LV_LENGTH TYPE I. DATA: OBJ_NOTIF TYPE BORIDENT. DATA: OBJ_ATTACH TYPE BORIDENT. DATA: P_QMNUM TYPE QMNUM. LV_FOLDER_ID = 'FOL40000000000004'. " CONVERT HEX CONTENT TO BINARY CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING BUFFER = LS_FILE-HEXCONT IMPORTING OUTPUT_LENGTH = LV_LENGTH TABLES BINARY_TAB = LT_HEXCONT. " SET VALUES LS_DOCDATA-OBJ_DESCR = LS_FILE-NAME. LS_DOCDATA-OBJ_LANGU = 'E'. LS_DOCDATA-OBJ_NAME = 'MESSAGE'. LS_DOCDATA-DOC_SIZE = XSTRLEN( LS_FILE-HEXCONT ). LV_DOCTYPE = LS_FILE-TYPE. UNPACK LS_FILE-QMNUM TO P_QMNUM. " CREATE ATTACHMENT CALL FUNCTION 'SO_DOCUMENT_INSERT_API1' EXPORTING FOLDER_ID = LV_FOLDER_ID DOCUMENT_DATA = LS_DOCDATA DOCUMENT_TYPE = LV_DOCTYPE IMPORTING DOCUMENT_INFO = LS_DOCINFO TABLES CONTENTS_HEX = LT_HEXCONT. " CREATE LINK TO OBJECT (Notification) OBJ_NOTIF-OBJKEY = P_QMNUM. OBJ_NOTIF-OBJTYPE = 'BUS2038'. OBJ_ATTACH-OBJKEY = LS_DOCINFO-DOC_ID. OBJ_ATTACH-OBJTYPE = 'MESSAGE'. CALL FUNCTION 'BINARY_RELATION_CREATE' EXPORTING OBJ_ROLEA = OBJ_NOTIF OBJ_ROLEB = OBJ_ATTACH RELATIONTYPE = 'ATTA'. " COMMIT COMMIT WORK.