2012-06-04 55 views
0

我正在尋找一個webdynpro abap-code snippet來獲取上傳文件(xstring)到SAP的BDS(業務文檔服務)系統。我正在使用webdynpro的「文件上傳」功能。ABAP Webdynpro文件上傳

我試着插入帶有BDS函數「CREATE_WITH_AS_TABLE」的文件,但只有垃圾存儲在BDS中。大多數文件都是二進制格式或zip文件。

有人可以幫我解決這個小問題嗎?

謝謝

回答

0

您是否試過這個功能?

-BDS_BUSINESSDOCUMENT_CREATEF 

也存儲在BDS這個文件,你必須使用

-CL_BDS_DOCUMENT_SET=>CREATE_WITH_TABLE 

希望它有幫助。

+0

嗨,謝謝你的回答。 – Enrico2012

2

嗨,謝謝你的回答。

我發現了這個小問題的解決方案。我忘了將二進制格式的xsting轉換爲在bds系統中插入文件。不幸的是,許多人都有同樣的問題,但沒有人發佈了一個片段。

重要的代碼是:

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 
EXPORTING 
    buffer  = im_xstr 
IMPORTING 
    output_length = lv_size 
TABLES 
    binary_tab = lt_data. 

我的完整的類:

method WD_SAVE_NEW_FILE. 

DATA: i_files TYPE sbdst_files, 
     wa_files LIKE LINE OF i_files, 
     i_signature TYPE sbdst_signature, 
     wa_signature LIKE LINE OF i_signature. 

* prepare data for FM - COMPONENTS 
    DATA: i_components TYPE sbdst_components, 
     wa_components LIKE LINE OF i_components . 

    wa_components-doc_count = 1. 
    wa_components-comp_count = 1. 
    wa_components-comp_id = IM_FILE_NAME. 
    wa_components-mimetype = IM_FILE_MIME. 
    APPEND wa_components to i_components. 


* set signature to intial = 1 
    wa_signature-doc_count = 1. 
    wa_signature-doc_ver_no = 1. 
    wa_signature-doc_var_id = 1. 
    wa_signature-doc_var_tg = ''. 
    wa_signature-comp_count = 1. 
    wa_signature-prop_name = 'BDS_DOCUMENTCLASS'. 
    wa_signature-prop_value = ''. 
    APPEND wa_signature TO i_signature. 
    CLEAR wa_signature. 

    wa_signature-doc_count = 1. 
    wa_signature-doc_ver_no = 1. 
    wa_signature-doc_var_id = 1. 
    wa_signature-doc_var_tg = ''. 
    wa_signature-comp_count = 1. 
    wa_signature-prop_name = 'DESCRIPTION'. 
    wa_signature-prop_value = im_file_comment. 
    APPEND wa_signature TO i_signature. 
    CLEAR wa_signature. 

DATA lt_data TYPE sbdst_content. 
    DATA lv_size TYPE i. 
    DATA ls_xstring TYPE XSTRINGVAL. 
* Fill ls_xstring 

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 
    EXPORTING 
     buffer  = im_xstr 
    IMPORTING 
     output_length = lv_size 
    TABLES 
     binary_tab = lt_data. 

CALL METHOD me->o_document_set->create_with_table 
     EXPORTING 
     classname  = me->i_classname 
     classtype  = me->i_classtype 
     content   = lt_data 
     components  = i_components 
     CHANGING 
     object_key  = me->i_object_key 
     signature  = i_signature 
     EXCEPTIONS 
     nothing_found = 1 
     parameter_error = 2 
     not_allowed  = 3 
     error_kpro  = 4 
     internal_error = 5 
     not_authorized = 6 
     OTHERS   = 7. 


    CASE sy-subrc. 
     WHEN 0. 
*  
     WHEN 1. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
     WHEN 2. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
     WHEN 3. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
     WHEN 4. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
     WHEN 5. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
     WHEN 6. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
     WHEN OTHERS. 
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 

    ENDCASE. 

*return values 

endmethod. 

我希望的代碼將有助於其它Web Dynpro新手的。

Cheers Heinrich