Sending Adobe form as email to external user in ABAP

                                Refer Introduction to sending adobe form as email

                                 Refer -  Adobe to print PO details

                                 Refer  Call adobe form in Report


    1. Goto T-code SE38.

    2. Give program name click on create.

    3. Write code.

    

    REPORT yr_ab_send_email_extrnl_adobe.

    DATA: lr_outparam TYPE sfpoutputparams,
          lr_result   TYPE sfpjoboutput,
          lf_funcname TYPE funcname.
    DATA: lr_formout       TYPE fpformoutput,
          lt_binary        TYPE solix_tab,
          lo_bcs           TYPE REF TO cl_bcs,
          lo_externaluser  TYPE REF TO cl_cam_address_bcs,
          lo_externaluser1 TYPE REF TO cl_cam_address_bcs,
          lt_text          TYPE soli_tab,
          lr_text          TYPE soli,
          lo_document_bcs  TYPE REF TO cl_document_bcs,
          lf_subject       TYPE sood-objdes,
          lf_result        TYPE boolean.
    PARAMETERS: p_ebeln TYPE ebeln.

    lr_outparam-preview = 'X'.
    lr_outparam-nodialog = 'X'.
    lr_outparam-dest = 'LP01'.
    * 1. Get the PDF content of adobe form.
    lr_outparam-getpdf = 'X'.

    CALL FUNCTION 'FP_JOB_OPEN'
      CHANGING
        ie_outputparams = lr_outparam
      EXCEPTIONS
        cancel          = 1
        usage_error     = 2
        system_error    = 3
        internal_error  = 4
        OTHERS          = 5.

    CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
      EXPORTING
        i_name     = 'YL_AB_PURCHASE_ORDER'
      IMPORTING
        e_funcname = lf_funcname.

    CALL FUNCTION lf_funcname
      EXPORTING
    *   /1BCDWB/DOCPARAMS  =
        p_ebeln            = p_ebeln
      IMPORTING
        /1bcdwb/formoutput = lr_formout
      EXCEPTIONS
        usage_error        = 1
        system_error       = 2
        internal_error     = 3
        OTHERS             = 4.
    * 2. Convert the PDF from rawstring to binary format.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = lr_formout-pdf
      TABLES
        binary_tab = lt_binary.

    * 3. Create send request.
    TRY.
        CALL METHOD cl_bcs=>create_persistent
          RECEIVING
            result = lo_bcs.
      CATCH cx_send_req_bcs.
    ENDTRY.

    * 4. Create SAP user/external user.
    TRY.
        CALL METHOD cl_cam_address_bcs=>create_internet_address
          EXPORTING
            i_address_string = 'XXXXXXXXX@GMAIL.COM'
    *       i_address_name   =
    *       i_incl_sapuser   =
          RECEIVING
            result           = lo_externaluser.
      CATCH cx_address_bcs.
    ENDTRY.
    TRY.
        CALL METHOD cl_cam_address_bcs=>create_internet_address
          EXPORTING
            i_address_string = 'AJAYVARIKALLU@GMAIL.COM'
    *       i_address_name   =
    *       i_incl_sapuser   =
          RECEIVING
            result           = lo_externaluser1.
      CATCH cx_address_bcs.
    ENDTRY.

    * 5. Add the recipient.
    TRY.
        CALL METHOD lo_bcs->add_recipient
          EXPORTING
            i_recipient = lo_externaluser.
    *    i_express    =
    *    i_copy       =
    *    i_blind_copy =
    *    i_no_forward =

      CATCH cx_send_req_bcs.
    ENDTRY.

    TRY.
        CALL METHOD lo_bcs->add_recipient
          EXPORTING
            i_recipient = lo_externaluser1
    *       i_express   =
            i_copy      = 'X'.
    *    i_blind_copy =
    *    i_no_forward =

      CATCH cx_send_req_bcs.
    ENDTRY.

    * 6. Create document.
    lr_text-line = 'Dear user,'.
    APPEND lr_text TO lt_text.
    CLEAR lr_text.
    lr_text-line = ' '. APPEND lr_text TO lt_text. CLEAR lr_text.
    lr_text-line = 'Please find the below Po details PDF..'.
    APPEND lr_text TO lt_text.
    CLEAR lr_text.
    lr_text-line = ' '. APPEND lr_text TO lt_text. CLEAR lr_text.
    lr_text-line = 'Thanks & Regards,'.
    APPEND lr_text TO lt_text.
    CLEAR lr_text.
    lr_text-line = 'Ajay'.
    APPEND lr_text TO lt_text.
    CLEAR lr_text.
    TRY.
        CALL METHOD cl_document_bcs=>create_document
          EXPORTING
            i_type    = 'RAW'
        i_subject = 'ADOBE FORM FOR PO DETAILS'
    *       i_length  =
    *       i_language      = SPACE
    *       i_importance    =
    *       i_sensitivity   =
            i_text    = lt_text
    *       i_hex     =
    *       i_header  =
    *       i_sender  =
    *       iv_vsi_profile  =
    *       iv_vsi_scan_off =
          RECEIVING
            result    = lo_document_bcs.
      CATCH cx_document_bcs.
    ENDTRY.

    *  7. Add attachment
    lf_subject = |{ p_ebeln } PO attachment|.
    TRY.
        CALL METHOD lo_document_bcs->add_attachment
          EXPORTING
            i_attachment_type    = 'PDF'
            i_attachment_subject = lf_subject
    *       i_attachment_size    =
    *       i_attachment_language = SPACE
    *       i_att_content_text   =
            i_att_content_hex    = lt_binary
    *       i_attachment_header  =
    *       iv_vsi_profile       =
    *       iv_vsi_scan_off      =
          .
      CATCH cx_document_bcs.
    ENDTRY.

    *  8. Set the document.
    TRY.
        CALL METHOD lo_bcs->set_document
          EXPORTING
            i_document = lo_document_bcs.
      CATCH cx_send_req_bcs.
    ENDTRY.

    *  9. Activate/deactivate immediate sending.
    TRY.
        CALL METHOD lo_bcs->set_send_immediately
          EXPORTING
            i_send_immediately = 'X'.
      CATCH cx_send_req_bcs.
    ENDTRY.

    * 10. Send.
    TRY.
        CALL METHOD lo_bcs->send
    *  EXPORTING
    *    i_with_error_screen = SPACE
          RECEIVING
            result = lf_result.
      CATCH cx_send_req_bcs.
    ENDTRY.

    IF  lf_result = 'X'.
      COMMIT WORK.
    ENDIF.

    CALL FUNCTION 'FP_JOB_CLOSE'
      IMPORTING
        e_result       = lr_result
      EXCEPTIONS
        usage_error    = 1
        system_error   = 2
        internal_error = 3
        OTHERS         = 4.


Input



Output

    1. Goto T-code SOST or check email.

    



        

                        Refer- Sending Adobe form as email to SAP user


*********************************Thank You******************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).