data: LV_DOC_DATA TYPE SODOCCHGI1,
LV_FOLDER_ID TYPE SOODK,
IT_SOLIX_TAB TYPE SOLIX_TAB,
WA_DOC_INFO TYPE SOFOLENTI1,
LV_OBJTYPE TYPE SWOTOBJID-OBJTYPE,
LV_OBJKEY TYPE SWOTOBJID-OBJKEY,
LV_SOFM TYPE SWOTRTIME-OBJECT,
LV_RETURN TYPE SWOTRETURN,
TB_OBJ TYPE TABLE OF OBJ_RECORD,
LV_OBJECT TYPE OBJ_RECORD.
LV_FOLDER_ID TYPE SOODK,
IT_SOLIX_TAB TYPE SOLIX_TAB,
WA_DOC_INFO TYPE SOFOLENTI1,
LV_OBJTYPE TYPE SWOTOBJID-OBJTYPE,
LV_OBJKEY TYPE SWOTOBJID-OBJKEY,
LV_SOFM TYPE SWOTRTIME-OBJECT,
LV_RETURN TYPE SWOTRETURN,
TB_OBJ TYPE TABLE OF OBJ_RECORD,
LV_OBJECT TYPE OBJ_RECORD.
**If there are no prior attachments then identify the folder id based on sy-user
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
OWNER = SY-UNAME
REGION = 'B'
IMPORTING
FOLDER_ID = LV_FOLDER_ID.
EXPORTING
OWNER = SY-UNAME
REGION = 'B'
IMPORTING
FOLDER_ID = LV_FOLDER_ID.
**Creating First attachment
LV_DOC_DATA-OBJ_NAME = 'Purchase Order details as PDF'.
LV_DOC_DATA-OBJ_DESCR = 'Attachment 1'.
LV_DOC_DATA-OBJ_LANGU = SY-LANGU.
LV_DOC_DATA-SENSITIVTY = 'P'.
**--Here V_BIN_FILESIZE is file size of PDF form stored in IT_SOLIX_TAB
LV_DOC_DATA-DOC_SIZE = V_BIN_FILESIZE.
LV_DOC_DATA-DOC_SIZE = V_BIN_FILESIZE.
**--IT_SOLIX_TAB = PDF of Smart form.
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
FOLDER_ID = LV_FOLDER_ID
DOCUMENT_DATA = LV_DOC_DATA
DOCUMENT_TYPE = 'PDF'
FOLDER_ID = LV_FOLDER_ID
DOCUMENT_DATA = LV_DOC_DATA
DOCUMENT_TYPE = 'PDF'
IMPORTING
DOCUMENT_INFO = WA_DOC_INFO
DOCUMENT_INFO = WA_DOC_INFO
TABLES
CONTENTS_HEX = IT_SOLIX_TAB
CONTENTS_HEX = IT_SOLIX_TAB
EXCEPTIONS
FOLDER_NOT_EXIST = 1
DOCUMENT_TYPE_NOT_EXIST = 2
OPERATION_NO_AUTHORIZATION = 3
PARAMETER_ERROR = 4
X_ERROR = 5
ENQUEUE_ERROR = 6
OTHERS = 7.
FOLDER_NOT_EXIST = 1
DOCUMENT_TYPE_NOT_EXIST = 2
OPERATION_NO_AUTHORIZATION = 3
PARAMETER_ERROR = 4
X_ERROR = 5
ENQUEUE_ERROR = 6
OTHERS = 7.
* Populate object type and object key for create an instance
LV_OBJTYPE = 'SOFM'.
LV_OBJKEY = WA_DOC_INFO-DOC_ID.
LV_OBJTYPE = 'SOFM'.
LV_OBJKEY = WA_DOC_INFO-DOC_ID.
**Creating SOFM object
CALL FUNCTION 'SWO_CREATE'
EXPORTING
OBJTYPE = LV_OBJTYPE
OBJKEY = LV_OBJKEY
IMPORTING
OBJECT = LV_SOFM
RETURN = LV_RETURN
EXCEPTIONS
NO_REMOTE_OBJECTS = 1
OTHERS = 2.
CALL FUNCTION 'SWO_CREATE'
EXPORTING
OBJTYPE = LV_OBJTYPE
OBJKEY = LV_OBJKEY
IMPORTING
OBJECT = LV_SOFM
RETURN = LV_RETURN
EXCEPTIONS
NO_REMOTE_OBJECTS = 1
OTHERS = 2.
* Prepare for attaching the object to container
LV_OBJECT-HEADER = 'OBJH'.
LV_OBJECT-TYPE = 'SWO'.
LV_OBJECT-HANDLE = LV_SOFM.
APPEND LV_OBJECT TO TB_OBJ.
LV_OBJECT-HEADER = 'OBJH'.
LV_OBJECT-TYPE = 'SWO'.
LV_OBJECT-HANDLE = LV_SOFM.
APPEND LV_OBJECT TO TB_OBJ.
CALL METHOD LO_CONTAINER->SET
EXPORTING
NAME = '_ATTACH_OBJECTS' "To attach objects to WOrk item
VALUE = TB_OBJ[].
EXPORTING
NAME = '_ATTACH_OBJECTS' "To attach objects to WOrk item
VALUE = TB_OBJ[].