webdynpro GOS BDS 文档/附件 上传下载处理

对于webdynpro 的GOS, 不可以做
但是可以用BDS实现部分



SAP BDS (Business Document Service) for storage of documents and attachments in SAP ECC
In some business scenarios there is need to attach/store external file to standard object like Material/ Purchase Order or to custom application like Loan Application; in such case we can use SAP standard methodology like SAP Office, BDS (Business Document Service), DMS (Document Management Service), GOS (Generic Document Services) to store actual files in system with logical relation with an object or Application so we can retrieve the same.


All these methodologies provide basic functionality which includes:


Attachment Creation for Object
This functionality will create logical relationship between attached object and actual SAP business object
Retrieving stored attachment and Display
BDS (Business Document Service)


Maintain Assignment of Business Objects to Document Classes – Tcode – SBDSV
As basic configuration, you need to create class (for Business Object) for your application e.g. Student Admission Application.
Maintain Storage Categories – Tcode – SBDSV2
Once you are done with creation of BDS Application Class, assign required document type such as BDS_ATTACH –Attachment, BDS_HTMLT- HTML template, BDS_IMAGE –Screen, BDS_SHEET          Table template, BDS_SLIDE Presentation, BDS_TEXT Text to BDS Application class name. You can create new Document class and document Type through SPRO configuration if needed.
BDN (Business Document Navigator)
BDN (Business Document Navigator) is a tool provided by SAP for mediating Documents.


Basic functions provided by BDN includes:


Store Document
Display Detail information about stored document
Display Documents
Display Version, Keyword for documents
Copy, Edit, Delete Documents
Store WWW address
These are some functionality examples provided by BDN.


These documents are stored in SAP Database Table (default for existing classes defined by SAP), but we can change this storage location, like if we want to store these documents in any external server. To achieve this we can create Content Repository, Content Category and assign it to Physical Document class.


Standard Function modules and BAPI’s are available to do all these functionality through ABAP code so we can use BDS to store documents for external applications. Below are some useful Function modules for BDS.


BDS_BUSINESSDOCUMENT_CREATEF


BDS_ALL_CONNECTIONS_GET


BDS_BUSINESSDOCUMENT_GET_INFO


BDS_BUSINESSDOCUMENT_GET_TAB


Class – CL_BDS_DOCUMENT_SET








1.1 Code for getting attachment from BDS and GOS


  DATA lt_signature        TYPE STANDARD TABLE OF bapisignat.
  DATA lwa_signature       TYPE bapisignat.
  DATA lt_comp             TYPE STANDARD TABLE OF bapicompo2.
  DATA ls_comp             TYPE bapicompo2.
  DATA lwa_attachment_list TYPE ty_s_attachment_list.
  DATA lt_con              TYPE TABLE OF bdn_con.
  DATA ls_con              TYPE bdn_con.
  DATA lt_sig              TYPE TABLE OF bapisignat.
  DATA ls_sig              TYPE bapisignat.
  DATA lt_content          TYPE TABLE OF sdokcntbin.




  DATA: l_sdok_objid TYPE sdokobject,
        l_lines TYPE i,
        l_len TYPE i,
        l_count TYPE sy-index,
        content TYPE xstring.


  DATA: l_ess_emp TYPE ess_emp.
  DATA: ls_attachment  TYPE hap_s_attachments.
  DATA: li_document    TYPE REF TO cl_bsp_hap_document_if.
  DATA: lv_fcont_txt   TYPE string.
  DATA: lv_fcont_hex   TYPE xstring.
  DATA: lv_mime_type   TYPE string.
  CALL FUNCTION 'BDS_ALL_CONNECTIONS_GET'
    EXPORTING
      classname              = classname "'FIPP' " 如果是一个business object, 这里规定是哪个
      classtype              = classtype "'BO'   "这里BO是指它是一个business object
      objkey                 = object_key      " 这里是CONCATENATE 那个BO所有的keyfields
      all                    = ' '
      no_gos_docs            = ' '
*   CHECK_STATE            = ' '
   IMPORTING
     count                  = l_count
   TABLES
     signature              = lt_sig
     all_connections        = lt_con
  EXCEPTIONS
    no_objects_found       = 1
    error_kpro             = 2
    internal_error         = 3
    not_authorized         = 4
    OTHERS                 = 5
             .


  LOOP AT lt_con INTO ls_con.


*-  file title
    lwa_attachment_list-title = ls_con-descript.


*-  Created by
    lwa_attachment_list-userid  = ls_con-crea_user.


    CLEAR l_ess_emp.
    CALL FUNCTION 'Z_GERCFM_GET_EMPLOYEEDATA'
      EXPORTING
        iv_username = lwa_attachment_list-userid
      IMPORTING
        es_ess_emp  = l_ess_emp.
*-  Name
    lwa_attachment_list-creator =  l_ess_emp-name.


*-  Created date
    lwa_attachment_list-date = ls_con-crea_time+0(8).


*-  Mime type
    lwa_attachment_list-mime_type = ls_con-mimetype.


*-  Doc id
    lwa_attachment_list-doc_id = ls_con-loio_id.


*-  Doc ver no
    lwa_attachment_list-doc_ver_no = ls_con-doc_ver_no.


*-  Doc ver id
    lwa_attachment_list-doc_var_id = ls_con-doc_var_id.


*--- Get file content
    IF ls_con-stor_tab = '9'. "GOS


*     Get file content
      CLEAR ls_attachment.
      ls_attachment-id   = ls_con-loio_id.
      ls_attachment-name = ls_con-descript.
      ls_attachment-type = ls_con-docuclass.


      CREATE OBJECT li_document.
      CLEAR: lv_fcont_hex, lv_fcont_txt, lv_mime_type.
      CALL METHOD li_document->document_display_attachment
        EXPORTING
          attachment       = ls_attachment
        IMPORTING
          file_content     = lv_fcont_txt
          file_content_hex = lv_fcont_hex
          mime_file_type   = lv_mime_type.


      IF NOT lv_fcont_txt IS INITIAL.
*       Convert STRING to XSTRING
        CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
          EXPORTING
            text   = lv_fcont_txt
          IMPORTING
            buffer = content
          EXCEPTIONS
            failed = 1
            OTHERS = 2.
      ELSE.
*       No conversion required
        content = lv_fcont_hex.
      ENDIF.
      CONCATENATE lwa_attachment_list-title ls_con-docuclass
      INTO lwa_attachment_list-title SEPARATED BY '.'.


      lwa_attachment_list-mime_type = lv_mime_type.
      lwa_attachment_list-content = content.


    ELSE."BDS
      REFRESH: lt_comp, lt_sig.


      CALL FUNCTION 'BDS_BUSINESSDOCUMENT_GET_INFO'
        EXPORTING
          classname           = classname
          classtype           = classtype
          object_key          = object_key
        TABLES
          signature           = lt_sig
*          connections         = lt_con
          extended_components = lt_comp
        EXCEPTIONS
          nothing_found       = 1
          parameter_error     = 2
          not_allowed         = 3
          error_kpro          = 4
          internal_error      = 5
          not_authorized      = 6
          OTHERS              = 7.
      LOOP AT lt_sig INTO ls_sig WHERE doc_id = ls_con-loio_id.
        EXIT.
      ENDLOOP.
      CHECK sy-subrc = 0.
      LOOP AT lt_comp INTO ls_comp WHERE doc_count = ls_sig-doc_count.
        EXIT.
      ENDLOOP.
      IF sy-subrc = 0.
        l_sdok_objid-objid = ls_comp-objid.
        l_sdok_objid-class = ls_comp-class.
*--     Get content now
        REFRESH lt_content.
        CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
          EXPORTING
            object_id           = l_sdok_objid
            raw_mode            = 'X'
          TABLES
            file_content_binary = lt_content
          EXCEPTIONS
            not_existing        = 1
            not_authorized      = 2
            no_content          = 3
            bad_storage_type    = 4
            OTHERS              = 5.
        IF sy-subrc = 0.
          l_lines = LINES( lt_content ).
          l_len = l_lines * 1022.
*--       Convert content to xstring format


          CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
            EXPORTING
              input_length = l_len
            IMPORTING
              buffer       = content
            TABLES
              binary_tab   = lt_content
            EXCEPTIONS
              failed       = 1
              OTHERS       = 2.
          IF sy-subrc = 0.
            lwa_attachment_list-content = content.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.


    APPEND lwa_attachment_list TO attachment_list.
    CLEAR: lwa_attachment_list,ls_con,ls_comp, l_sdok_objid,
           content.
  ENDLOOP.




For deleting attachment: 




  DATA lt_connections TYPE STANDARD TABLE OF bapiconnec.
  DATA ls_connections TYPE bapiconnec.
  DATA: lt_con TYPE TABLE OF bdn_con.
  ls_connections-classname = 'PDOTYPE_O'.
  ls_connections-classtype = 'BO'.
  ls_connections-object_key = '0150042977'.
  ls_connections-doc_id = ls_attach-doc_id.
  APPEND ls_connections TO lt_connections.
  CALL FUNCTION 'BDS_ALL_CONNECTIONS_GET'
    EXPORTING
*   LOGICAL_SYSTEM         =
      classname              = 'PDOTYPE_O'
      classtype              = 'BO'
     objkey                 = '0150042977'
*   CLIENT                 = SY-MANDT
*   ALL                    = 'X'
*   NO_AL_DOCS             = ' '
*   NO_GOS_DOCS            = 'X'
*   CHECK_STATE            = ' '
* IMPORTING
*   COUNT                  =
    TABLES
     signature              = lt_signature
      all_connections        = lt_con
*   FRAMEWORK              =
   EXCEPTIONS
     no_objects_found       = 1
     error_kpro             = 2
     internal_error         = 3
     not_authorized         = 4
     OTHERS                 = 5
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  delete lt_signature where doc_id ne ls_attach-doc_id.
  delete lt_signature from 2.


    CALL FUNCTION 'BDS_BUSINESSDOCUMENT_DELETE'
      EXPORTING
        classname       =  <class name>
        classtype       = 'BO'
        object_key      = l_doc_key
        x_force_delete  = 'X'
      TABLES
        signature       = lt_signature
      EXCEPTIONS
        nothing_found   = 1
        parameter_error = 2
        not_allowed     = 3
        error_kpro      = 4
        internal_error  = 5
        not_authorized  = 6


        OTHERS          = 7.
For storing attachment: 




*-- Transer file content
    REFRESH lt_file_content.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = lw_attachment_list-content
      TABLES
        binary_tab = lt_file_content.


*-- Set file default path
*    l_file_pathlen = STRLEN( l_directory ).
*    IF NOT l_file_pathlen IS INITIAL.
*      l_file_pathlen = l_file_pathlen - 1.
*      l_file_path = l_file_path(l_file_pathlen).
*      IF l_file_path <> space AND l_file_pathlen < 250.
*        l_file_path_memory = l_file_path.
*        SET PARAMETER ID 'OAP' FIELD l_file_path_memory.
*      ELSE.
*        l_file_path_memory = space.
*        SET PARAMETER ID 'OAP' FIELD l_file_path_memory.
*      ENDIF.
*    ENDIF.


*    IF l_file_extension <> space.
*      SET LOCALE LANGUAGE sy-langu.
*      TRANSLATE l_file_extension TO UPPER CASE.
*      SET LOCALE LANGUAGE space.
*    ENDIF.


* -- fill components and signature structure                        -- *
    lw_component-doc_count  = 1.
    lw_component-comp_count = 1.
    lw_component-mimetype   = lw_attachment_list-mime_type.
    lw_component-comp_id    = lw_attachment_list-title.


    APPEND lw_component TO lt_components.


    lw_signature-doc_count  = 1.
    lw_signature-prop_name  = 'BDS_DOCUMENTCLASS'.
    lw_signature-prop_value = l_file_extension.
    APPEND lw_signature TO lt_signature.


    lw_signature-prop_name  = 'BDS_CONTREP'.
    lw_signature-prop_value = ' '.
    APPEND lw_signature TO lt_signature.


    lw_signature-prop_name  = 'BDS_DOCUMENTTYPE'.
    lw_signature-prop_value = ' '.
    APPEND lw_signature TO lt_signature.


    lw_signature-prop_name  = 'DESCRIPTION'.
    lw_signature-prop_value = lw_attachment_list-title.
    APPEND lw_signature TO lt_signature.


    lw_signature-prop_name  = 'LANGUAGE'.
    lw_signature-prop_value = sy-langu.
    APPEND lw_signature TO lt_signature.


* Created by
*  lw_signature-prop_name  = 'CREATED_BY'.
*  lw_signature-prop_value = lw_attachment_list-USERID.
*  APPEND lw_signature TO lt_signature.


*-- Save attachment list
    CALL FUNCTION 'BDS_BUSINESSDOCUMENT_CREA_TAB'
      EXPORTING
        classname       = <classname>
        classtype       = 'BO'" classtype_select
        object_key      = l_doc_key
        binary_flag     = 'X'
      TABLES
        signature       = lt_signature
        components      = lt_components
        content         = lt_file_content
      EXCEPTIONS
        nothing_found   = 1
        parameter_error = 2
        not_allowed     = 3
        error_kpro      = 4
        internal_error  = 5
        not_authorized  = 6
        OTHERS          = 7.


    REFRESH: lt_components, lt_signature.
    CLEAR lw_attachment_list.


For employee, business obj should be BUS1065 ( I think so ). 
Other things to help in debugging: 
Fn : BINARY_RELATION_CREATE 
CL_GOS_DOCUMENT_SERVICE -> CREATE_ATTACHMENT
CL_GOS_SRV_ATTACHMENT_CREATE -> execute


Using all this info, I think the procedure should be like this: 
From WD XSTRING, convert it to binary, store it in BDS passing an emp no. 
Check in PA30 whether it is appearing against the employee or not. If it appears, it works.. If it does not appear, something is wrong. Let me know then J

你可能感兴趣的:(webdynpro GOS BDS 文档/附件 上传下载处理)