on 08-09-2011 12:49 PM
Hi Experts!!
We have a requirement to attach the Service Object attachments to Workitem. After searching in SDN, I have almost implemented everything. But when executed, the attachment is not working. It's throwing an error as 'The file has been damaged'. PFB my code:
FUNCTION ztest_service_atta.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IV_WORKITEMID) TYPE SWW_WIID OPTIONAL
*" REFERENCE(IV_PERNR) TYPE PERSNO
*" REFERENCE(IV_REINR) TYPE REINR
*" EXPORTING
*" REFERENCE(ES_ATT_ID) TYPE SWR_ATT_ID
*" EXCEPTIONS
*" ATTACH_FAILED
*"----------------------------------------------------------------------
DATA: gs_att_header TYPE swr_att_header.
DATA: ls_lpor TYPE sibflporb,
lt_lpor LIKE TABLE OF ls_lpor,
ls_option TYPE obl_s_relt,
lt_option TYPE obl_t_relt,
ls_rol_op TYPE obl_s_rolt,
lt_rol_op TYPE obl_t_rolt,
ls_links TYPE obl_s_link,
lt_links TYPE obl_t_link,
ls_folder TYPE soodk,
ls_object TYPE soodk,
ls_obj_hd TYPE sood2,
lt_object_content_l TYPE TABLE OF solisti1,
ls_object_content_l TYPE solisti1,
lt_obj_cont TYPE TABLE OF soli.
* Work areas
DATA: lwa_doc_data LIKE sodocchgi1,
lwa_document_data LIKE sofolenti1,
lv_document_id TYPE sofolenti1-doc_id,
lwa_links LIKE LINE OF lt_links,
lwa_object TYPE borident,
ev_binfile TYPE xstring.
FIELD-SYMBOLS <p> TYPE x.
ls_lpor-instid = '000011110000000123'.
ls_lpor-typeid = 'BUS2089'.
ls_lpor-catid = 'BO'.
APPEND ls_lpor TO lt_lpor.
ls_option-sign = 'I'.
ls_option-option = 'EQ'.
ls_option-low = 'ATTA'.
APPEND ls_option TO lt_option.
ls_rol_op-sign = 'I'.
ls_rol_op-option = 'EQ'.
ls_rol_op-low = 'GOSAPPLOBJ'.
APPEND ls_rol_op TO lt_rol_op.
*
CALL METHOD cl_binary_relation=>read_links
EXPORTING
is_object = ls_lpor
it_relation_options = lt_option
it_role_options = lt_rol_op
IMPORTING
et_links = lt_links.
* Process the attachment list
LOOP AT lt_links INTO ls_links.
lv_document_id = ls_links-instid_b.
* Read the data
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_document_id
IMPORTING
document_data = lwa_document_data
TABLES
object_content = lt_object_content_l
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
ENDLOOP.
LOOP AT lt_object_content_l INTO ls_object_content_l.
ASSIGN ls_object_content_l TO <p> CASTING.
CONCATENATE ev_binfile <p> INTO ev_binfile IN BYTE MODE.
ENDLOOP.
IF ev_binfile IS NOT INITIAL AND iv_workitemid IS NOT INITIAL.
gs_att_header-file_type = 'B'.
gs_att_header-file_extension = 'PDF'.
gs_att_header-language = 'EN'.
gs_att_header-file_name = 'Scanned Atta.PDF'.
CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
EXPORTING
workitem_id = iv_workitemid
att_header = gs_att_header
att_bin = ev_binfile
do_commit = 'X'
IMPORTING
att_id = es_att_id.
IF es_att_id IS INITIAL.
RAISE attach_failed.
ENDIF.
ENDIF.
ENDFUNCTION.
Can somebody please tell me if I went somewhere wrong. What I feel is, it's because of the PDF file being 255 chars. As I have got the PDF file but not OTF, how can I convert that ot be of 132 chars. Whatever, is the problem due to this reason only?
Please help me out. Your help is really appreciable.
Solved. Instead of converting object_content, I got contents_hex also and converted that as below:
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_document_id
IMPORTING
document_data = lwa_document_data
TABLES
object_content = lt_object_content_l
contents_hex = lt_hex_cont
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
LOOP AT lt_hex_cont INTO ls_hex_cont.
ASSIGN ls_hex_cont TO <p> CASTING.
CONCATENATE ev_binfile <p> INTO ev_binfile IN BYTE MODE.
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can somebody please help me out?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.