Skip to Content

Which program generates SPOOL ID for PO Creation

Hi everyone,

I wish to send PO PDF through email at the time of creation after pressing save button..

I have done research on SCN but didn't got satisfactory solution.

Please guide me on this.

Thanks,

Darshan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Oct 30, 2015 at 03:46 PM

    Hi Folks

    Got the solution...

    I debugged the program SAPLMEPO  and in include MM06EF0P_PARAMETER_SETZEN

    Wrote below code:

    TYPES:  lty_document_data TYPE sodocchgi1,
             lty_packing_list TYPE sopcklsti1,
             lty_attachment TYPE solisti1,
             lty_body_msg TYPE solisti1,
             lty_receivers TYPE somlreci1,
             lty_pdf TYPE tline.

         TYPES: BEGIN OF lty_preis,
                  preis TYPE bapre,
                  menge TYPE BAMNG,
                 END OF lty_preis.

         DATA :   lw_nast TYPE nast,
                  lt_otf LIKE itcoo OCCURS 0 WITH HEADER LINE,
                  lw_doc   TYPE meein_purchase_doc_print,
                  lw_druvo LIKE t166k-druvo,
                  lv_from_memory,
                  lv_ent_retco TYPE i,
                  lv_nast TYPE na_objkey,
                  lv_ebeln TYPE ebeln,
                  lw_document_data TYPE lty_document_data,
                  lw_packing_list TYPE lty_packing_list,
                  lw_attachment TYPE lty_attachment,
                  lw_body_msg TYPE lty_body_msg,
                  lw_receivers TYPE lty_receivers,
                  lt_pdf TYPE TABLE OF solisti1,
                  lw_pdf TYPE lty_pdf,
                  lt_packing_list TYPE STANDARD TABLE OF lty_packing_list,
                  lt_body_msg TYPE STANDARD TABLE OF lty_body_msg,
                  lt_receivers TYPE STANDARD TABLE OF lty_receivers,
                  lt_pdf_tab TYPE TABLE OF tline,
                  lv_ernam TYPE ernam,
                  lv_po TYPE char10,
                  lv_pr TYPE char50,
                  lv_subject TYPE so_obj_des,
                  lv_body TYPE solisti1,
                  lv_aedat TYPE aedat,
                  lv_date_external TYPE char10,
                  lv_erdat TYPE erdat,
                  lv_erdat_c TYPE char10,
                  lv_name1 TYPE name1_gp,
                  lv_ernam_po TYPE ernam,
                  lv_lifnr TYPE lifnr,
                  lt_preis TYPE STANDARD TABLE OF lty_preis,
                  lw_preis TYPE lty_preis,
                  lv_sum_c TYPE char50,
                  lv_preis TYPE bapre,
                  lv_menge TYPE bamng,
                  lv_mul TYPE bapre,
                  lv_sum   TYPE bapre,
                  lw_sent_to_all TYPE sonv-flag,
                  lv_tab_lines TYPE i,
                  lv_bin_filesize TYPE i.


       WAIT UP TO 4 SECONDS.
    lv_nast = ekko-ebeln.


    SELECT SINGLE *
           FROM nast
           INTO lw_nast
           WHERE kappl EQ 'EF' AND
                 objky EQ lv_nast.

       IF sy-subrc eq 0.

    *   clear ent_screen.
      CLEAR lv_ent_retco.

    IF lw_nast-aende EQ space.
       lw_druvo = '1'.
    ELSE.
       lw_druvo = '2'.
    ENDIF.

       CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'
       EXPORTING
         ix_nast        = lw_nast
         ix_screen      = 'X'
       IMPORTING
         ex_retco       = lv_ent_retco
         ex_nast        = lw_nast
         doc            = lw_doc
       CHANGING
         cx_druvo       = lw_druvo
         cx_from_memory = lv_from_memory.

    CHECK lv_ent_retco EQ 0.


       CALL FUNCTION 'ECP_PRINT_PO'
       EXPORTING
         ix_nast   = lw_nast
         ix_druvo  = lw_druvo
         doc       = lw_doc
         ix_screen = 'X'
       IMPORTING
         ex_retco  = lv_ent_retco.
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

       CALL FUNCTION 'READ_OTF_FROM_MEMORY'
       EXPORTING
         memory_key   = lw_nast-objky
       TABLES
         otf          = lt_otf[]
       EXCEPTIONS
         memory_empty = 1
         OTHERS       = 2.
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        FORMAT                      = 'PDF'
        MAX_LINEWIDTH               = 132
      IMPORTING
        BIN_FILESIZE                = lv_bin_filesize
    *   BIN_FILE                   = pdf_bin
       TABLES
         otf                         = lt_otf[]
         lines                       = lt_pdf_tab[]
      EXCEPTIONS
        ERR_MAX_LINEWIDTH           = 1
        ERR_FORMAT                  = 2
        ERR_CONV_NOT_POSSIBLE       = 3
        ERR_BAD_OTF                 = 4
        OTHERS                      = 5
               .
    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ENDIF.

    ** date 28/10/2015
      CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
         EXPORTING
           line_width_dst              = '255'
         TABLES
           content_in                  = lt_pdf_tab[]
           content_out                 = lt_pdf[]
         EXCEPTIONS
           err_line_width_src_too_long = 1
           err_line_width_dst_too_long = 2
           err_conv_failed             = 3
           OTHERS                      = 4.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.
    ******************PO DATA**************************
    lv_aedat = ekko-aedat.
    lv_ernam_po = ekko-ernam.
    lv_po    = ekko-ebeln.
    lv_lifnr = ekko-lifnr.


       CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
       EXPORTING
         date_internal = lv_aedat
       IMPORTING
         date_external = lv_date_external.

    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ENDIF.
    ******************PO DATA**************************
    ******************PR DATA************************************
    SELECT preis menge
        FROM eban
         INTO TABLE lt_preis
           WHERE banfn EQ eban-banfn.
    CLEAR lv_sum.

    LOOP AT lt_preis INTO lw_preis.
       CLEAR: lv_mul, lv_preis, lv_menge.
       lv_preis = lw_preis-preis.
       lv_menge = lw_preis-menge.
       lv_mul = lv_preis * lv_menge.
       lv_sum = lv_sum + lv_mul.
    ENDLOOP.

             DIVIDE lv_sum BY 1000.
             MOVE lv_sum TO lv_sum_c.
             CONDENSE lv_sum_c.

             lv_ernam = eban-ernam.
             lv_pr    = eban-banfn.
             lv_erdat = eban-erdat.

      CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
       EXPORTING
         date_internal = lv_erdat
       IMPORTING
         date_external = lv_erdat_c.

    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ENDIF.

    *****************PR DATA************************************
    *****************vendor name*****************************
    SELECT SINGLE name1
           FROM lfa1
             INTO lv_name1
               WHERE lifnr EQ ekko-lifnr.
    *****************vendor name*****************************

    CONCATENATE 'PO#'lv_po'created wrt PR#'lv_pr INTO lv_subject SEPARATED BY space.

    CONCATENATE 'PO'lv_po'has been created by'lv_ernam_po'On'lv_date_external
                  'for Purchase Request #'lv_pr'in the amount of'lv_sum_c'On'lv_erdat_c
                  'To Vendor #'lv_lifnr'Name:-'lv_name1 INTO lv_body SEPARATED BY space.

    * SUBJECT OF THE MAIL.
         lw_document_data-obj_name = 'MAIL_TO_HEAD'.
         lw_document_data-obj_descr = lv_subject."'Regarding Mail Program by SAP ABAP'.

    * BODY OF THE MAIL
         lw_body_msg = lv_body."'This is body of mail msg.'.
         APPEND lw_body_msg TO lt_body_msg.
         CLEAR lw_body_msg.

    * WRITE PACKING LIST FOR BODY
         DESCRIBE TABLE lt_body_msg LINES lv_tab_lines.
         lw_packing_list-head_start = 1.
         lw_packing_list-head_num = 0.
         lw_packing_list-body_start = 1.
         lw_packing_list-body_num = lv_tab_lines.
         lw_packing_list-doc_type = 'RAW'.
         APPEND lw_packing_list TO lt_packing_list.
         CLEAR lw_packing_list.

    * WRITE PACKING LIST FOR ATTACHMENT
         lw_packing_list-transf_bin = 'X'.
         lw_packing_list-head_start = 1.
         lw_packing_list-head_num = 1.
         lw_packing_list-body_start = 1.

         DESCRIBE TABLE lt_pdf LINES lw_packing_list-body_num.
         lw_packing_list-doc_type = 'PDF'.
         lw_packing_list-obj_descr = 'PDF Attachment'.
         lw_packing_list-obj_name = 'PDF_ATTACHMENT'.
         lw_packing_list-doc_size = lw_packing_list-body_num * 255.
         APPEND lw_packing_list TO lt_packing_list.
         CLEAR lw_packing_list.

    * FILL THE DOCUMENT DATA &GET SIZE OF ATTACHMENT
         lw_document_data-obj_langu = sy-langu.
         READ TABLE lt_pdf INTO lw_pdf INDEX lv_tab_lines.
         lw_document_data-doc_size = ( lv_tab_lines - 1 ) * 255 + strlen( lw_attachment ).

         lw_receivers-receiver = lv_ernam. "<-- change address
         lw_receivers-rec_type = 'B'. " 'U'. " B - for sap mail; U for internet email
         APPEND lw_receivers TO lt_receivers.
    * SEND MAILS TO RECIPIENTS
         CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           EXPORTING
             document_data              = lw_document_data
             put_in_outbox              = 'X'
             commit_work                = 'X'
           IMPORTING
             sent_to_all                = lw_sent_to_all
           TABLES
             packing_list               = lt_packing_list
             contents_bin               = lt_pdf
             contents_txt               = lt_body_msg
             receivers                  = lt_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 .
           MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
         ENDIF.
    endif.


    Thanks people for your support...




    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 26, 2015 at 11:40 AM

    Hi,

    What output type you are using? Standard Output type is NEU. If you use medium as "5" ( External send ) it will send a mail instead of printing. Check transaction NACE.(Application "EF" )

    If you are using custom output type you need to write the code on your own.

    R

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2015 at 11:48 AM

    Purchase order automatically will send to vendor via e-mail after final release, then set Dispatch time as 4 {Send immediately (when saving the application)} in NACE t.code in application EF for your PO output type and save.

    Also maintain condition record for PO output type in t.code: MN04 and keep Dispatch time as 4 {Send immediately (when saving the application)} with other parameters (document type, purchase organization etcu2026.)

    For more check links for details setting e-mail setting for PO

    http://www.architectsap.com/blog/sap/sap-mm-purchasing-send-purchase-order-by-mail-to-vendor-in-sap/

    http://www.sap-img.com/materials/external-send-sending-po-by-email.htm

    Note: You can not able to send the PO immediate after saving PO, because it needs approval. So after final approval, you can send mail.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 27, 2015 at 04:14 AM

    Hi Darshan,

    Better forget about spool programs.

    Implement BADI to trigger the Mail.

    *******Email Declaration***********
    DATA: w_send_request   TYPE REF TO cl_bcs,
           w_recipient      TYPE REF TO if_recipient_bcs,
           w_document       TYPE REF TO cl_document_bcs,
           w_bcs_exception  TYPE REF TO cx_bcs.


    If you want to send attachments add it also while sending the mail.

    It is much easier and good way to trigger the mail.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 30, 2015 at 03:47 PM

    This code is executing after commit work is done!!!!!!.....

    Add comment
    10|10000 characters needed characters exceeded