Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Mail

Former Member
0 Kudos

Hi,

I have introuced 4 mail options in 4 populate menus in the same program with different names.I want to know how to add the mail sending process using a function module.Is it possible to apply a common name for all populate menus and add the action in one perform method by calling that using a condition HOW.The mail should send as a excel format.Below i have given the 4 mail options in 4 selection screens code, and where the perform action for sending mail should be added in the code with above condition.In my Program there are different fields, i have sent here with another program code.Pls clear my doubt.

regards,

Pradeep


selection-screen begin of line.
selection-screen comment 1(25) for field mail_id.
parameters: mail_id(150) type c.
selection-screen end of line.

*selection-screen begin of block b3 with frame title text-036.
selection-screen begin of line.
selection-screen comment 1(25) for field tmail.
parameters: tmail(150) type c.
selection-screen end of line.
*selection-screen end of block b3.
....................
.....................
....................

Sample Mail Code
FORM datecal.
  CONCATENATE mon_yr '01' INTO dtyr.
  CALL FUNCTION 'FTI_FISCAL_YEAR_MONTH_GET'
    EXPORTING
      i_bukrs = '1000'
      i_budat = dtyr        "FTIS_DATUM-INITIAL
    IMPORTING
      e_gjahr = gjahr
      e_monat = monat.
ENDFORM.                    "datecal

*DATA: fname TYPE string,
*        subjtxt TYPE string,
*        bodytxt TYPE string,
*        t_dispo TYPE mdkp-dispo,
*        t_werks TYPE mdkp-plwrk.
**        t_mail  TYPE t024d-usrkey.

*&---------------------------------------------------------------------*
*&      Form  sendmail_excel
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sendmail_excel .

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = 100
      text       = text-025.

  DATA: v_subject TYPE string,
        v_mailid  TYPE string,
        var2 TYPE string,
        var1 TYPE string,
        cmdstr TYPE string,
        v_dt TYPE string.

  vardate = sy-datum.
  vartime = sy-uzeit.

  CONCATENATE vardate vartime INTO v_dt.

  CONCATENATE 'Inv_Val_Rep' v_dt '.html' INTO fheader.

  unixcmd = ' '.
  CLEAR itab_cmd.
  unixcmd = 'mkdir /usr/sap/tmp/inv_val'.
  CALL 'SYSTEM' ID 'COMMAND' FIELD  unixcmd
       ID 'TAB'   FIELD  itab_cmd-*sys*.
  CLEAR itab_cmd.

  perform set_text_date.

  CONCATENATE '"' text-024 ' ' return_date '"'   INTO v_subject SEPARATED BY space.

  CONCATENATE e_file1 fheader INTO h_file.
  OPEN DATASET h_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.


    var = return_date.

  IF total = 'X'.
    CLEAR post.

    CONCATENATE '<html><head><title>' v_subject '</title></head><table border=1 bordercolor=black>' INTO post.
    TRANSFER post TO h_file.

    CLEAR post.

    CONCATENATE  '<b>' text-030 '</b>' text-026 text-024 ' ' return_date'</td></b></td></tr>' INTO post SEPARATED BY space.

    TRANSFER post TO h_file.

    CLEAR post.

    CONCATENATE '<tr><th>slno</th><th>' text-006 '</th><th>' text-007 '</th><th>' text-008 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE  '<th>' text-009 '</th><th>' text-010 '</th><th>' text-029 '</th><th>' text-011 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-012 '</th><th>' text-013 '</th><th>' text-014 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-015 '</th><th>' text-016 '</th><th>' text-017 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-018 '</th><th>' text-019 '</th><th>' text-020 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-021 '</th><th>' text-022 '</th><th>' text-023 '</th></tr>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.

  ELSEIF exfou = 'X'.
    TRANSFER '<html><head><title>' TO h_file.
    TRANSFER v_subject TO h_file.
    TRANSFER '</title></head><table border=1 bordercolor=black>' TO h_file.
    CLEAR post.

    CONCATENATE '<b>' text-030 '</b>' text-027 text-024 ' ' return_date'</b></td></tr>' INTO post SEPARATED BY space.

    TRANSFER post TO h_file.

    CLEAR post.

    CONCATENATE '<tr><th>slno</th><th>' text-006 '</th><th>' text-007 '</th><th>' text-008 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE  '<th>' text-009 '</th><th>' text-010 '</th><th>' text-029 '</th><th>' text-011 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-012 '</th><th>' text-013 '</th><th>' text-014 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-015 '</th><th>' text-016 '</th><th>' text-017 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-018 '</th><th>' text-019 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-021 '</th><th>' text-022 '</th><th>' text-023 '</th></tr>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
  ELSE.
    TRANSFER '<html><head><title>' TO h_file.
    TRANSFER v_subject TO h_file.
    TRANSFER '</title></head><table border=1 bordercolor=black>' TO h_file.
    CLEAR post.

    CONCATENATE '<b>' text-030 '</b>' text-028 text-024 ' ' return_date'</b></td></tr>' INTO post SEPARATED BY space.

    TRANSFER post TO h_file.

    CLEAR post.

    CONCATENATE '<tr><th>slno</th><th>' text-006 '</th><th>' text-007 '</th><th>' text-008 '</th>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.
    CONCATENATE '<th>' text-020 '</th><th>' text-023 '</th></tr>' INTO post.
    TRANSFER post TO  h_file.
    CLEAR post.

  ENDIF.

  CLOSE DATASET h_file.

  CONCATENATE e_file1 fheader INTO h_file.

  OPEN DATASET h_file FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  LOOP AT it4 INTO wa_it2.


    post = '<tr><td>'.
    TRANSFER post TO h_file.

    post = wa_it2-slno.
    TRANSFER post TO h_file.

    post = '</td><td>'.
    TRANSFER post TO h_file.

    post = wa_it2-category.
    TRANSFER post TO h_file.

    post = '</td><td>'.
    TRANSFER post TO h_file.

    post = wa_it2-bkbez.
    TRANSFER post TO h_file.

    post = '</td><td>'.
    TRANSFER post TO h_file.

    post = wa_it2-mtart.
    TRANSFER post TO h_file.

    post = '</td><td>'.
    TRANSFER post TO h_file.


    IF total = 'X'.

      post = wa_it2-bd01_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-du00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-du04_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd03_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd09_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd02_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd04_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-pl01_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd05_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd06_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd07_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-fd00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-iwh00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-rwh00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-tot_val.
      TRANSFER post TO h_file.

    ELSEIF exfou = 'X'.

      post = wa_it2-bd01_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-du00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-du04_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd03_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd09_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd02_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd04_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-pl01_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd05_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd06_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd07_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-bd00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-iwh00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-rwh00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-tot_val.
      TRANSFER post TO h_file.

    ELSE.
      post = wa_it2-fd00_val.
      TRANSFER post TO h_file.

      post = '</td><td>'.
      TRANSFER post TO h_file.

      post = wa_it2-tot_val.
      TRANSFER post TO h_file.

      post = '</td></tr>'.
      TRANSFER post TO h_file.
    ENDIF.
  ENDLOOP.

  CLOSE DATASET h_file.

  OPEN DATASET h_file FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  TRANSFER '</table></html>' TO h_file.
  CLOSE DATASET h_file.

****Mail Sending from Shell
  unixcmd = ' '.
  CLEAR itab_cmd.

  CONCATENATE 'Inv_Val_Rep' v_dt '.html' INTO var1.
  CONCATENATE var1 'Inv_Val_Rep' INTO var1 SEPARATED BY space.
  CONCATENATE var1 v_dt '.xls' INTO var1.
  CONCATENATE 'uuencode /usr/sap/tmp/inv_val/' var1 INTO var2 ."SEPARATED BY space.
  CONCATENATE var2 '|mail -s' INTO var2 SEPARATED BY space.


* For Subject of the mail
* For mail id
  CONCATENATE t_mail ' ' INTO v_mailid.

* For entire syntax
* CONCATENATE 'uuencode /usr/sap/tmp/mrp_run/mrp_run.html mrp_run.xls |mail -s' v_subject v_mailid INTO cmdstr SEPARATED BY space.

  CONCATENATE var2 v_subject v_mailid INTO cmdstr SEPARATED BY space.

  unixcmd = cmdstr.

*For executing the command

  CALL 'SYSTEM' ID 'COMMAND' FIELD  unixcmd
       ID 'TAB'   FIELD  itab_cmd-*sys*.
  CLEAR itab_cmd.

  unixcmd = ' '.
  CLEAR itab_cmd.

  FREE: var1, var2,cmdstr.

  CONCATENATE 'rm' '/usr/sap/tmp/inv_rep/Inv_Val_Rep'  INTO var1 SEPARATED BY space.
  CONCATENATE var1 v_dt '.html' INTO var1.

  unixcmd = var1.

  CALL 'SYSTEM' ID 'COMMAND' FIELD  unixcmd
       ID 'TAB'   FIELD  itab_cmd-*sys*.
  CLEAR itab_cmd.

  FREE: var1, var2,cmdstr.

  CONCATENATE 'rm' 'Inv_Val_Rep'  INTO var1 SEPARATED BY space.
  CONCATENATE var1 v_dt '.xls' INTO var1.

  unixcmd = var1.

  CALL 'SYSTEM' ID 'COMMAND' FIELD  unixcmd
       ID 'TAB'   FIELD  itab_cmd-*sys*.
  CLEAR itab_cmd.

  FREE: var1, var2,cmdstr.

ENDFORM.                    " co_blowup_excel

*&---------------------------------------------------------------------*
*&      Form  add_sortseq
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SPOS       text
*      -->P_FIELDNAME  text
*      -->P_TABNAME    text
*      -->P_SORT       text
*      -->P_SUBTOTAL   text
*----------------------------------------------------------------------*
FORM add_sortseq  USING    p_spos      TYPE alvdynp-sortpos
                           p_fieldname TYPE slis_fieldname
                           p_tabname   TYPE slis_tabname
                           p_sort      TYPE alvdynp-sortup
                           p_subtotal  TYPE alvdynp-subtotals.

  w_sort-spos = p_spos.                           " Sort order
  w_sort-fieldname = p_fieldname.
  w_sort-tabname = p_tabname.
  w_sort-up = p_sort.
  w_sort-subtot = p_subtotal.                      " Sub total allowed
  w_sort-comp = 'X'.
  w_sort-expa = ''.


  APPEND w_sort TO it_sort.
  CLEAR w_sort.

ENDFORM.                    "add_sortseq

FORM set_text_date.

DATA: month(9),
      year(4).

CASE mon_yr+4(2).

WHEN '01'.
  month = 'January'.

WHEN '02'.
  month = 'February'.

WHEN '03'.
  month = 'March'.

WHEN '04'.
  month = 'April'.

WHEN '05'.
  month = 'May'.

WHEN '06'.
  month = 'June'.

WHEN '07'.
  month = 'July'.

WHEN '08'.
  month = 'August'.

WHEN '09'.
  month = 'September'.

WHEN '10'.
  month = 'October'.

WHEN '11'.
  month = 'November'.

WHEN '12'.
  month = 'December'.

WHEN OTHERS.

ENDCASE.

WRITE mon_yr+0(4) TO year.

CONCATENATE ' ' month ',' year INTO return_date SEPARATED BY space.

CONDENSE return_date.

ENDFORM.

2 REPLIES 2

Former Member
0 Kudos

hi

you can use a function module

'Attp_send_mail'

Thanks.

Former Member
0 Kudos

Which version of SAP are you using? You appear to be bypassing the SAP SMTP interface using SAP Connect and sending using the operating system instead? This makes the whole process extra complicated.

In ECC5 / ECC6 take a look at the class CL_BCS for sending emails. This is well documented in SAP Help, and there is example code in lots of other SDN posts and Blogs.

Andrew