Skip to Content
avatar image
Former Member

smart form: adding mail content to a mail with a pdf attachment

Hi everyone.

I am sending a smart form via mail as pdf attachment and i need to add two lines of text in that mail.

Can anyone please helo me?

I am sending the mail automatically.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = c_formname

IMPORTING

fm_name = v_fmname

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

ENDIF.

*-- passing generated function name, parameters and i_tables

CALL FUNCTION v_fmname

EXPORTING

is_nast = nast

wa_header = wa_header

user_settings = ' '

control_parameters = lv_control_param

output_options = lv_composer_param

mail_recipient = lv_recipient

mail_sender = lv_sender

mail_appl_obj = lv_mail_app_obj

TABLES

*-- passing internal tables

i_items = i_items[]

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

ENDIF.

Can anyone please guide me?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Apr 07, 2008 at 01:20 PM

    Hi,

    Following will be useful for you...

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = PU_FORMNAME

    IMPORTING

    FM_NAME = L_FNAM

    EXCEPTIONS

    NO_FORM = 1

    NO_FUNCTION_MODULE = 2

    OTHERS = 3.

    IF SY-SUBRC <> 0.

    • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

    ENDIF.

    LWA_CTRLOP-GETOTF = C_X.

    LWA_CTRLOP-NO_DIALOG = C_X.

    LWA_COMPOP-TDNOPREV = C_X.

    CALL FUNCTION L_FNAM

    EXPORTING

    CONTROL_PARAMETERS = LWA_CTRLOP

    OUTPUT_OPTIONS = LWA_COMPOP

    USER_SETTINGS = C_X

    IMPORTING

    JOB_OUTPUT_INFO = LWA_RETURN

    EXCEPTIONS

    FORMATTING_ERROR = 1

    INTERNAL_ERROR = 2

    SEND_ERROR = 3

    USER_CANCELED = 4

    OTHERS = 5.

    IF SY-SUBRC <> 0.

    • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

    ENDIF.

    GIT_OTF[] = LWA_RETURN-OTFDATA[].

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = C_PDF

    MAX_LINEWIDTH = C_132

    IMPORTING

    BIN_FILESIZE = G_DUMMY

    TABLES

    OTF = GIT_OTF

    LINES = LIT_TLINE

    EXCEPTIONS

    ERR_MAX_LINEWIDTH = 1

    ERR_FORMAT = 2

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

    • Convert PDF from 132 to 255.

    CALL FUNCTION 'QCE1_CONVERT'

    TABLES

    T_SOURCE_TAB = LIT_TLINE

    T_TARGET_TAB = LIT_RECORD

    EXCEPTIONS

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

    • Sending mail.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = GWA_DOC_DATA

    PUT_IN_OUTBOX = C_X

    COMMIT_WORK = C_X

    TABLES

    PACKING_LIST = GIT_OBJPACK

    • object_header = gIT_objhead

    CONTENTS_BIN = GIT_OBJBIN

    CONTENTS_TXT = GIT_OBJTXT

    RECEIVERS = GIT_RECEIVER

    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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    REWARD IF USEFUL

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Shree,

      Thank you.

      Actually i am required to use the function module for smart form itself to send the mai.

      I am successful in sending the mai, but i still searching how to add content to the mai.

      The mai is going blank together with the attachment, I need to add one line in the mai to provide information.

      Kind regards,

  • avatar image
    Former Member
    Apr 07, 2008 at 01:37 PM

    Hello Devi, [1.Convert Smartform into PDF and Download.|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/62ae7fcd-0b01-0010-3e9d-a54f26944450] 2.Sending mai with PDF attachement. Check the following program. Declaration part and send_mai subroutine have to be considered. After getting PDF from above link use SEND_MAI portion. in that convert_spool_2_pdf TABLES i_attachment subroutine should not be considered as we already got PDF. just change receiver address and run the program. It runs perfectly. only needs to be clubed.

    REPORT  zvenkat_mai_pdf_attach.
    *--------------------------------------------------------*
    "  Data retrieval related declarations
    *--------------------------------------------------------*
    "Variables
    DATA:
          g_spool_no TYPE TSP01-RQIDENT.
    "Types
    TYPES:
         BEGIN OF t_emp_dat,
           pernr     TYPE pa0001-pernr,
           persg     TYPE pa0001-persg,
           persk     TYPE pa0001-persk,
           plans     TYPE pa0001-plans,
           stell     TYPE pa0001-stell,
         END OF t_emp_dat.
    "Work area
    DATA:
         w_emp_data  TYPE t_emp_dat.
    "Internal tables
    DATA:
         i_emp_data  TYPE STANDARD TABLE OF t_emp_dat.
    *--------------------------------------------------------*
    "  Mai related declarations
    *--------------------------------------------------------*
    "Variables
    DATA :
         g_sent_to_all   TYPE sonv-flag,
         g_tab_lines     TYPE i.
    "Types
    TYPES:
         t_document_data  TYPE  sodocchgi1,
         t_packing_list   TYPE  sopcklsti1,
         t_attachment     TYPE  solisti1,
         t_body_msg       TYPE  solisti1,
         t_receivers      TYPE  somlreci1,
         t_pdf            TYPE  tline.
    "Workareas
    DATA :
         w_document_data  TYPE  t_document_data,
         w_packing_list   TYPE  t_packing_list,
         w_attachment     TYPE  t_attachment,
         w_body_msg       TYPE  t_body_msg,
         w_receivers      TYPE  t_receivers,
         w_pdf            TYPE  t_pdf.
    "Internal Tables
    DATA :
         i_document_data  TYPE STANDARD TABLE OF t_document_data,
         i_packing_list   TYPE STANDARD TABLE OF t_packing_list,
         i_attachment     TYPE STANDARD TABLE OF t_attachment,
         i_body_msg       TYPE STANDARD TABLE OF t_body_msg,
         i_receivers      TYPE STANDARD TABLE OF t_receivers,
         i_pdf            TYPE STANDARD TABLE OF t_pdf.
    *--------------------------------------------------------*
    "Top-of-page.
    *--------------------------------------------------------*
    TOP-OF-PAGE.
      PERFORM top_of_page.
    
    *--------------------------------------------------------*
      "Start-of-selection.
    *--------------------------------------------------------*
    START-OF-SELECTION.
      PERFORM get_data.
      IF i_emp_data[] IS INITIAL.
        PERFORM test_data.
      ENDIF.
      PERFORM do_print_n_get_spoolno.
    
    *--------------------------------------------------------*
      "End-of-selection.
    *--------------------------------------------------------*
    END-OF-SELECTION.
      PERFORM send_mai.
    
    *&---------------------------------------------------------------------*
    *&      Form  top_of_page
    *&---------------------------------------------------------------------*
    FORM top_of_page.
      DATA: inc_colnum TYPE i.
      ULINE.
      inc_colnum = sy-linsz - 60.
      WRITE: / 'Report: ', sy-repid(18).
      WRITE AT 30(inc_colnum) sy-title CENTERED.
      inc_colnum = sy-linsz - 20.
      WRITE: AT inc_colnum 'Page: ', (11) sy-pagno RIGHT-JUSTIFIED.
      WRITE: / 'Client: ', sy-mandt.
      inc_colnum = sy-linsz - 20.
      WRITE: AT inc_colnum 'Date: ', sy-datum.
      WRITE: / 'User  : ', sy-uname.
      inc_colnum = sy-linsz - 60.
      WRITE AT 30(inc_colnum) 'Company Confidential' CENTERED.
      inc_colnum = sy-linsz - 20.
      WRITE: AT inc_colnum 'Time: ', (10) sy-uzeit RIGHT-JUSTIFIED.
      ULINE .
      SKIP.
      ULINE AT /(127).
      WRITE:/ sy-vline,'pernr' COLOR COL_HEADING,13
              sy-vline,'persg' COLOR COL_HEADING,20
              sy-vline,'persk' COLOR COL_HEADING,26
              sy-vline,'plans' COLOR COL_HEADING,35
              sy-vline,'stell' COLOR COL_HEADING,46
              sy-vline.
      ULINE AT /(46).
    ENDFORM.                    "top_of_page
    *&--------------------------------------------------------*
    "Form  get_data from PA0001
    *&--------------------------------------------------------*
    FORM get_data.
    
      SELECT pernr
             persg
             persk
             plans
             stell
       FROM pa0001
       INTO CORRESPONDING FIELDS OF TABLE i_emp_data
       UP TO 4 ROWS.
    
    ENDFORM.                    " get_data
    *&---------------------------------------------------------------------*
    "Form  do_print_n_get_spoolno
    *&---------------------------------------------------------------------*
    FORM do_print_n_get_spoolno.
    
      "Display Output
      LOOP AT i_emp_data INTO w_emp_data .
        AT FIRST.
          PERFORM get_print_parameters.
        ENDAT.
      WRITE:/ sy-vline,w_emp_data-pernr,13
              sy-vline,w_emp_data-persg,20
              sy-vline,w_emp_data-persk,26
              sy-vline,w_emp_data-plans,35
              sy-vline,w_emp_data-stell,46
              sy-vline.
      ULINE AT /(46).
        AT LAST.
          g_spool_no  = sy-spono.
          NEW-PAGE PRINT OFF.
          CALL FUNCTION 'ABAP4_COMMIT_WORK'.
        ENDAT.
      ENDLOOP.
    
    ENDFORM.                    "do_print_n_get_spoolno
    *&----------------------------------------------------------*
    "Form  send_mai
    "---------------
    "PACKING LIST
    "This table requires information about how the data in the
    "tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to
    "be distributed to the documents and its attachments.The first
    "row is for the document, the following rows are each for one
    "attachment.
    *&-----------------------------------------------------------*
    FORM send_mai .
    
      "Subject of the mai.
      w_document_data-obj_name  = 'MAI_TO_HEAD'.
      w_document_data-obj_descr = 'Regarding Mai Program by SAP ABAP'.
    
      "Body of the mai
      PERFORM build_body_of_mai
        USING:space,
              'Hi,',
              'I am fine. How are you? How are you doing ? ',
              'This program has been created to send simple mai',
              'with Subject,Body with Address of the sender. ',
              'Regards,',
              'Venkat.O,',
              'SAP HR Technical Consultant.'.
      "Convert ABAP Spool job to PDF
      PERFORM convert_spool_2_pdf TABLES i_attachment.
    
      "Write Packing List for Body
      DESCRIBE TABLE i_body_msg LINES g_tab_lines.
      w_packing_list-head_start = 1.
      w_packing_list-head_num   = 0.
      w_packing_list-body_start = 1.
      w_packing_list-body_num   = g_tab_lines.
      w_packing_list-doc_type   = 'RAW'.
      APPEND w_packing_list TO i_packing_list.
      CLEAR  w_packing_list.
    
      "Write Packing List for Attachment
      w_packing_list-transf_bin = 'X'.
      w_packing_list-head_start = 1.
      w_packing_list-head_num   = 1.
      w_packing_list-body_start = 1.
      DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
      w_packing_list-doc_type   = 'PDF'.
      w_packing_list-obj_descr  = 'PDF Attachment'.
      w_packing_list-obj_name   = 'PDF_ATTACHMENT'.
      w_packing_list-doc_size   = w_packing_list-body_num * 255.
      APPEND w_packing_list TO i_packing_list.
      CLEAR  w_packing_list.
    
      "Fill the document data and get size of attachment
      w_document_data-obj_langu  = sy-langu.
      READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
      w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
    
      "Receivers List.
      w_receivers-rec_type   = 'U'.  "Internet address
      w_receivers-receiver   = mai_id. "here mai Id should be given
      w_receivers-com_type   = 'INT'.
      w_receivers-notif_del  = 'X'.
      w_receivers-notif_ndel = 'X'.
      APPEND w_receivers TO i_receivers .
      CLEAR:w_receivers.
    
      "Function module to send mai to Recipients
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = w_document_data
          put_in_outbox              = 'X'
          commit_work                = 'X'
        IMPORTING
          sent_to_all                = g_sent_to_all
        TABLES
          packing_list               = i_packing_list
          contents_bin               = i_attachment
          contents_txt               = i_body_msg
          receivers                  = i_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 'Mai has been Successfully Sent.'.
      ELSE.
        WAIT UP TO 2 SECONDS.
        "This program starts the SAPconnect send process.
        SUBMIT rsconn01 WITH mode = 'INT'
                        WITH output = 'X'
                        AND RETURN.
      ENDIF.
    Please here wherever you find MAI or mail you should treat mail.I could not post with that word as part of the community rule. I hope that it helps u . Regards, Venkat.O

    Add comment
    10|10000 characters needed characters exceeded