Home > SAP > BADI – MB_DOCUMENT_BADI – création document article

BADI – MB_DOCUMENT_BADI – création document article

October 27th, 2009 admin Leave a comment Go to comments

La badi MB_DOCUMENT_BADI permet de réaliser des traitements à la création d’un document article. Et cela en direct depuis la transaction MIGO ou depuis la BAPI  :  BAPI_GOODSMVT_CREATE ou tous autres moyens.

Dans l’exemple suivant nous allons envoyer un e-mail lors de la création d’un doc.Article sur le magasin ‘XX’ et pour les codes mouvements ‘101′ et ‘622′ (en sachant que par docArticle on a 1 seul mvt et 1 seul magasin).

DATA : ws_ent type sodocchgi1.
DATA : wt_poste type TABLE OF soli,
                ws_poste type soli.
data : ws_mseg type mseg,
            ws_mkpf type mkpf.
 DATA : wv_adr type AD_SMTPADR.
 data : wr_range type range of mseg-BWART,
             ws_range like line of wr_range.
 * initialisation des codes mvt
  ws_range-option = ’EQ’.
  ws_range-sign = ’I’.
  ws_range-low = ’101′.
  append ws_range to wr_range.
  clear ws_range.
  ws_range-option = ’EQ’.
  ws_range-sign = ’I’.
  ws_range-low = ’622′.
  append ws_range to wr_range.

loop at xmkpf into ws_mkpf .

read table xmseg into ws_mseg with key mblnr = ws_mkpf-mblnr

                                                              mjahr = ws_mkpf-mjahr. 

  if sy-subrc = 0 and ws_mseg-BWART in wr_range and ws_mseg-lgort = ’XX’.

  * Entete du mail
       CLEAR ws_ent.
      ws_ent-obj_descr = text-001.
      ws_ent-obj_name = ’MAIL’.
      ws_ent-sensitivty = ’O’.

* Corps du mail
      clear ws_poste.      
       …      APPEND ws_poste to wt_poste.

* Fonction spécifique d’envoi d’un mail

      wv_adr = ‘contact.sapdev@gmail.com’.
      CALL FUNCTION ’Z_QM_MAIL’
        EXPORTING
          WS_ENTETE = ws_ent
          MAIL              = wv_adr
        TABLES
          WT_POSTE  = wt_poste
        EXCEPTIONS
          ERROR     = 1
          OTHERS    = 2.
  endif.

endloop.

Categories: SAP Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.