cancel
Showing results for 
Search instead for 
Did you mean: 

SAP inbound mail -> DMS

former_member184443
Participant
0 Kudos

Dear SAP DMS gurus...

We have succeeded to set up inbound email in our SAP system, and in transaction SO50 we now want to create a rule (abap coding) to store every inbound mail as a DMS document.

In the rule we will receive the email as binary data...

The rule use interface IF_INBOUND_EXIT_BCS and method PROCESS_INBOUND needs to be implemented:

try.
*-----Get the email document that was sent
     
data: document type ref to if_document_bcs.
      document = io_sreq->get_document( ).


Can it be possible to use function SCMS_DOC_CREATE to create a DMS document ?

Please advice.

Best regards

Erik

Accepted Solutions (1)

Accepted Solutions (1)

former_member184443
Participant
0 Kudos

Thomas Jung informed me in his excellent blog:

http://scn.sap.com/people/thomas.jung/blog/2004/09/09/receiving-e-mail-and-processing-it-with-abap--...

...that email in SAP is a multi-part MIME. You will not find a datastream representing the email like a outlook msg file.  Therefore you must call GET_BODY_PART_CONTENT for the number of body parts. You can get the content in either text or binary format from this method.

And create a txt file in SAP DMS like this:

   *-------------------------------------------*
*- Get a pointer to the reply email object -*
*-------------------------------------------*
  TRY.
      lo_reply = io_sreq->reply( ).
    CATCH cx_send_req_bcs.
  ENDTRY.


*---------------------*
*- Get email subject -*
*---------------------*
  TRY.
      lo_document = io_sreq->get_document( ).
      l_mail_attr = lo_document->get_body_part_attributes( '1' ).
    CATCH cx_document_bcs.
  ENDTRY.

*-----------------*
*- Get mail body -*
*-----------------*
  TRY.
      l_mail_content = lo_document->get_body_part_content( '1' ).
    CATCH cx_document_bcs.
  ENDTRY.

*------------------------*
*- Get mime data in hex -*
*------------------------*
  TRY.
      result = lo_document->as_mime_document( mime_generator ).
    CATCH cx_document_bcs.
  ENDTRY.


*------------------*
*- Create DMS DIR -*
*------------------*
  ls_dokar = 'CAD'.
  ls_dokvr = '00'.
  ls_doktl = '000'.
  ls_dokst = '00'.

  CLEAR: ls_documentdata.
  ls_documentdata-documenttype    = ls_dokar.
  ls_documentdata-documentpart    = ls_doktl.
  ls_documentdata-documentversion = ls_dokvr.
  ls_documentdata-description     = 'Test inbound mail'.

  CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
    EXPORTING
      documentdata         = ls_documentdata
    IMPORTING
      documentnumber       = ls_doknr
      return               = ls_return
    TABLES
      characteristicvalues = lt_characteristicvalues
      classallocations     = lt_classallocations
      documentstructure    = lt_docstructure.

  IF NOT ls_doknr IS INITIAL.
    COMMIT WORK AND WAIT.
  ENDIF.




*-----------------------------------*
*- Add email to DMS as binary data -*
*-----------------------------------*

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer          = result
      append_to_table = ' '
    IMPORTING
      output_length   = lv_size
    TABLES
      binary_tab      = lt_bindata.


  LOOP AT lt_bindata INTO ls_bindata.
    CLEAR ls_drao.
    ls_drao-mandt = sy-mandt.
    ls_drao-orblk = ls_bindata-line.
    ls_drao-orln  = lv_size.
    ls_drao-dokar = ls_dokar.
    ls_drao-doknr = ls_doknr.
    ls_drao-dokvr = ls_dokvr.
    ls_drao-doktl = ls_doktl.
    ls_drao-appnr = '1'.
    APPEND ls_drao TO lt_drao.
  ENDLOOP.

  CALL FUNCTION 'CV120_DOC_GET_APPL'
    EXPORTING
      pf_file   = 'DO.TXT'
    IMPORTING
      pfx_dappl = ls_files-dappl.

  ls_files-appnr          = '1'.
  ls_files-filename       = 'DO.TXT'.
  ls_files-updateflag     = 'I'.
  ls_files-langu          = sy-langu.
  ls_files-storage_cat    = 'Z_RS1_ALL'.
  ls_files-description    = 'DO.TXT'.
  APPEND ls_files TO lt_files.

  CALL FUNCTION 'CVAPI_DOC_CHECKIN'
    EXPORTING
      pf_dokar           = ls_dokar
      pf_doknr           = ls_doknr
      pf_dokvr           = ls_dokvr
      pf_doktl           = ls_doktl
      ps_api_control     = ls_api_ctrl
      pf_content_provide = 'TBL'
    IMPORTING
      psx_message        = ls_message
    TABLES
      pt_files_x         = lt_files
      pt_content         = lt_drao.

  COMMIT WORK AND WAIT.


  IF ls_message-msg_type CA 'EA'.
    WRITE : ls_doknr.
  ENDIF.

Former Member
0 Kudos

Hi Erik ,

I  have same kind of requirement , i am sending mail using Cl_BCS method and using the object

cl_document_bcs  i am getting MIME_STREAM

i followed same step what you did . but my file format is not coming properly

Can you please let me know what is issues .

Regards

RamTeja

8149421468

Answers (0)