How to Send Custom Purchase Order Form Directly to the Vendor?

How to Send Custom Purchase Order Form Directly to the Vendor?

The cycle stream to accomplish the equivalent is : Let’s see practical steps on How to Send Custom Purchase Order Form Directly to the Vendor?

1. Make a Result Type for the Buy Request with ‘Outer Send’ medium in ME22N

2. Select the Result Type and go to Additional Information.
Select either ‘Send with application own exchange’ to have the choice to audit the report prior to sending or select ‘Send Quickly’ to send email straightforwardly on Save.

3. Click Save to save the result type and to set off the email.
Assuming you picked ‘Send with application own exchange’, go to ME9F – > Open the record – > Select the PO and snap Result Message to set off the email.


Assuming you picked ‘Send Right away’, email would set off upon save. Go to SOST to see email set off.

Detailed Steps :

1. Go to NACE transaction to create a custom output type and assign your PO form and its program in ‘Processing Routine’

2. Add outer send as ‘Medium’, your zprogram’s name in ‘Program’, a subroutine in your zprogram in ‘Program’s Structure Schedule’, your PO structure’s name in ‘PDF/Smartform Structure’ and pdf in ‘Type’

or then again you can utilize Standard PO structure in light of your necessity or need.

3. Make a custom program to set off PO structure and join it to an email to the seller.
The rationale is to set off PO structure’s FM and get the PO structure information from the FM’s Bringing in boundaries, convert it to a paired table and add it as connection to the email. See the code underneath

REPORT zprogram.

INCLUDE rvadtabl. "standardinclude, needed for getting objky from me22n
DATA: gv_fm_name TYPE rs38l_fnam, " FM Name
       gs_fp_docparams TYPE sfpdocparams,
       gs_fp_outputparams TYPE sfpoutputparams.
Data: gv_purdoc_no type ekko-ebeln,
      gv_ldest     type char4.
CONSTANTS : gv_form_name TYPE fpname VALUE 'YOUR CUSTOM FORM NAME',
            gc_printprev type string VALUE 'PREVOUTPUT'.

FORM zsubroutine USING uv_retco LIKE sy-subrc "return code
                           uv_screen TYPE c.
  PERFORM display CHANGING uv_retco. "if output successfull, need to change return code from 999.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form display
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- ENT_RETCO
*&---------------------------------------------------------------------*
FORM display  CHANGING cv_retco TYPE sy-subrc.

  IF sy-ucomm = gc_printprev."'PREVOUTPUT'
    gs_fp_outputparams-nodialog = ''.
    gs_fp_outputparams-preview  = abap_true.
  ELSE.
    gs_fp_outputparams-nodialog = abap_true.
    gs_fp_outputparams-preview  = ''.
    gs_fp_outputparams-reqnew   = abap_true.
    gs_fp_outputparams-getpdf   = abap_true.
    IF nast-dimme = abap_true. 
      gs_fp_outputparams-reqimm   = abap_true.
    ENDIF.
  ENDIF.

  DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
  DATA: lt_message_body TYPE bcsy_text VALUE IS INITIAL,
        lo_document     TYPE REF TO cl_document_bcs VALUE IS INITIAL.
  DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
  DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL.
  DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
  DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL,
        lw_return         TYPE bapiret2.

  DATA: lw_formoutput TYPE fpformoutput,
        lt_binarytab  TYPE solix_tab,
        lv_sub        TYPE so_obj_des,
        lv_in_update TYPE i.

  CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
      ie_outputparams = gs_fp_outputparams
    EXCEPTIONS
      cancel          = 
      usage_error     = 2
      system_error    = 3
      internal_error  = 4
      OTHERS          = 5.
  IF sy-subrc <> 0.

    CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
      EXPORTING
        msg_arbgb = sy-msgid
        msg_nr    = sy-msgno
        msg_ty    = sy-msgty
        msg_v1    = sy-msgv1
        msg_v2    = sy-msgv2
        msg_v3    = sy-msgv3
        msg_v4    = sy-msgv4
      EXCEPTIONS
        OTHERS    = 0.

  ENDIF.
**
  TRY.
      CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
        EXPORTING
          i_name     = gv_form_name 
        IMPORTING
          e_funcname = gv_fm_name.
      "Exception handling
    CATCH cx_fp_api_internal.
    CATCH cx_fp_api_repository.
    CATCH cx_fp_api_usage.
  ENDTRY.

  cv_retco = 0.

  gv_purdoc_no = nast-objky. "objky contains purchase doc number

  CALL FUNCTION gv_fm_name 
    EXPORTING
      iv_purdoc_no       = gv_purdoc_no
    IMPORTING
      /1bcdwb/formoutput = lw_formoutput
    EXCEPTIONS
      usage_error        = 1
      system_error       = 2
      internal_error     = 3
      OTHERS             = 4.

  IF sy-subrc = 0.

    CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
      EXPORTING
        msg_arbgb = 'ZSCM'
        msg_nr    = '022'
        msg_ty    = 'S'
*       MSG_V1    = TEXT-001
      EXCEPTIONS
        OTHERS    = 0.
  ELSE.

    CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
      EXPORTING
        msg_arbgb = sy-msgid
        msg_nr    = sy-msgno
        msg_ty    = sy-msgty
        msg_v1    = sy-msgv1
        msg_v2    = sy-msgv2
        msg_v3    = sy-msgv3
        msg_v4    = sy-msgv4
      EXCEPTIONS
        OTHERS    = 0.

  ENDIF.

  CALL FUNCTION 'FP_JOB_CLOSE'
    EXCEPTIONS
      usage_error    = 1
      system_error   = 2
      internal_error = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.

"Convert Form Output to Binary table to be added as email attachment
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = lw_formoutput-pdf
*     APPEND_TO_TABLE       = ' '
*   IMPORTING
*     OUTPUT_LENGTH         =
    TABLES
      binary_tab = lt_binarytab.

  SELECT SINGLE ekko~ebeln, ekpo~ebelp, ekko~lifnr, ekpo~werks, ekko~bedat FROM ekko
    INNER JOIN ekpo
    ON ekko~ebeln = ekpo~ebeln
    INTO @DATA(lw_povendor)
    WHERE ekko~ebeln = @gv_purdoc_no
      AND ekpo~loekz = ''.

  IF sy-subrc = 0.

    "Here you can create a Custom Table to maintain email data for each Vendor. I am fetching Email To, Email Cc, Email From and Subject Line that is maintained for that PO's vendor

    SELECT SINGLE * FROM zvendoremaildatatable INTO @DATA(lw_vendordetails)
      WHERE lifnr = @lw_povendor-lifnr.
    IF sy-subrc = 0.

      lv_sub = lw_vendordetails-zsubject.
      "You can edit the subject line with PO data dynamically       data(lv_bedat_formatted) = |{ lw_povendor-bedat+4(2) }| && |/| && |{ lw_povendor-bedat+6(2) }|.
      REPLACE FIRST OCCURRENCE OF 'mmdd' IN lv_sub WITH lv_bedat_formatted. "lw_povendor-bedat
      REPLACE FIRST OCCURRENCE OF '&&' IN lv_sub WITH gv_purdoc_no.

      lo_send_request = cl_bcs=>create_persistent( ).

      "Add email body  APPEND 'Thanks,' TO lt_message_body.
       APPEND 'Bhavya Kariwala' TO lt_message_body.

      lo_document = cl_document_bcs=>create_document(
                                      i_type = 'RAW'
                                      i_text = lt_message_body
                                      i_subject = lv_sub ).
      DATA(lv_attachment_name) = |PO#| && |{ gv_purdoc_no }| && | Form|.
      TRY.

          lo_document->add_attachment(
                        EXPORTING
                          i_attachment_type = 'pdf'
                          i_attachment_subject = CONV sood-objdes( lv_attachment_name )
*                   I_ATTACHMENT_SIZE =
*                   I_ATTACHMENT_LANGUAGE = SPACE
*                   I_ATT_CONTENT_TEXT =
*                   I_ATTACHMENT_HEADER =
                          i_att_content_hex = lt_binarytab ).

        CATCH cx_document_bcs INTO lx_document_bcs.

      ENDTRY.

      lo_send_request->set_document( lo_document ).

      "Set sender
      lo_sender = cl_sapuser_bcs=>create( sy-uname ).
      lo_sender = cl_cam_address_bcs=>create_internet_address( CONV adr6-smtp_addr(  lw_vendordetails-zemail_from ) ).

      lo_send_request->set_sender(
                        EXPORTING
                          i_sender = lo_sender ).

      "Set recipient
"I have maintained multiple email addresses for a vendor separated by ';', so it's now been put into an internal table to be looped through.
      SPLIT lw_vendordetails-zemail_to AT ';' INTO TABLE DATA(lt_emailto).
      SPLIT lw_vendordetails-zemail_cc AT ';' INTO TABLE DATA(lt_emailcc).

      LOOP AT lt_emailto INTO DATA(lw_emailto).
*        TRY.
          lo_recipient = cl_cam_address_bcs=>create_internet_address( CONV adr6-smtp_addr( lw_emailto ) ).
          lo_send_request->add_recipient(
                            EXPORTING
                              i_recipient  = lo_recipient                 " Recipient of Message
                            i_express    = abap_true                 " Send As Express Message
*                        i_copy       =                  " Send Copy
*                        i_blind_copy =                  " Send As Blind Copy
*                        i_no_forward =                  " No Forwarding
                          ).
*        CATCH cx_send_req_bcs. " BCS: Send Request Exceptions
*        ENDTRY.
      ENDLOOP.

      LOOP AT lt_emailcc INTO DATA(lw_emailcc).
*        TRY.
            lo_recipient = cl_cam_address_bcs=>create_internet_address( CONV adr6-smtp_addr( lw_emailcc ) ).
            lo_send_request->add_recipient(
                              EXPORTING
                                i_recipient  = lo_recipient                 " Recipient of Message
                              i_express    =  abap_true                " Send As Express Message
                                i_copy       = abap_true                  " Send Copy
*                    i_blind_copy =                  " Send As Blind Copy
*                    i_no_forward =                  " No Forwarding
                            ).
*        CATCH cx_send_req_bcs. " BCS: Send Request Exceptions
*        ENDTRY.
      ENDLOOP.

      "Send email
      lo_send_request->send(
                        EXPORTING
                          i_with_error_screen = 'X'
                        RECEIVING
                          result = lv_sent_to_all ).
"Check to see if email was triggered in UPDATE TASK
      CALL FUNCTION 'TH_IN_UPDATE_TASK'
       IMPORTING
         IN_UPDATE_TASK       = lv_in_update
                .
      IF lv_in_update <> 1.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   = abap_true
          IMPORTING
            return = lw_return.
      endif.

    ENDIF.
  ENDIF.
ENDFORM.

4. Furthermore, as consumed in the code above, you can make a table to keep up with Email Information for every Merchant. You can make a Table Upkeep Generator to keep up with sections against every Seller so this interaction can turn out to be more robotized.

Hope you got the How to Send Custom Purchase Order Form Directly to the Vendor?

thanks! have a good day.

 

YOU MAY LIKE THIS

Is SAP ABAP a High Paying Job?

SAP ABAP Consultant Trainer

Your Definitive Guide to Becoming a SAP ABAP Developer

WhatsApp WhatsApp us