Archive

Posts Tagged ‘MM’

SAP MM – BAPI : BAPI_PO_CREATE1

February 3rd, 2010 admin No comments

Exemple d’utilisation de la BAPI :   BAPI_PO_CREATE1 pour la création d’une commande achat (Purchase order).

Je l’utilise depuis un avis QM pour automatiser la création du PO sur ordre de service afin de facturer des coûts de garantie. Pour info : La réception de ce PO est aussi automatisée via la barre d’activités de l’avis et la BAPI  :   BAPI_GOODSMVT_CREATE  .

 - Dans cet exemple on ne crée qu’un seul poste dans le PO

DATA : ws_poheader     TYPE bapimepoheader,
             ws_poheaderx     TYPE bapimepoheaderx,
             wt_poitem            TYPE TABLE OF bapimepoitem,
             ws_poitem            TYPE bapimepoitem,
             wt_poitemx          TYPE TABLE OF bapimepoitemx,
             ws_poitemx          TYPE bapimepoitemx,
             wt_poaccount     TYPE TABLE OF bapimepoaccount,
             ws_poaccount     TYPE bapimepoaccount,
             ws_poaccountx   TYPE bapimepoaccountx,
             wt_poaccountx   TYPE TABLE OF bapimepoaccountx,
             wt_pocondx         TYPE TABLE OF bapimepocondx,
             ws_pocondx        TYPE bapimepocondx,
             wt_pocond           TYPE TABLE OF bapimepocond,
             ws_pocond          TYPE bapimepocond,
             wt_return             TYPE TABLE OF bapiret2,
             ws_return            TYPE bapiret2.

  DATA : wv_waers TYPE bstwa,
              wv_netpr TYPE bprei.

  CONSTANTS : wc_avtf(4) VALUE ’AVTF’,
                           wc_604(10) VALUE ’0060411150′,
                           wc_1000(4) value ’1000′,
                           wc_gar(8)  value ’GARANTIE’.

*… Récupération des données

********************************************
*            Entete                        *
********************************************
  
CLEAR ws_poheader.
  ws_poheader-doc_type = ’NB’.
  ws_poheader-comp_code = wc_avtf.
  ws_poheader-purch_org = wc_avtf.
  ws_poheader-pur_group = ws_zq14-ekgrp.
  ws_poheader-vendor = ws_zq14-lifnr.
  ws_poheader-our_ref = i_viqmel-qmnum.
  ws_poheader-item_intvl = 00010.
  ws_poheader-currency = wv_waers.
  CLEAR ws_poheaderx.
  ws_poheaderx-doc_type = ’X’.
  ws_poheaderx-comp_code = ’X’.
  ws_poheaderx-purch_org = ’X’.
  ws_poheaderx-pur_group = ’X’.
  ws_poheaderx-vendor = ’X’.
  ws_poheaderx-our_ref = ’X’.
  ws_poheaderx-item_intvl = ’X’.
  ws_poheader-currency = ’X’.
*  ws_poheaderx-our_ref = ’X’.
**********************************************
*                Poste                       *
**********************************************
  CLEAR ws_poitem. REFRESH wt_poitem.
  CLEAR ws_poitemx. REFRESH wt_poitemx.
  ws_poitem-plant  = wc_1000.
  ws_poitemx-plant = ’X’.
  ws_poitem-stge_loc  = ws_zq14-lgort.
  ws_poitemx-stge_loc = ’X’.
  ws_poitem-matl_group  = wc_gar.
  ws_poitemx-matl_group = ’X’.
  ws_poitem-short_text  = text-607.
  ws_poitemx-short_text = ’X’.
  ws_poitem-po_item  = ’00010′.
  ws_poitemx-po_item = ’00010′.
  ws_poitemx-po_itemx = ’X’.
  ws_poitem-po_unit  = ’ST’.
  ws_poitemx-po_unit = ’X’.
  ws_poitem-quantity  = ’1′.
  ws_poitemx-quantity = ’X’.
  ws_poitem-acctasscat  = ’F’.
  ws_poitemx-acctasscat = ’X’.

  APPEND ws_poitem TO wt_poitem.
  APPEND ws_poitemx TO wt_poitemx.
*********************************************
*          Onglet imputation                *
*********************************************
 
 CLEAR ws_poaccount. REFRESH wt_poaccount.
  CLEAR ws_poaccountx. REFRESH wt_poaccountx.

  ws_poaccount-po_item  = ’00010′.
  ws_poaccountx-po_item = ’00010′.
  ws_poaccountx-po_itemx = ’X’.
  ws_poaccount-gl_account  = wc_604. 
  ws_poaccountx-gl_account = ’X’.
  ws_poaccount-orderid  = wv_aufnr. 
  ws_poaccountx-orderid = ’X’.
  ws_poaccount-co_area  = ’HVT’.
  ws_poaccountx-co_area = ’X’.
  ws_poaccount-bus_area = ’1′.
  ws_poaccountx-bus_area = ’X’.

  APPEND ws_poaccount  TO wt_poaccount.
  APPEND ws_poaccountx TO wt_poaccountx.

*********************************************
*           Conditions                      *
*********************************************
  CLEAR ws_pocond. REFRESH wt_pocond.
  CLEAR ws_pocondx. REFRESH wt_pocondx.

  ws_pocond-itm_number  = ’00010′.
  ws_pocondx-itm_number = ’00010′.
  ws_pocondx-itm_numberx = ’X’.
  ws_pocond-cond_value  = wv_netpr.
  ws_pocondx-cond_value = ’X’.
  ws_pocond-change_id  = ’I’.
  ws_pocondx-change_id = ’X’.
  ws_pocond-cond_type  = ’PB00′.
  ws_pocondx-cond_type = ’X’.

  APPEND ws_pocond TO wt_pocond.
  APPEND ws_pocondx TO wt_pocondx.

  CALL FUNCTION ‘BAPI_PO_CREATE1′
    EXPORTING
      poheader         = ws_poheader
      poheaderx        = ws_poheaderx
    IMPORTING
      exppurchaseorder = wv_ebeln
    TABLES
      return           = wt_return
      poitem           = wt_poitem
      poitemx          = wt_poitemx
      poaccount        = wt_poaccount
      poaccountx       = wt_poaccountx
      pocond           = wt_pocond
      pocondx          = wt_pocondx.

  CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
    EXPORTING
      wait = ’X‘.

Categories: SAP Tags: , ,

BADI – MB_DOCUMENT_BADI – création document article

October 27th, 2009 admin No 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: , ,