Skip to Content
0
Former Member
Feb 16, 2009 at 12:45 PM

email sending condition.

21 Views

Hi All,

Hi

1>I have to send mail to to purchase order creater ,sales order creater & one field in my custom table like this i have to send mail to 3 persons.

but if the flag is set my my custom table for PO creater & SO creater then only mail should go to that person.

2>i have one precondition that check purchase requisition BANFN is based on service order accounting type '0'.

how can I achive above 2 condtions in my code which is below.


*&---------------------------------------------------------------------*
*& Report  ZTEST001
*&---------------------------------------------------------------------*

REPORT  ztest001.

TABLES:ekko,ekpo,usr21,adr6,eban.

DATA: z_data TYPE STANDARD TABLE OF solisti1,
      z_addr TYPE STANDARD TABLE OF sadrud.

DATA: z_str TYPE so_unx_adr.

DATA: l_var1 TYPE char10,
      l_var2 TYPE  char04,
      l_var3 TYPE  char04,
      l_mblnr TYPE mblnr,
      l_mjahr TYPE mjahr,
      l_zeile TYPE mblpo,
      l_ebeln TYPE ebeln,
      l_ebelp TYPE ebelp,
      l_werks TYPE werks_d,
      l_ekgrp TYPE ekgrp,
      l_bsart TYPE bsart,
      l_knttp_po TYPE knttp,
      l_knttp_pr TYPE knttp,
      l_banfn TYPE banfn,
      l_bnfpo TYPE bnfpo,
      l_ernam TYPE ernam,
      l_banme TYPE bname,
      l_persnumber TYPE ad_persnum,
      l_addrnumber TYPE ad_addrnum,
      l_smtp_addr TYPE ad_smtpadr,
      l_lifnr TYPE lifnr,
      l_adrnr TYPE adrnr.

TYPES: BEGIN OF ty_z_mm_wema ,
      werks TYPE werks_d,
      ekgrp TYPE ekgrp,
      bsart TYPE esart,
      knttp_pr TYPE knttp,
      knttp_po TYPE knttp,
      zmailpocre TYPE z_mm_zmailpocre,
      zmailsdlo TYPE z_mm_zmailsdlo,
      smtp_addr TYPE ad_smtpadr,
      END OF ty_z_mm_wema.

DATA: t_z_mm_wema TYPE TABLE OF ty_z_mm_wema,
      w_z_mm_wema TYPE ty_z_mm_wema.

DATA: snast TYPE TABLE OF nast WITH HEADER LINE,
      ernam TYPE ekko-ernam,
      bname TYPE usr21-bname,
      smtp_srch TYPE adr6.

*  l_mblnr = snast-objky(10).
*  l_mjahr = snast-objky+10(4).
*  l_zeile = snast-objky+14(4).
l_mblnr = '5000000585'.
l_mjahr = '2009'.
l_zeile = '0001'.

CLEAR: l_mblnr,l_mjahr,l_zeile,l_ebeln,l_ebelp,l_werks,
        l_ekgrp,l_bsart,l_knttp_po,l_knttp_pr,l_banfn,
        l_bnfpo,l_ernam ,l_banme,l_persnumber,l_addrnumber ,
        l_smtp_addr,l_lifnr,l_adrnr .

SELECT SINGLE ebeln ebelp INTO (l_ebeln, l_ebelp)
 FROM mseg WHERE mblnr = l_mblnr
                        AND mjahr = l_mjahr
                        AND zeile = l_zeile.

SELECT SINGLE werks knttp banfn bnfpo INTO (l_werks, l_knttp_po, l_banfn, l_bnfpo) FROM ekpo
                                     WHERE ebeln = l_ebeln
                                     AND ebelp = l_ebelp.

SELECT SINGLE ekgrp bsart INTO (l_ekgrp, l_bsart) FROM ekko
                      WHERE ebeln = l_ebeln.

SELECT SINGLE knttp INTO l_knttp_pr FROM eban
                   WHERE banfn = l_banfn
                   AND bnfpo = l_bnfpo.

* to get the mail id of po creater
SELECT SINGLE
       a~ernam
       b~persnumber
       b~addrnumber
       c~smtp_addr
       INTO (l_ernam, l_persnumber,l_addrnumber,l_smtp_addr)
       FROM ( ( usr21 AS b INNER JOIN ekko AS a ON b~bname = a~ernam )
       INNER JOIN adr6 AS c ON b~addrnumber = c~addrnumber
                         AND b~persnumber = c~persnumber ).
* to get mail id of SD logistic responsible person
SELECT SINGLE
       ekko~lifnr
       lfa1~adrnr
       adr6~smtp_addr
       INTO (l_lifnr, l_adrnr, l_smtp_addr)
       FROM ( ( ekko INNER JOIN lfa1 ON ekko~lifnr = lfa1~lifnr )
                     INNER JOIN adr6 ON lfa1~adrnr = adr6~addrnumber ).

data: t_THEAD type table of THEAD,
      wa_thead type thead,
      t_TLINES type table of tline.

DATA: g_CHANGED,
      g_prog LIKE SY-REPID,
      g_NEW_CURSOR_COLUMN LIKE SY-TABIX,
      g_NEW_CURSOR_LINE   LIKE SY-TABIX,
      g_tab type sy-tabix.

  DESCRIBE TABLE t_TLINES LINES  g_tab.

  IF g_tab EQ 0 AND NOT t_THEAD IS INITIAL.

CALL FUNCTION 'READ_TEXT'
EXPORTING
      id        = wa_thead-tdid
      language  = wa_thead-tdspras
      name      = wa_thead-tdname
      object    = wa_thead-tdobject
* IMPORTING
*     HEADER    =
TABLES
      lines     = t_tlines
EXCEPTIONS
      id        = 01
      not_found = 04
      object    = 05
*     SAVEMODE  = 06                             " K11K065531
      language  = 02
      name      = 03.
ENDIF.

DESCRIBE TABLE t_tlines LINES  g_tab.

CHECK g_tab GT 0.
g_prog = sy-repid.
* In case of updating SO from MM.
CASE g_prog.
WHEN 'RM_MEPO_GUI'.
  g_prog = 'SAPLMEPO'.
ENDCASE.

CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
     EXPORTING
          endline = g_tab
          header = t_thead
*           INIT = 'X'
*           OPTION_DIALOG = E04
            program = g_prog
*           REPLACE_PROGRAM = E06
*           REPLACE_STANDARD = 'X'
*           REPLACE_SYSTEM = 'X'
*           REPLACE_TEXT = 'X'
*           STARTLINE = E10
     IMPORTING
          changed = g_changed
*           NEWHEADER =
     TABLES
          lines = t_tlines.
          
CALL FUNCTION 'FORMAT_TEXTLINES'
*      EXPORTING
*           CURSOR_COLUMN = E01
*           CURSOR_LINE = E02
*           ENDLINE = E03
*           FORMATWIDTH = E04
*           LINEWIDTH = E05
*           STARTLINE = E06
     IMPORTING
          new_cursor_column = g_new_cursor_column
          new_cursor_line =   g_new_cursor_line
     TABLES
          lines = t_tlines.