Upload file in Webdynpro ABAP

3.1k views Asked by At

I'm searching a Webdynpro way to uploaded xstring file into the BDS (Business Document Service), most of the files are in binary or ZIP format. I use the File upload function of Webdynpro.

I've tried to insert the file with the BDS-function CREATE_WITH_AS_TABLE but only rubbish was stored in the BDS.

Can someone help me to solve this little problem?

Thanks

2

There are 2 answers

0
Mtu On

Have you tried this function?

-BDS_BUSINESSDOCUMENT_CREATEF 

Also to store that file in BDS, you have to use

-CL_BDS_DOCUMENT_SET=>CREATE_WITH_TABLE

Hope its helpful.

0
Enrico2012 On

Hi thanks for your answer.

I found the solution of this little problem. I forgot to convert the xsting in binary format to insert the file in the bds system. Unfortunatly many guys have the same problem but nobody posted a snippet.

The important code is:

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

My complete class:

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.

I hope the code will help other Web Dynpro newbie's.

Cheers Heinrich