Webdynpro上传附件 并关联

DATA lo_nd_upload TYPE REF TO if_wd_context_node.


  DATA lo_el_upload TYPE REF TO if_wd_context_element.
  DATA ls_upload TYPE wd_this->element_upload.


* navigate from <CONTEXT> to <UPLOAD> via lead selection
  lo_nd_upload = wd_context->get_child_node( name = wd_this->wdctx_upload ).


* @TODO handle non existant child
* IF lo_nd_upload IS INITIAL.
* ENDIF.


* get element via lead selection
  lo_el_upload = lo_nd_upload->get_element( ).
* @TODO handle not set lead selection
  IF lo_el_upload IS INITIAL.
  ENDIF.


* get all declared attributes
  lo_el_upload->get_static_attributes(
    IMPORTING
      static_attributes = ls_upload ).


  DATA:
         lv_index TYPE i,
         lv_name TYPE string,
         lt_signature TYPE TABLE OF bapisignat,
         ls_signature TYPE bapisignat,
         lt_components TYPE TABLE OF bapicompon,
         ls_component TYPE bapicompon,
         ls_content TYPE bapiconten,
         lt_content TYPE TABLE OF bapiconten,
         lv_type TYPE string,
         lv_key TYPE bapibds01-objkey,
         lc_sign      TYPE char1  VALUE '>',
               lc_class     TYPE char25 VALUE 'BDS_DOCUMENTCLASS',
               lc_contrep   TYPE char25 VALUE 'BDS_CONTREP',
               lc_type      TYPE char25 VALUE 'BDS_DOCUMENTTYPE',
               lc_des       TYPE char25 VALUE 'DESCRIPTION',
               lc_lan       TYPE char25 VALUE  'LANGUAGE',
               lc_01        TYPE char2  VALUE '01',
               lc_classname TYPE bapibds01-classname VALUE 'BUS1065',
               lc_classtype TYPE bapibds01-classtype VALUE 'BO'.


  DATA lt_str TYPE TABLE OF string .
  DATA ls_str TYPE string.




  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer          = ls_upload-file_content
*     APPEND_TO_TABLE = ' '
    IMPORTING
      output_length   = lv_index
    TABLES
      binary_tab      = lt_content.
*File information
  ls_component-doc_count  = 1.
  ls_component-comp_count = 1.
  ls_component-mimetype   = ls_upload-file_type.
  ls_component-comp_id    = ls_upload-file_name. "File name
  ls_component-comp_size  = lv_index.
  APPEND ls_component TO lt_components.






  SPLIT ls_upload-file_name AT '.' INTO lv_name lv_type.
  CLEAR:lt_str.
  SPLIT lv_name AT '\' INTO TABLE lt_str.
  READ TABLE lt_str INTO lv_name INDEX lines( lt_str ).






  TRANSLATE lv_type TO UPPER CASE.
  ls_signature-doc_count  = 1.
  ls_signature-prop_name  = lc_class.
  ls_signature-prop_value = lv_type.
  APPEND ls_signature TO lt_signature.




  ls_signature-prop_name  = lc_contrep.
  CLEAR ls_signature-prop_value.
  APPEND ls_signature TO lt_signature.




  ls_signature-prop_name  = lc_type.
  CLEAR ls_signature-prop_value.
  APPEND ls_signature TO lt_signature.


*    CONCATENATE ls_download-filetype ls_download-filename INTO lv_des
*     SEPARATED BY lc_sign.
  ls_signature-prop_name  = lc_des.
  ls_signature-prop_value = lv_name .
  APPEND ls_signature TO lt_signature.




  ls_signature-prop_name  = lc_lan.
  ls_signature-prop_value = sy-langu.
  APPEND ls_signature TO lt_signature.


  lv_key = '00000003'.
*Create alttachment
  CALL FUNCTION 'BDS_BUSINESSDOCUMENT_CREA_TAB'
    EXPORTING
*     logical_system        = lv_los
      classname            = lc_classname
      classtype            = lc_classtype
*   CLIENT                = SY-MANDT
     object_key            = lv_key
*       binary_flag           = 'X'
* IMPORTING
*   OBJECT_KEY            =
    TABLES
      signature             = lt_signature
      components            = lt_components
      content               = lt_content
*   ASCII_CONTENT         =
   EXCEPTIONS
     nothing_found         = 1
     parameter_error       = 2
     not_allowed           = 3
     error_kpro            = 4
     internal_error        = 5
     not_authorized        = 6
     OTHERS                = 7
            .

你可能感兴趣的:(Webdynpro上传附件 并关联)