2

So I'm working on a small program that will extract Quality Notification data from ECC. So far I've used the standard "BAPI_QUALNOT_GETDETAIL" to extract the textual data of a notification. What I want to do is to extract the attachments also which is related to the notification.

For this purpose I've found "BAPI_DOCUMENT_GETDETAIL2" which I hope will cater my requirement. The problem that I have is where can I get the following information required to run the BAPI;

  • DOC TYPE
  • DOC NUMBER
  • DOC PART
  • DOC VERSION

BAPI

The only information that I have is the data that I've extracted from the BAPI_QUALNOT_GETDETAIL in which so far I couldn't find any information related to any attachments that was uploaded against the notification.

Following is a screenshot from the Document Flow in t-code IQS3 displaying 3 attachments related to the notification.

Document Flow

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Isuru
  • 3,044
  • 6
  • 30
  • 39
  • you could have a look at the tables involved fo find out how to call BAPI_DOCUMENT_GETDETAIL2. From what I can see in the bapi sources, table DRAD may be a good place to start. – Dirk Trilsbeek Aug 30 '16 at 07:01
  • Are you attempting to extract just DMS documents, or are you interested in documents attached via Object Services? If you're after Object Services then you can just call class method cl_binary_relation=>read_links. – Raggedtoad Sep 26 '16 at 15:34
  • @StuG whats the difference between the two? – Isuru Sep 27 '16 at 04:35
  • DMS documents are a more legacy concept, and they are maintained in transactions CV01N and CV02N. They require maintenance of an entire document info record, where you can add one or more "originals", which would be actual documents that you upload to the application server. Object Services document attachments can be accessed via the Object Services menu in the top-left of many standard SAP transactions. See https://help.sap.com/saphelp_nw70/helpdata/en/be/3fe63659241157e10000009b38f889/content.htm – Raggedtoad Sep 27 '16 at 20:37
  • I don't agree that DMS is a legacy concept. Two different use cases. GOS is not versioned, no workflow, etc. DMS is more into the direction of a real document management system (just as the name implies) :-) – Tschenser Feb 08 '19 at 19:30

2 Answers2

0

If you use GOS for storing attachments try using following FM for fetching them:

CALL FUNCTION 'BDS_GOS_CONNECTIONS_GET'
 IMPORTING
  logical_system  = <system name> * << optional parameter       
  classname       = BUS2078       * << object type for quality notification    
  objkey          = 1014866112016 * << quality notification number + year        
  client          = XXX
 TABLES
  gos_connections = lt_attachments
.

Quality notification numbers, as well as other attributes, are kept in VIQMEL DB table.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
-2

If the attachments are stored in the DMS system please use the following code to retrieve them.

REPORT qn_attachments.

  DATA ls_docfile TYPE bapi_doc_files2.
  DATA lv_objkey  TYPE objky.
  DATA lv_objekt  TYPE dokob.
  DATA lt_drad    TYPE TABLE OF drad.
  DATA lt_docfiles TYPE bapi_tt_doc_files2.
  DATA lv_msg     TYPE string.
  DATA lt_content_bin TYPE sdokcntbins.
  DATA lt_access_info TYPE STANDARD TABLE OF scms_acinf.
  DATA ls_access_info TYPE scms_acinf.
  DATA ls_packing_list TYPE sopcklsti1.
  DATA lv_xstring     TYPE xstring.
  DATA lv_type                  TYPE string.
  DATA lv_name                  TYPE string.
  DATA lv_dot_offset TYPE i.
  DATA lv_extension TYPE mimetypes-extension.
  DATA lv_mimetype TYPE mimetypes-type.
  data lv_qmnum type qmnum.

  lv_objkey = lv_qmnum." QMNUM

  lv_objekt = 'QMQMEL'.
  CALL FUNCTION 'DOKUMENTE_ZU_OBJEKT'
    EXPORTING
      key           = lv_objkey
      objekt        = lv_objekt
    TABLES
      doktab        = lt_drad
    EXCEPTIONS
      kein_dokument = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
  ENDIF.

  LOOP AT lt_drad INTO DATA(ls_drad).
    CLEAR: lt_docfiles, ls_docfile.

  CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'  
    EXPORTING                               
      documenttype    = ls_drad-dokar       
      documentnumber  = ls_drad-doknr       
      documentpart    = ls_drad-doktl       
      documentversion = ls_drad-dokvr       
      getactivefiles  = 'X'                 
    TABLES                                  
      documentfiles   = lt_docfiles.        

    LOOP AT lt_docfiles INTO ls_docfile.
* Get binary content for documents
      REFRESH lt_access_info.
      REFRESH lt_content_bin.
      CALL FUNCTION 'SCMS_DOC_READ'
        EXPORTING
          stor_cat              = ls_docfile-storagecategory
          doc_id                = ls_docfile-file_id
        TABLES
          access_info           = lt_access_info
          content_bin           = lt_content_bin
        EXCEPTIONS
          bad_storage_type      = 1
          bad_request           = 2
          unauthorized          = 3
          comp_not_found        = 4
          not_found             = 5
          forbidden             = 6
          conflict              = 7
          internal_server_error = 8
          error_http            = 9
          error_signature       = 10
          error_config          = 11
          error_format          = 12
          error_parameter       = 13
          error                 = 14
          OTHERS                = 15.
      IF sy-subrc EQ 0.
        APPEND LINES OF: lt_access_info TO lt_access_info,
                         lt_content_bin TO lt_content_bin.
      ELSE.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
      ENDIF.

      READ TABLE lt_access_info INTO ls_access_info INDEX 1.
      IF sy-subrc = 0.

        CLEAR ls_packing_list.

        "Convert DMS document content to XSTRING
        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            input_length = ls_access_info-comp_size
            first_line   = ls_access_info-first_line
            last_line    = ls_access_info-last_line
          IMPORTING
            buffer       = lv_xstring
          TABLES
            binary_tab   = lt_content_bin
          EXCEPTIONS
            failed       = 1
            OTHERS       = 2.
        IF sy-subrc <> 0.
          DELETE lt_content_bin FROM ls_access_info-first_line TO ls_access_info-last_line.
          CONTINUE.
        ENDIF.
        DELETE lt_content_bin FROM ls_access_info-first_line TO ls_access_info-last_line.
* File extension
        FIND FIRST OCCURRENCE OF REGEX '\.[^\.]+$'
          IN ls_access_info-comp_id MATCH OFFSET lv_dot_offset.
        lv_extension = ls_access_info-comp_id+lv_dot_offset.
        TRANSLATE lv_extension TO LOWER CASE.
        lv_type    = ls_access_info-mimetype.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
  • Whilst this code snippet is welcome, and may provide some help, it would be [greatly improved if it included an explanation](//meta.stackexchange.com/q/114762) of *how* and *why* this solves the problem. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Mar 27 '17 at 10:21
  • Thanks for your comment. I've added the following: If the attachments are stored in the DMS system please use the following code to retrieve them. – Attila Barcsik Mar 28 '17 at 11:02