Skip to Content
avatar image
Former Member

Send Adobe form as email attachment

Hello Experts,

Recently iu2019m facing a problem regarding Adobe form PDF attachment and sending an e-mail along with the PDF attachment to customer mail id.But when i execute the RFC Function module, in customer side no mail is comming. And when i check the transaction SBWP then i found that the PDF attachment hold only 1KB of data which is not right.For that iu2019m sending my code which i was declared in my program.Can anybody Please help me to overcome this problem?

FORM print_form USING p_disp TYPE char1

drb_mail TYPE char1

p_email LIKE itcpo-tdcovtitle

p_email1 LIKE itcpo-tdcovtitle.

DATA ds_recipient TYPE swotobjid.

CLEAR: dg_funcnam, dg_outputparams.

*--Call generated function module

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

EXPORTING

i_name = c_form

IMPORTING

e_funcname = dg_funcnam.

dg_outputparams-nodialog = 'X'.

dg_outputparams-getpdf = 'X'.

  • Job Open for PDF

CALL FUNCTION 'FPCOMP_JOB_OPEN'

CHANGING

ie_outpar = dg_outputparams

EXCEPTIONS

cancel = 1

usage_error = 2

system_error = 3

internal_error = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

EXIT.

ENDIF.

dg_docparams-langu = 'X'.

dg_docparams-country = 'US'.

dg_docparams-fillable = 'X'.

form CONVERT_PDF_BINARY .

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = FP_FORMOUTPUT-PDF

  • APPEND_TO_TABLE = ' '

  • IMPORTING

  • OUTPUT_LENGTH =

TABLES

BINARY_TAB = t_att_content_hex .

endform. " CONVERT_PDF_BINARY

&----


*& Form MAIL_ATTACHMENT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form MAIL_ATTACHMENT USING p_email LIKE itcpo-tdcovtitle

p_email1 LIKE itcpo-tdcovtitle.

CLASS cl_bcs DEFINITION LOAD.

DATA:

lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.

lo_send_request = cl_bcs=>create_persistent( ).

  • Message body and subject

DATA:

lt_message_body TYPE bcsy_text VALUE IS INITIAL,

lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.

APPEND 'Dear,' TO lt_message_body.

append ' ' to lt_message_body.

APPEND 'Please fill the attached form and send it back to us.'

TO lt_message_body.

append ' ' to lt_message_body.

APPEND 'Thank You,' TO lt_message_body. lo_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = lt_message_body

i_subject = 'Personnel Information Form' ).

DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL. TRY.

lo_document->add_attachment(

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = 'Personnel Information Form'

  • I_ATTACHMENT_SIZE =

  • I_ATTACHMENT_LANGUAGE = SPACE

  • I_ATT_CONTENT_TEXT =

  • I_ATTACHMENT_HEADER =

i_att_content_hex = t_att_content_hex ).

CATCH cx_document_bcs INTO lx_document_bcs.

ENDTRY.

  • Add attachment

  • Pass the document to send request

lo_send_request->set_document( lo_document )."* Create sender

DATA:

lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,

l_send type ADR6-SMTP_ADDR value ' here mail id '.

  • l_send = P_email.

  • l_send = P_email1.

  • lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).

lo_sender = cl_sapuser_bcs=>create( sy-uname ).

  • Set sender

lo_send_request->set_sender(

EXPORTING

i_sender = lo_sender )." Create recipient

DATA:

lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.

  • lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

lo_recipient = cl_cam_address_bcs=>create_internet_address( l_send ).

  • lo_recipient = cl_cam_address_bcs=>create_internet_address( l_send ).

  • Set recipient

lo_send_request->add_recipient(

EXPORTING

i_recipient = lo_recipient

i_express = 'X' ).

  • lo_send_request->add_recipient(

  • EXPORTING

  • i_recipient = lo_recipient

  • i_express = 'X' ).* Send email

DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.

lo_send_request->send(

EXPORTING

i_with_error_screen = 'X'

RECEIVING

result = lv_sent_to_all ).

COMMIT WORK.

message 'The Personnel Information form has been emailed to the Employee' type 'I'.

endform. " MAIL_ATTACHMENT

*--Call Function module

CALL FUNCTION dg_funcnam

EXPORTING

/1bcdwb/docparams = dg_docparams

im_logo = dg_logo

im_user_address = dt_user_address

im_ship_to_addr = dt_imp_data

im_text = ds_text

im_sales_text = dt_sales_text

im_item_data = dt_item_data

IMPORTING

/1BCDWB/FORMOUTPUT = FP_FORMOUTPUT

EXCEPTIONS

usage_error = 1

system_error = 2

internal_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

CALL FUNCTION 'FPCOMP_JOB_CLOSE'

IMPORTING

e_jobresult = l_result

EXCEPTIONS

usage_error = 1

system_error = 2

internal_error = 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.

  • DATA : dl_msg TYPE string.

  • CONCATENATE 'Successfully mailed to' p_email p_email1 INTO dl_msg SEPARATED BY space.

  • IF drb_mail = 'X'.

  • COMMIT WORK.

  • MESSAGE dl_msg TYPE 'I' .

  • MESSAGE i000 WITH 'Successfully mailed to' p_email1.

  • ENDIF.

  • ENDFORM. "print_form

    Could you please any body help me, it's very uregent issue.

    Regards

    Sandeep

    Add comment
    10|10000 characters needed characters exceeded

    • Get RSS Feed

    2 Answers

    • Mar 06, 2012 at 06:02 PM

      I am not sure, what your error is... the way code is over here, is confusing me...

      did you convert your output string to binary string, so that it is able to attach to email.. Use function module ..SCMS_XSTRING_TO_BINARY to do that.

      Thanks,

      Rakesh

      Add comment
      10|10000 characters needed characters exceeded

    • avatar image
      Former Member
      Jul 31, 2013 at 11:25 AM

      *&---------------------------------------------------------------------*

      *& Report  ZGB_ATTACHMENT

      *&

      *&---------------------------------------------------------------------*

      *&

      *&

      *&---------------------------------------------------------------------*

      REPORT  zgb_attachment.

      DATA:

      l_formname        TYPE fpname VALUE 'ZGB_ATTACHMENT',

      l_fm_name         TYPE rs38l_fnam,

      fp_outputparams   TYPE sfpoutputparams,

      fp_docparams      TYPE sfpdocparams,

      fp_formoutput     TYPE fpformoutput.

      DATA:

        t_att_content_hex TYPE solix_tab.

      PARAMETERS: p_pernr TYPE persno.

      START-OF-SELECTION.

        PERFORM get_function_module.

        PERFORM create_document.

        PERFORM convert_pdf_to_binary.

        PERFORM mail_attachment.

      *&---------------------------------------------------------------------*

      *&      Form  GET_FUNCTION_MODULE

      *&---------------------------------------------------------------------*

      *       text

      *----------------------------------------------------------------------*

      *  -->  p1        text

      *  <--  p2        text

      *----------------------------------------------------------------------*

      FORM get_function_module .

        CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

          EXPORTING

            i_name              = l_formname

          IMPORTING

            e_funcname          = l_fm_name

      *     E_INTERFACE_TYPE    =

      *     EV_FUNCNAME_INBOUND =

          .

      ENDFORM.                    " GET_FUNCTION_MODULE

      *&---------------------------------------------------------------------*

      *&      Form  CREATE_DOCUMENT

      *&---------------------------------------------------------------------*

      *       text

      *----------------------------------------------------------------------*

      *  -->  p1        text

      *  <--  p2        text

      *----------------------------------------------------------------------*

      FORM create_document .

      *JOB OPEN

        CALL FUNCTION 'FP_JOB_OPEN'

          CHANGING

            ie_outputparams = fp_outputparams

          EXCEPTIONS

            cancel          = 1

            usage_error     = 2

            system_error    = 3

            internal_error  = 4

            OTHERS          = 5.

        IF sy-subrc <> 0.

      * Implement suitable error handling here

        ENDIF.

        fp_docparams-langu = 'X'.

        fp_docparams-country = 'US'.

        fp_docparams-fillable = 'X'.

        CALL FUNCTION l_fm_name

          EXPORTING

           /1bcdwb/docparams        = fp_docparams

            pernr                    = p_pernr

         IMPORTING

           /1bcdwb/formoutput       = fp_formoutput

      * EXCEPTIONS

      *   USAGE_ERROR              = 1

      *   SYSTEM_ERROR             = 2

      *   INTERNAL_ERROR           = 3

      *   OTHERS                   = 4

                  .

        IF sy-subrc <> 0.

      * Implement suitable error handling here

        ENDIF.

      *JOB CLOSE

        CALL FUNCTION 'FP_JOB_CLOSE'

      *    IMPORTING

      *      e_result       =

          EXCEPTIONS

            usage_error    = 1

            system_error   = 2

            internal_error = 3

            OTHERS         = 4.

        IF sy-subrc <> 0.

      * Implement suitable error handling here

        ENDIF.

      ENDFORM.                    " CREATE_DOCUMENT

      *&---------------------------------------------------------------------*

      *&      Form  CONVERT_PDF_TO_BINARY

      *&---------------------------------------------------------------------*

      *       text

      *----------------------------------------------------------------------*

      *  -->  p1        text

      *  <--  p2        text

      *----------------------------------------------------------------------*

      FORM convert_pdf_to_binary .

        CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

          EXPORTING

            buffer                = fp_formoutput-pdf

      *   APPEND_TO_TABLE       = ' '

      * IMPORTING

      *   OUTPUT_LENGTH         =

          TABLES

            binary_tab            = t_att_content_hex

                  .

      ENDFORM.                    " CONVERT_PDF_TO_BINARY

      *&---------------------------------------------------------------------*

      *&      Form  MAIL_ATTACHMENT

      *&---------------------------------------------------------------------

      FORM mail_attachment .

        CLASS cl_bcs DEFINITION LOAD.

        DATA:

        lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.

        lo_send_request = cl_bcs=>create_persistent( ).

      * Message body and subject

        DATA:

        lt_message_body TYPE bcsy_text VALUE IS INITIAL,

        lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.

        APPEND 'Dear,' TO lt_message_body.

        APPEND ' ' TO lt_message_body.

        APPEND 'Please fill the attached form and send it back to us.'

        TO lt_message_body.

        APPEND ' ' TO lt_message_body.

        APPEND 'Thank You,' TO lt_message_body.

        lo_document = cl_document_bcs=>create_document(

        i_type = 'RAW'

        i_text = lt_message_body

        i_subject = 'Personnel Information Form' ).

        DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.

        TRY.

            lo_document->add_attachment(

            EXPORTING

            i_attachment_type = 'PDF'

            i_attachment_subject = 'Personnel Information Form'

      * I_ATTACHMENT_SIZE =

      * I_ATTACHMENT_LANGUAGE = SPACE

      * I_ATT_CONTENT_TEXT =

      * I_ATTACHMENT_HEADER =

            i_att_content_hex = t_att_content_hex ).

          CATCH cx_document_bcs INTO lx_document_bcs.

        ENDTRY.

      * Add attachment

      * Pass the document to send request

        lo_send_request->set_document( lo_document ).

      * Create sender

        DATA:

        lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,

        l_send TYPE adr6-smtp_addr VALUE 'gaurab.banerji@somewebsite.com'.

      *  lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).

        lo_sender = cl_sapuser_bcs=>create( sy-uname ).

      * Set sender

        lo_send_request->set_sender(

        EXPORTING

        i_sender = lo_sender ).

      * Create recipient

        DATA:

        lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.

      *  lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

        lo_recipient = cl_cam_address_bcs=>create_internet_address( l_send ).

      ** Set recipient

        lo_send_request->add_recipient(

        EXPORTING

        i_recipient = lo_recipient

        i_express = 'X' ).

      *  lo_send_request->add_recipient(

      *  EXPORTING

      *  i_recipient = lo_recipient

      *  i_express = 'X' ).

      * Send email

        DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.

        lo_send_request->send(

        EXPORTING

        i_with_error_screen = 'X'

        RECEIVING

        result = lv_sent_to_all ).

        COMMIT WORK.

        MESSAGE 'The Personnel Information form has been emailed to the Employee' TYPE 'I'.

      ENDFORM.                    " MAIL_ATTACHMENT

      Add comment
      10|10000 characters needed characters exceeded