cancel
Showing results for 
Search instead for 
Did you mean: 

Sending DMS Document as Attachment thru e-mail

Former Member
0 Kudos

Hi,

I am attaching the DMS document in purchase order & I am sending the PO thru email to vendor.But while doing so the attached document shuld be sent as attachment But in my present config setting it is not doing so.

Pl suggest

Rgds

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

Unfortunatly it's not possible with the standard to send the attachment by mail with the form .

You have to develop enhancement with several BADI for this.

Tell me if you need sample code because i just do it for my customer.

Best regards.

Former Member
0 Kudos

Hi Bertrand / Nitin,

Thnks for the reply.

Pl send me the detailed steps. it is very urgent.

Rgds

Former Member
0 Kudos

Hi,

Steps

1)Recipient Management

Show all entries for recipient management

User menu document management system Environment Document distribution Recipient Office User

Use the address info and communication type RMA. Show all entries.

2) Customizing settings :

Under Document management → Document distribution→ Distribution type→ Define distribution types

Click on the distribution type which you want to activate and make it default (RMA).

3) Go to DIR, Environment ---> doc distribution ---> create recepient list and save the recipient list.

4) Start the distribution with your defined entries. T code CVI8

5) Look at the log entries. CVI9

6) Use the Workplace in the standard SAP menu. If you did everything in the right way, you will find an entry in your workplace ( t code SBWP).

7) Refer Note 824949-Document distribution: for Activating Event type linkage.

Thank you

Regards,

nitin

Award points if useful

Former Member
0 Kudos

Hi,

With my solution you will be able to send the PO and all link document in a mail at the same time you print it.

First Step

Create a new message with transaction NACE , this message will use support 8 ( external program) . The print program should be a copy the same as for printing your PO but add a new form entry inside.

Second step .

In the print program , create the new form entry and add the code . bellow a sample code i wrote . Some object are specific so you have to create it . If you need i can give you te detail of thoses objects.


  DATA : bin_file       TYPE xstring ,
         bin_filesize   TYPE i ,
         w_objky        TYPE objky,
         my_sender      TYPE zcl_send_mail=>ty_sender,
         mail_line      TYPE LINE OF soli_tab,
         w_attsub       TYPE so_obj_des.

  DATA: l_druvo TYPE t166k-druvo,
        l_nast  TYPE nast,
        l_from_memory,
        l_doc   TYPE meein_purchase_doc_print.

  DATA : v_parvw2   TYPE nast-parvw,
         v_parnr2   TYPE nast-parnr,
         v_lifnr    TYPE konv-lifnr,
         v_adrnr    TYPE lfa1-adrnr,
         st_address TYPE addr1_sel,
         st_sadr    TYPE sadr.

* definition des tables internes
  DATA : it_otf   TYPE STANDARD TABLE OF itcoo ,
         it_line  TYPE STANDARD TABLE OF tline ,
         it_fill  TYPE STANDARD TABLE OF drad,
         it_new   TYPE STANDARD TABLE OF drad ,
         itb_xtkomv TYPE STANDARD TABLE OF komv WITH HEADER LINE,
         itb_xekpo  TYPE STANDARD TABLE OF ekpo WITH HEADER LINE,
         it_ekpo  TYPE HASHED TABLE OF ekpo WITH UNIQUE KEY ebeln ebelp ,
         it_draw  TYPE HASHED TABLE OF draw WITH UNIQUE KEY dokar
                                                            doknr
                                                            dokvr
                                                            doktl ,
         it_drat  TYPE HASHED TABLE OF drat WITH UNIQUE KEY dokar
                                                            doknr
                                                            dokvr
                                                            doktl
                                                            langu,
         my_attachement_list TYPE zcl_send_mail=>attachement_list,
         my_recipient_list   TYPE zcl_send_mail=>recipient_list  ,
         it_hexa TYPE solix_tab ,
         it_body TYPE soli_tab.

  CONSTANTS : c_object TYPE dokob VALUE 'EKPO' .
*
  FIELD-SYMBOLS : <ekpo>   TYPE ekpo,
                  <drad>   TYPE drad ,
                  <draw>   TYPE draw,
                  <drat>   TYPE drat .
*
  DATA : my_mail TYPE REF TO zcl_send_mail . => Specific object 

***** 
.....
** Here write your own code like you print the PO form in order to be able to retrieve it from memory
** don't send it to the printer only in spool .
.....
.....

* Get OTF from Memory.

  CALL FUNCTION 'READ_OTF_FROM_MEMORY'
    EXPORTING
      memory_key   = nast-objky
    TABLES
      otf          = it_otf
    EXCEPTIONS
      memory_empty = 1.

  CHECK sy-subrc EQ 0.

* Transform OTF into PDF
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = bin_filesize
      bin_file              = bin_file
    TABLES
      otf                   = it_otf
      lines                 = it_line
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4.

* Transform PDF as Binary Table
  it_hexa = cl_document_bcs=>xstring_to_solix( ip_xstring = bin_file ).

* Add PO as PDF file to the mail 
  zcl_send_mail=>add_attachement_to_list(
    EXPORTING
      type                       = 'PDF'
      subject                    = 'PO'
      content_hexa               = it_hexa
    CHANGING
      attachement_list           = my_attachement_list
    EXCEPTIONS
      no_content_for_attachement = 1
      no_application_type        = 2 ).

* Get PO Item because DIR are link to item only.

  SELECT * FROM ekpo
    APPENDING CORRESPONDING FIELDS OF TABLE it_ekpo
    WHERE ebeln = nast-objky.

* Search for DIR .

  FREE : it_draw , it_drat .

  LOOP AT it_ekpo ASSIGNING <ekpo>.
    FREE : it_fill , it_new.
    CONCATENATE <ekpo>-ebeln <ekpo>-ebelp INTO w_objky.
    CALL FUNCTION 'CV140_SELECT_DRAD_DOCUMENTS'
      EXPORTING
        pf_key       = w_objky
        pf_object    = c_object
      TABLES
        pt_fill_drad = it_fill
        pt_new_drad  = it_new
      EXCEPTIONS
        no_document  = 1.
* For each DIR , retrieve physical content

    LOOP AT it_fill ASSIGNING <drad>.
      IF <draw> IS ASSIGNED.
        UNASSIGN <draw>.
      ENDIF.
      READ TABLE it_draw ASSIGNING <draw>
         WITH TABLE KEY dokar = <drad>-dokar
                        doknr = <drad>-doknr
                        dokvr = <drad>-dokvr
                        doktl = <drad>-doktl.

      IF NOT <draw> IS ASSIGNED.
        SELECT * FROM draw
           APPENDING CORRESPONDING FIELDS OF TABLE it_draw
           WHERE dokar = <drad>-dokar
             AND doknr = <drad>-doknr
             AND dokvr = <drad>-dokvr
             AND doktl = <drad>-doktl.

        SELECT * FROM drat
           APPENDING CORRESPONDING FIELDS OF TABLE it_drat
           WHERE dokar = <drad>-dokar
             AND doknr = <drad>-doknr
             AND dokvr = <drad>-dokvr
             AND doktl = <drad>-doktl
             AND langu = sy-langu.

        READ TABLE it_draw ASSIGNING <draw>
           WITH TABLE KEY dokar = <drad>-dokar
                          doknr = <drad>-doknr
                          dokvr = <drad>-dokvr
                          doktl = <drad>-doktl.
      ENDIF.
      CHECK <draw> IS ASSIGNED.
      READ TABLE it_drat ASSIGNING <drat>
               WITH TABLE KEY dokar = <drad>-dokar
                              doknr = <drad>-doknr
                              dokvr = <drad>-dokvr
                              doktl = <drad>-doktl
                              langu = sy-langu.
      IF <drat> IS ASSIGNED.
        w_attsub = <drat>-dktxt.
      ELSE.
        CONCATENATE <drad>-dokar <drad>-doknr <drad>-dokvr <drad>-doktl
           INTO w_attsub SEPARATED BY '/'.
      ENDIF.
      PERFORM add_fid_to_attachement USING <draw>
                                           w_attsub
                                  CHANGING my_attachement_list.
      CHECK <drat> IS ASSIGNED.
      UNASSIGN <drat>.
    ENDLOOP.

    LOOP AT it_new ASSIGNING <drad>.
      IF <draw> IS ASSIGNED.
        UNASSIGN <draw>.
      ENDIF.
      READ TABLE it_draw ASSIGNING <draw>
         WITH TABLE KEY dokar = <drad>-dokar
                        doknr = <drad>-doknr
                        dokvr = <drad>-dokvr
                        doktl = <drad>-doktl.

      IF NOT <draw> IS ASSIGNED.
        SELECT * FROM draw
           APPENDING CORRESPONDING FIELDS OF TABLE it_draw
           WHERE dokar = <drad>-dokar
             AND doknr = <drad>-doknr
             AND dokvr = <drad>-dokvr
             AND doktl = <drad>-doktl.

        SELECT * FROM drat
           APPENDING CORRESPONDING FIELDS OF TABLE it_drat
           WHERE dokar = <drad>-dokar
             AND doknr = <drad>-doknr
             AND dokvr = <drad>-dokvr
             AND doktl = <drad>-doktl
             AND langu = sy-langu.

        READ TABLE it_draw ASSIGNING <draw>
           WITH TABLE KEY dokar = <drad>-dokar
                          doknr = <drad>-doknr
                          dokvr = <drad>-dokvr
                          doktl = <drad>-doktl.
      ENDIF.
      CHECK <draw> IS ASSIGNED.
      READ TABLE it_drat ASSIGNING <drat>
               WITH TABLE KEY dokar = <drad>-dokar
                              doknr = <drad>-doknr
                              dokvr = <drad>-dokvr
                              doktl = <drad>-doktl
                              langu = sy-langu.
      IF <drat> IS ASSIGNED.
        w_attsub = <drat>-dktxt.
      ELSE.
        CONCATENATE <drad>-dokar <drad>-doknr <drad>-dokvr <drad>-doktl
           INTO w_attsub SEPARATED BY '/'.
      ENDIF.
      PERFORM add_fid_to_attachement USING <draw>
                                           w_attsub
                                  CHANGING my_attachement_list.
      CHECK <drat> IS ASSIGNED.
      UNASSIGN <drat>.
    ENDLOOP.

  ENDLOOP.

* Send mail to PO creator

* Sender
my_sender-mail = '****' . => Set the sender mail adress

* Add Recipient
  zcl_send_mail=>add_recipient_to_list(
    EXPORTING
      uname               = sy-uname
    CHANGING
      recipient_list      = my_recipient_list
    EXCEPTIONS
      no_recipient_to_add = 1 ).

* Mail body 
  mail_line = 'PO by mail with Attachment'.
  APPEND mail_line TO it_body.

* Create send request 
  CREATE OBJECT my_mail.

* Send Mail 
  my_mail->send_mail(
      sender                      = my_sender
      mail_subject                = 'E-mail PO'
      mail_body                   = it_body
      recipient_list              = my_recipient_list
      attachement_list            = my_attachement_list ).

Bellow the code for the routine ADD_FID_TO_ATTACHEMENT


  DATA : w_cout         TYPE dms_checkout_def,
         w_dttrg        TYPE dttrg, "Name of data carrier
         w_docfile      TYPE dms_doc_file,
         w_dappl        TYPE dappl, "Application
         w_tabix        TYPE i ,
         w_tdwa         TYPE tdwa ,
         w_phio         TYPE dms_phio,
         w_frontend TYPE dms_frontend_data.

  DATA : it_drao  TYPE STANDARD TABLE OF drao WITH HEADER LINE,
         it_kpro  TYPE dms_tbl_file .

  CONSTANTS : "c_print_option TYPE apptp VALUE '3', "Print option
              c_hostname TYPE ntadr VALUE 'DEFAULT', "Hostname
              c_type TYPE typdt VALUE 'PC', "Type
              c_system TYPE char4 VALUE 'WN32'. "System

  FIELD-SYMBOLS : <kpro>   TYPE LINE OF dms_tbl_file,
                  <phio>   TYPE LINE OF dms_tbl_phio .

  CLEAR : w_tdwa .

* Check if for DIR type KPRO is used
  CALL FUNCTION 'CV200_DB_TDWA_SELECT'
    EXPORTING
      pf_dokar  = in_draw-dokar
    IMPORTING
      psx_tdwa  = w_tdwa
    EXCEPTIONS
      not_found = 1.

  w_frontend-frontend_type = c_type. "'PC'.
  w_frontend-hostname      = c_hostname. "'DEFAULT'.
  w_frontend-winsys        = c_system.                      "'WN32'.
  w_frontend-platform      = 0.

  w_cout-comp_get          = abap_true.
  w_cout-kpro_use          = w_tdwa-kpro_use.
  w_cout-batchmode         = abap_true.
  w_cout-content_provide   = 'TBL'.

  CALL FUNCTION 'CV120_KPRO_MASTER_DATA_GET'
    EXPORTING
      pf_dokar  = in_draw-dokar
      pf_doknr  = in_draw-doknr
      pf_dokvr  = in_draw-dokvr
      pf_doktl  = in_draw-doktl
    TABLES
      ptx_data  = it_kpro
    EXCEPTIONS
      not_found = 1
      error     = 2.

  CASE w_tdwa-kpro_use.
    WHEN abap_true.
      CALL FUNCTION 'CV120_KPRO_MASTER_DATA_GET'
        EXPORTING
          pf_dokar  = in_draw-dokar
          pf_doknr  = in_draw-doknr
          pf_dokvr  = in_draw-dokvr
          pf_doktl  = in_draw-doktl
        TABLES
          ptx_data  = it_kpro
        EXCEPTIONS
          not_found = 1
          error     = 2.
      w_frontend-frontend_type = 'KP'.
      LOOP AT it_kpro ASSIGNING <kpro>.
        FREE it_drao.
        LOOP AT <kpro>-tbl_phios ASSIGNING <phio>.
          MOVE-CORRESPONDING <phio> TO w_phio.

          CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW'
            EXPORTING
              ps_cout_def = w_cout
              ps_doc_file = w_docfile
              ps_draw     = in_draw
              ps_phio     = w_phio
              ps_frontend = w_frontend
            TABLES
              ptx_content = it_drao
            EXCEPTIONS
              error       = 1.

          PERFORM transform_fid_to_binary TABLES it_drao
                                       USING <kpro>-dappl
                                             in_attsub
                                      CHANGING attachement_list .

        ENDLOOP.
      ENDLOOP.
    WHEN abap_false.
      DO 2 TIMES.
        CLEAR : w_docfile .

        FREE : it_drao.

        w_tabix = sy-index.

        w_docfile-fileno = w_tabix.

        CASE w_tabix.
          WHEN 1.
            w_dappl = in_draw-dappl.
            w_dttrg = in_draw-dttrg.
          WHEN 2.
            w_dappl = in_draw-dappl1.
            w_dttrg = in_draw-dttrg1.
        ENDCASE.

        w_docfile-dappl = w_dappl.
        w_docfile-dttrg = w_dttrg.

        CALL FUNCTION 'CV120_DOC_CHECKOUT'
          EXPORTING
            ps_cout_def      = w_cout
            ps_draw          = in_draw
            ps_doc_file      = w_docfile
          TABLES
            ptx_drao         = it_drao
          EXCEPTIONS
            error            = 1
            OTHERS           = 2.

        PERFORM transform_fid_to_binary TABLES it_drao
                                   USING w_dappl
                                         in_attsub
                                  CHANGING attachement_list .
      ENDDO.
  ENDCASE.

Bellow the code for routine TRANSFORM_FID_TO_BINARY


  FIELD-SYMBOLS : <drao>   TYPE drao ,
                  <source> TYPE x ,
                  <dest>   TYPE x,
                  <hexa>   TYPE solix .

  DATA :   w_filelong     TYPE i ,
           w_long         TYPE i,
           w_longdes      TYPE i  .

  DATA :   it_hexa  TYPE solix_tab .

  CHECK it_drao[] IS NOT INITIAL.

* Transform Physical document into Binary 
  LOOP AT it_drao ASSIGNING <drao>.
    IF w_filelong IS INITIAL.
      w_filelong = <drao>-orln.
    ENDIF.
    ASSIGN <drao>-orblk TO <source>.
    DESCRIBE FIELD <source> LENGTH w_long IN BYTE MODE.
    CLEAR w_longdes.

    WHILE w_long GT 0.
      ASSIGN <source>+w_longdes(w_long) TO <source>.
      APPEND INITIAL LINE TO it_hexa ASSIGNING <hexa>.
      ASSIGN <hexa>-line TO <dest>.
      DESCRIBE FIELD <dest> LENGTH w_longdes IN BYTE MODE.

      MOVE <source> TO <dest>.
      w_filelong = w_filelong - w_longdes.
      w_long = w_long - w_longdes.
      CHECK w_filelong LE w_longdes.
      IF w_long NE 0.
        w_long = w_filelong.
      ENDIF.
      CHECK w_long LE 0.
      w_long = 0.
    ENDWHILE.
  ENDLOOP.
* Add file to list of attachment
  CHECK NOT it_hexa[] IS INITIAL.

  zcl_send_mail=>add_attachement_to_list(
    EXPORTING
      type                       = w_dappl
      subject                    = in_attsub
      content_hexa               = it_hexa
    CHANGING
      attachement_list           = attachement_list
    EXCEPTIONS
      no_content_for_attachement = 1
      no_application_type        = 2 ).

In my complete solution, an additionnal screen have been define in the header of PO to allow user managing recipient list . If you need so i can give you the code also .

Let me know.

Best regards

Former Member
0 Kudos

Thnks Bertrand/Nitin ,

Bertrand , I discussed with my ABAPER regarding this procedure & we are working on it.I need the object list which u defined in the code.

Thnnks again

Former Member
0 Kudos

Hi,

I'll work on it tonight in order to be able to send it to you .

Best regards.

Former Member
0 Kudos

You can use INT instead of RMA and it should strip off the attachment and send to external recipients in document distribution. You also don't need to create the recipient list first, if you go to send without having a recipient list, it will allow you to create the recipients when creating the distribution item.

Former Member
0 Kudos

Hi,

I can't post it here, can you give me your mail and i'll send you all necessary information.

Best regards.

Bertrand

nirajsikligar
Active Contributor
0 Kudos

This message was moderated.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi shrikrishna,

there is a solution on your problem.

With the help of object linking, you can link DMS (DIR) with the PO. or

Attach the PO to the DIR, with the help of documnet distribution , , you can send the DIR with attached file to any one through remote mail.

Instead of RML select RMA, DIR will send with original appliction file as attachment.

I can provide you the steps for document distribution if you need

Regards,

nitin

Award point, if useful.

Edited by: nitin bhagat on Apr 1, 2008 8:36 AM

Former Member
0 Kudos

Hello Bertrand , Shrikrishna,

Could you please provide me details how it was solved? As we have the same requirement where business would like to send attachments which are there at PO line item level to vendor whenever PO goes out to vendor via email.

Thank you in advance for your help.

Best Regards

Ritesh

former_member224273
Participant
0 Kudos

This message was moderated.