Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Correct class/method(s) to extract DMS doc & email it in native format?

Former Member
0 Kudos

Well, I'm finally at a client site that has DMS running over an external content server. (Some of you may remember last year, when I was at a site using the old internal SOFFDB table - it turned out to be very tricky to put a URL on a picture so you could pop it in PM.)

Anyway, the requirement here is as follows.

Given a SalesOrder (and therefore the associated busienss object for the SO):

a) pick a particular document attached to the Business Object;

b) extract it from DMS

c) attach it to an email (in its native format, e.g. an "xls", or a "doc", etc.

Please advise at your earliest convenience.

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

Hi,

Good to see u back.

1. For getting the content server you can use


  i_object-typeid = 'KNA1'.              " Please change the object id
  i_object-catid  = 'BO'.                " ?
  i_object-instid = docno.
  refresh : i_brel, i_link.
* Get Attachment List
  append 'ATTA' to i_brel.
  if not i_brel is initial.
    select *
      from srgbtbrel
      appending corresponding fields of table i_link
      for all entries in i_brel
      where
        instid_a eq i_object-instid and
        typeid_a eq i_object-typeid and
        catid_a  eq i_object-catid and
        reltype  eq i_brel-reltype.
  endif.
  wa_filter-send_info = 'X'.
  wa_filter-no_content = 'X'.

  loop at i_link into ls_link.
    clear : wa_doc_data.
    wa_fol_cont-doc_id = ls_link-instid_b.
    call function 'SO_DOCUMENT_READ_API1'
      exporting
        document_id                = wa_fol_cont-doc_id
        filter                     = wa_filter
      importing
        document_data              = wa_doc_data
      exceptions
        document_id_not_exist      = 1
        operation_no_authorization = 2
        others                     = 3.

then use fm to send mail out


call function 'SO_DOCUMENT_SEND_API1'

or use class if you want to single mail with all the attachments of that document.

please check this link

11 REPLIES 11

former_member188685
Active Contributor
0 Kudos

There is some simialr requirement. But it will download the attachment.

Report  zorders.
************************************************************************
* TABLES
************************************************************************
TABLES:
 caufvd,
 itcpo.


************************************************************************
* DATA - INTERNAL TABLES
************************************************************************
* Internal table to hold the key of the document
DATA:
  BEGIN OF i_key OCCURS 0,
    order LIKE srgbtbrel-instid_a,     " Order/Notif.
    key LIKE srgbtbrel-instid_b,
  END OF i_key.

* Internal table to hold the file locations
DATA:
  i_files TYPE so_url OCCURS 0 WITH HEADER LINE.

* Internal table to hold the document details
DATA:
  i_sood LIKE STANDARD TABLE OF sood WITH HEADER LINE.

* structure to split the key
DATA:
  BEGIN OF fs_key,
    foltp LIKE sood4-foltp,              " Folder type
    folyr LIKE sood4-folyr,              " Folder year
    folno LIKE sood4-folno,              " Folder Number
    objtp LIKE sood-objtp,               " Object type
    objyr LIKE sood-objyr,               " Object Year
    objno LIKE sood-objno,               " Object Number
  END OF fs_key.

************************************************************************
* DATA - Variables
************************************************************************
DATA:
 sw_document LIKE sood4,
 sw_lines LIKE sy-tabix,
 sw_operation TYPE string.
*&---------------------------------------------------------------------*
*&      Form PRINT_ATTA
*&---------------------------------------------------------------------*
*   No interface parameters required
*----------------------------------------------------------------------*
*  This subroutine is triggered for printing attachments of work order
*----------------------------------------------------------------------*
FORM print_atta.
  DATA:
    exec TYPE REF TO cl_gui_frontend_services.

  DATA:
    w_dir TYPE string,                 " Directory
    w_result TYPE abap_bool.           " Result
  CREATE OBJECT exec.

  DATA:
    sw_document1 TYPE string.
* Select key for attachments linked to work order
  SELECT instid_a                     
         instid_b
    FROM srgbtbrel
    INTO TABLE i_key
   WHERE typeid_a EQ 'BUS2007'
     AND instid_a EQ caufvd-aufnr.

* Select key for attachments linked to notifications
  SELECT instid_a                     
         instid_b
    FROM srgbtbrel
    APPENDING TABLE i_key
   WHERE typeid_a EQ 'BUS2038'
     AND instid_a EQ caufvd-qmnum.

  DESCRIBE TABLE i_key  LINES sw_lines.

  IF sw_lines > 0.
    IF itcpo-tdpreview EQ 'X'.
      MOVE:
       'OPEN' TO sw_operation.
    ELSE.
      MOVE:
       'PRINT' TO sw_operation.
    ENDIF.


* First check whether H: exist in the system directories. If H: exist
* Application is running in The Citrix. If H: Does not exist then
* Use the C:
    MOVE: 'H:' TO w_dir.
    CLEAR w_result.
    CALL METHOD cl_gui_frontend_services=>directory_exist
      EXPORTING
        directory            = w_dir
      RECEIVING
        result               = w_result
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 4
        OTHERS               = 5.
    IF w_result IS INITIAL.
      MOVE: 'C:' TO w_dir.
    ENDIF.                             " IF sy-subrc NE 0.



    LOOP AT i_key.
      MOVE i_key-key TO fs_key.
      SHIFT i_key-order LEFT DELETING LEADING '0'.

* Select attachments
      SELECT *
        FROM sood
        INTO TABLE i_sood
       WHERE objno EQ fs_key-objno
         AND objtp EQ fs_key-objtp
         AND objyr EQ fs_key-objyr.

      IF sy-subrc EQ 0.
* loop at all the attachments
        LOOP AT i_sood.

          MOVE-CORRESPONDING i_sood TO sw_document.
          MOVE-CORRESPONDING fs_key TO sw_document.
          REFRESH i_files.
* Formulate the file name

* To include the Order/ Notification in the path
          CONCATENATE w_dir '\WORKATTA' '_'
                      i_key-order '_'
                      sy-datum
                      sy-uzeit '.'
                      sw_document-file_ext
                 INTO i_files.
          APPEND i_files.

* This function module creates a file in the PC
          CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
            EXPORTING
              method      = 'PUTCONTENTTOFILE'
              office_user = sy-uname
            TABLES
              files       = i_files
            CHANGING
              document    = sw_document.

          READ TABLE i_files INDEX 1.

          MOVE:
           i_files TO sw_document1.

* Printing the file created on the PC
          CALL METHOD exec->execute
            EXPORTING
              document  = sw_document1
              operation = sw_operation.

        ENDLOOP.                        " LOOP AT i_sood
      ENDIF.                            " IF sy-subrc EQ 0
    ENDLOOP.                            " LOOP AT i_key
  ENDIF.                                " IF sy-subrc EQ 0
ENDFORM.                    "print_atta

0 Kudos

Vijay -

Thank you, new friend.

Although aRs's solution is closer to what we presently need, there is very useful corollary material in your answer, and I will keep it handy.

Best regards

djh

0 Kudos

Welcome , and you are also My new friend.

Best Regards

Vijay Babu Dudla

former_member194669
Active Contributor
0 Kudos

Hi,

Good to see u back.

1. For getting the content server you can use


  i_object-typeid = 'KNA1'.              " Please change the object id
  i_object-catid  = 'BO'.                " ?
  i_object-instid = docno.
  refresh : i_brel, i_link.
* Get Attachment List
  append 'ATTA' to i_brel.
  if not i_brel is initial.
    select *
      from srgbtbrel
      appending corresponding fields of table i_link
      for all entries in i_brel
      where
        instid_a eq i_object-instid and
        typeid_a eq i_object-typeid and
        catid_a  eq i_object-catid and
        reltype  eq i_brel-reltype.
  endif.
  wa_filter-send_info = 'X'.
  wa_filter-no_content = 'X'.

  loop at i_link into ls_link.
    clear : wa_doc_data.
    wa_fol_cont-doc_id = ls_link-instid_b.
    call function 'SO_DOCUMENT_READ_API1'
      exporting
        document_id                = wa_fol_cont-doc_id
        filter                     = wa_filter
      importing
        document_data              = wa_doc_data
      exceptions
        document_id_not_exist      = 1
        operation_no_authorization = 2
        others                     = 3.

then use fm to send mail out


call function 'SO_DOCUMENT_SEND_API1'

or use class if you want to single mail with all the attachments of that document.

please check this link

0 Kudos

aRs -

Thank you, my old and dear friend.

Superb response as usual.

0 Kudos

I have a method "GETDETAIL2" I can run from the DMS Business Object "DRAW" that returns the folowing info on attached files.

APPLICATION_ID FILE_ID

Can I then use this data to create the attachment to the email?

Instead of getting to the data via the Sales Order, can I get to it this way?

JP_Barcenas
Participant
0 Kudos

Hello,

I think you can get the list of attached documents by reading the table TOA01 using object VBAK. There you will find the Document ID. With the DocID you can use ARCHIVOBJECT_DISPLAY to retrieve the file.

Regards,

Juan

0 Kudos

Hi Juan -

Judging from Vijay's and aRs' responses, I'm not sure what you're suggesting is the right way to go.

But I will investigate.

Thanks very much for taking the time to respond.

djh

former_member181923
Active Participant
0 Kudos

Thanks to Juan, Vijay, aRS - terrific info

Former Member
0 Kudos

I have a method "GETDETAIL2" I can run from the DMS Business Object "DRAW" that returns the folowing info on attached files.

APPLICATION_ID FILE_ID

Can I then use this data to create the attachment to the email?

Instead of getting to the data via the Sales Order, can I get to it this way?

Former Member
0 Kudos

a®s explained the way to get at the attachments to a Business Object using

the SRGTBREL table.

Are the entries in the SRGTBREL table somehow related to the APPLICATION ID

and FILE ID that are returned by the GETDETAIL2 method of the DMS Business Object

"DRAW"?

If so, how?

If not, what are APP ID and FILE ID for?

Thanks for considering this matter.

Ted Smith