Skip to Content
avatar image
Former Member

Send PO PDF to vendor and ALSO to others

Hi,

I have a custom Ouput Type, ZNEU, that sends our custom PO form via email to the vendor by using SAPFM06 and routine ENTRY_NEU at PO save. Works fine.

Also at PO save, a new requirement is to send an email with the PO attached to two other other recipients: the requisitioner (eban-banfn) and a custom field (eban-zuname). I created a second custom Output Type, ZNE2, that gets the recipient values and their email addresses and sends the email, but how can I attach the PDF as well. At the time the output message is being created, the spool file doesn't exist yet. I considered modifying our custom output type ZNEU to also send to the additional recipients, but can't figure out where to enhance the code.

Any suggestions on how to meet this requirement will be greatly appreciated. Yes, I reward all helpful answers.

Beth

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Apr 21, 2008 at 03:30 PM

    Hi,

    You could make a copy of SAPFM06 (ZSAPFM06) and do your improvements in that program.

    Then in NACE you can link your Zprogram for outputtype ZNEU.

    Regards,

    Bert

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I probably did not articulate this clearly earlier but there would be only one call to the print program (part copy of SAPFM06P). During this call, you add two recepients derived from eban-ernam and eban-zuname to the email function.

  • avatar image
    Former Member
    Jun 17, 2008 at 10:00 AM

    Hi Beth,

    I just came across your post about Sending PO to a vendor through e-mail with PDF attachement.

    I have a similar issue on hand.

    My Program name - Z_SAPFM06P

    Routine - ENTRY_NEU

    Form - Z_MEDRUCK

    My requirement : After creation of a PO, on click of 'Save' button, an e-mail needs to be sent to a given receipient.

    As of now, I have included the code in the routine - ENTRY_NEU and I'm facing probelms with the FM - SO_NEW_DOCUMENT_ATT_SEND_API1.

    Pls let me know what exactly is the codeand where to I need to include it. Pls tell me how to go about tis issue step-by-step.

    Thanks in advance.

    lakshmi

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Lakshmi,

      I suggest you make yourself very familiar with the SAP code that does this automatically. Once you understand the processing sequence SAP uses, it is much easier to add your customization and insert your enhancements. To debug it and step through the code, but a breakpoint in ENTRY_NEU, and process a PO. If you're sending your messages using a scheduled job, you'll hit the breakpoint when you process the message using RSNAST00. That's how I did it.

      I can tell you what I did to meet my requirements. You can change to meet your needs. It required a custom program, to use instead if ENTRY_NEU, and 3 enhancements to SAP code using the Enhancement Framework. You need to know how to use the framework.

      1. configure your output type ZNE2 to to run a new program ZMRP_OUTCTRL, to run form routine ENTRY_ZNE2, to create form Z_PURCHASE_ORDER.

      2. In ZMRP_OUTCTRL, call standard function modules, ME_READ_PO_FOR_PRINT and ME_PRINT_PO.

      3. Drill down into ME_PRINT_PO to PREPARE_FORMULAR function module. Create new enhancement, and if NAST-KSCHL = ZNE2, then lookup the recipient's email address. Pass it as parameter to ADDR_GET_NEXT_COMM_TYPE.

      4. Still in ME_PRINT_PO, PREPARE_FORMULAR, add another enhancement to set the value of itcpo-getotf to u2018Xu2019, to enable CLOSE_FORM to capture OTF data for PDF. Only set this OTF flag when the output is being run by RSNAST00, not when a user is simply previewing the printout. Sy-ucomm will be blank when RSNAST00 is running.

      5. In ME_PRINT_PO, drill down to ENDE, and add an enhancement to check for NAST-KSCHL = ZNE2, and if so, call standard SAP function modules to END_FORM, START_FORM, WRITE_FORM, and END_FORM. Next call the function CLOSE_FORM, and set table parameter to capture the OTF_DATA as a table parameter OTF_DATA.

      6. If OTF_DATA is found, then:

      If nast-kschl = 'ZNE2'.

      if NOT otf_data[] is initial.

      gs_OTF[] = otf_data[].

      CALL FUNCTION 'CONVERT_OTF'

      EXPORTING

      format = 'PDF'

      IMPORTING

      bin_filesize = v_len_in

      TABLES

      otf = gs_otf

      lines = gt_pdf

      EXCEPTIONS

      err_max_linewidth = 1

      err_format = 2

      err_conv_not_possible = 3

      OTHERS = 4.

      IF SY-SUBRC <> 0.

      p_retco = '1'.

      PERFORM protocol_update USING '303' 'OTF Conversion failed.' 'Output Message Cancelled.'

      space space.

      IF 1 = 2.

      MESSAGE S303(me) with 'OTF Conversion failed.'.

      ENDIF.

      EXIT.

      ENDIF.

      CALL FUNCTION 'QCE1_CONVERT'

      TABLES

      T_SOURCE_TAB = gt_pdf

      T_TARGET_TAB = outbin.

      IF SY-SUBRC <> 0.

      p_retco = '1'.

      PERFORM protocol_update USING '303' 'PDF Conversion failed.' 'Output Message Cancelled.'

      space space.

      IF 1 = 2.

      MESSAGE S303(me) with 'PDF Conversion failed.'.

      ENDIF.

      EXIT.

      ENDIF.

      *get email recipients (this is specific to my requirements)

      select single banfn ernam zuname1

      into (lv_banfn, lv_ernam, lv_zuname )

      from eban

      where ebeln = nast-objky.

      IF SY-SUBRC <> 0.

      p_retco = '1'.

      PERFORM protocol_update USING '303' 'Requisition Data not found.' 'Output Message Cancelled.'

      space space.

      IF 1 = 2.

      MESSAGE S303(me) with 'Requisition Data not found.'.

      ENDIF.

      EXIT.

      ENDIF.

      8. Build your OBJPACK and OBJBIN parameters:

      describe table mail_content lines lin.

      read table mail_content index lin.

      mail_data-doc_size = ( lin - 1 ) * 255 + STRLEN( mail_content ).

      clear objpack-transf_bin.

      objpack-head_start = 1.

      objpack-head_num = 0.

      objpack-body_start = 1.

      objpack-body_num = lin.

      objpack-doc_type = 'TXT'.

      APPEND objpack.

      describe table outbin lines lin.

      read table outbin index lin.

      objpack-doc_size = ( lin - 1 ) * 255 + strlen( outbin ).

      objpack-transf_bin = 'X'.

      objpack-head_start = 1.

      objpack-head_num = 0.

      objpack-body_start = 1.

      objpack-body_num = lin.

      objpack-doc_type = 'PDF'.

      objpack-obj_name = 'ATTACHMENT'.

      objpack-obj_descr = l_descr.

      APPEND objpack.

      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

      EXPORTING

      DOCUMENT_DATA = mail_data

      PUT_IN_OUTBOX = 'X'

      TABLES

      PACKING_LIST = objpack

      CONTENTS_BIN = outbin

      CONTENTS_TXT = mail_content

      RECEIVERS = receivers

      EXCEPTIONS

      TOO_MANY_RECEIVERS = 1

      DOCUMENT_NOT_SENT = 2

      DOCUMENT_TYPE_NOT_EXIST = 3

      OPERATION_NO_AUTHORIZATION = 4

      PARAMETER_ERROR = 5

      X_ERROR = 6

      ENQUEUE_ERROR = 7

      OTHERS = 8.

      IF SY-SUBRC <> 0.

      p_retco = '1'.

      PERFORM protocol_update USING '303' 'Send Email function failed.' 'Output Message Cancelled.'

      space space.

      IF 1 = 2.

      MESSAGE S303(me) with 'Send Email function failed.'.

      ENDIF.

      EXIT.

      ENDIF.

      9. Call function CLOSE_FORM, and end enhancement.

      That's everything. I hope it works for you.

  • avatar image
    Former Member
    Sep 21, 2010 at 06:57 AM

    Dear Folks,

    I hope my requirement is similar to this... Is there any way to send the Attachment with PO by E mail to vendor,

    I have already is place to send the PO to Vendor by Mail, now i have to include the attachment which is in PO to vendor in the same or original PO mail.

    Thanks in advance

    regards

    M.Kannan

    Add comment
    10|10000 characters needed characters exceeded