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: 

Badi ME_PROCESS_REQ_CUST Sample Code required for changing the values

Former Member
0 Kudos

Dear Friends,

I am new to the Badi technology. We would like to populate/change the standard field values, (Purchasing group) during Purchase Requisition creation/change.

Method --> PROCESS_ITEM.

I tried the following code, but system blnaks out all the field values entered during PR creation.

Appreciate, if you could provide me some sample code which can be of help.

Reg

Kumar

-


Sample code----


METHOD if_ex_me_process_req_cust~process_item .

DATA: k_mereqitem TYPE mereq_item,

om_data type mereq_item,

om_datax type mereq_itemx,

k_mereqitem = im_item->get_data( ).

check im_count = 1.

if k_mereqitem-bsart = 'ST' and

k_mereqitem-loekz = ' '.

om_data-pstyp = '5'. " assign default item category code

om_data-bnfpo = k_mereqitem-bnfpo.

om_data-WERKS = k_mereqitem-WERKS.

om_datax-pstyp = 'X'.

call method im_item->set_datax

exporting im_datax = om_datax.

call method im_item->set_data

exporting im_data = om_data.

endif.

ENDMETHOD.

5 REPLIES 5

Former Member
0 Kudos

Below is my sample code in method CHECK.

DATA: i_items TYPE mmpur_requisition_items.

Data: wa_item like line of i_items,

lv_if_item type ref to IF_PURCHASE_REQUISITION_ITEM,

lt_itm_data type MEREQ_ITEM,

lx_itm_data type mereq_itemx.

CALL METHOD im_header->get_items

RECEIVING

re_items = i_items.

loop at i_items into wa_item.

lv_if_item = wa_item-item.

CALL METHOD lv_if_item->get_data

RECEIVING

re_data = lt_itm_data.

CALL METHOD lv_if_item->get_datax

RECEIVING

re_datax = lx_itm_data.

if lt_itm_data-bnfpo <> '00001'.

lt_itm_data-ekgrp = 'A02'.

lx_itm_data-ekgrp = 'X'.

CALL METHOD lv_if_item->SET_DATAX

EXPORTING

IM_DATAX = lx_itm_data.

CALL METHOD lv_if_item->SET_DATA

EXPORTING

IM_DATA = lt_itm_data.

Reward Points if it is useful

Thanks

seshu

0 Kudos

Hi Sashu

Thanks for your prompt response. I tried the given code in check...method. But it does not reset the values.

I think process item method would be right place for resetting the values. As per the given code, im_header is not available in process item method.

The following syntax errors occured when I tried the code in the Process item.

1. IM_HEADER is not available in the Process item method.

2. Endloop and endif statements are missing in the sample code.

3. I believe if lt_itm_data-bnfpo <> '00001' statement should be defined as '00000'?.

Please advise.

Regards

Kumar

Secondly, endloop and endif statements are missing in the given sample code. It is also noticed that some times BADI will go into loop ..when we code any thing in process item method.. do we need to set im_count in this

Appreciate,

0 Kudos

Hi Experts

Could you please provide the solution.

Regards

Kumar

Hi Kumar,

i have not a special solution for your case, but i use this BADI with great effort

As my comments in example are in german lg. i explain in short words what i do:

X) define data

1) select data from base item

1a) header-data

1b) item data (easy)

1c) accounting data

2+3) check field values, post warning message + mostly change values + sometimes set cursor focus on field

Have a look and give me some points if my example increased your BADI knowledge

regards

Jörg

METHOD if_ex_me_process_po_cust~process_item .
* Business-Add-Inn ME_PROCESS_PO_CUST
* Jörg Sauterleute - 23.12.2005
*
* ----------------------------------------------
* Ablauf:
* 1. Datenbschaffung
* 2. Feldänderungen prüfen + Warnung ausgeben
* 3. Feldinhalte prüfen + evtl. ändern u. Hinweis ausgeben

  DATA: ls_mepoitem TYPE mepoitem,
        ls_mepoheader TYPE mepoheader,
        ls_mepoaccounting TYPE mepoaccounting.

* Interfacereferenz auf <if_purchase_order_mm>
  DATA: header_obj TYPE REF TO if_purchase_order_mm.
* Interfacereferenz auf <if_purchase_order_account_mm> über Tabelle
  DATA: it_accountings TYPE purchase_order_accountings, "Tabelle
        accounting_obj TYPE purchase_order_accounting.


* Include für Ausgabe von Meldungen
* im BAdI ME_PROCESS_PO_CUST niemals ABAP-Statement MESSAGE verwenden!
  INCLUDE mm_messages_mac.

* Hilfsvariablen
  DATA: h_change_mepoitem TYPE c,
        h_text TYPE string.

  IF sy-sysid = 'HLT'. break sau. ENDIF.

* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 1. Datenbeschaffung
* ######################################################################

* Kopfdaten
  header_obj = im_item->get_header( ).
  ls_mepoheader = header_obj->get_data( ).

* Positionsdaten
  ls_mepoitem = im_item->get_data( ).

* Kontierungsdaten (Accounting) über Tabelle it_accountings
  it_accountings = im_item->get_accountings( ).
* ...IF eingebaut, weil sonst später Abbruch, wenn sy-subrc <> 0
  IF NOT ls_mepoitem-knttp IS INITIAL.
    LOOP AT it_accountings INTO accounting_obj.
      ls_mepoaccounting = accounting_obj-accounting->get_data( ).
    ENDLOOP.
  ENDIF.


* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 2. Daten prüfen -> Warnmeldung
* ######################################################################

*______________________________________________________________________
* Feld Empfänger (Kontierung) prüfen -> Warnmeldung


  IF ls_mepoheader-ekorg = '1000' AND
     ls_mepoheader-bsart = 'IB'.
    IF NOT ls_mepoitem-knttp IS INITIAL.
      CASE ls_mepoheader-ekgrp.
        WHEN '500' OR '501'.
          IF NOT ls_mepoaccounting-wempf IS INITIAL.
            mmpur_metafield mmmfd_recipient.       "Warenempfänger - Cursor setzen
            mmpur_message_forced 'I' 'ME' '303' text-011 '' '' ''.
* Warnmeldung wieder aus Protokoll entfernen.
            IF ls_mepoaccounting-wempf IS INITIAL.
              mmpur_remove_messages_by_id ls_mepoaccounting-id.
              mmpur_business_obj_id ls_mepoaccounting-id.
            ENDIF.
          ENDIF.

        WHEN OTHERS.
          IF ls_mepoaccounting-wempf IS INITIAL.
            mmpur_metafield mmmfd_recipient.       "Warenempfänger - Cursor setzen
            mmpur_message_forced 'W' 'ME' '303' text-010 '' '' ''.
          ENDIF.
* Warnmeldung wieder aus Protokoll entfernen.
          IF NOT ls_mepoaccounting-wempf IS INITIAL.
            mmpur_remove_messages_by_id ls_mepoaccounting-id.
            mmpur_business_obj_id ls_mepoaccounting-id.
          ENDIF.
      ENDCASE.
    ENDIF.
  ENDIF.

* Ende Feld Empfänger (Kontierung) prüfen -> Warnmeldung

*
* Ende test

* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 3. Positionsdaten prüfen/ändern -> setzen
* ######################################################################
  CLEAR: h_change_mepoitem,
         h_text.

* ______________________________________________________________________
* Kennzeichen Wareneingang prüfen/ändern
*
* Belegart 'NB' immer mit "Wareneingang" wegen Log. Rechnungsprüfung
* Belegart 'IB' immer ohne "Wareneingang" weil Einsatz Workflow
* (Kennzeichen 'WEPOS' setzen/nicht setzen)


  IF NOT ls_mepoitem-knttp IS INITIAL.
    CASE ls_mepoheader-bsart.
      WHEN 'NB'.
* Prüfung ob gesetzt
* Wenn nicht, dann setzen und Daten übergeben
* Cursor auf Metafeld (aus Typgruppe MMMFD) für Fehlerbehandlung
        IF ls_mepoitem-wepos IS INITIAL.
          ls_mepoitem-wepos = 'X'.
          h_change_mepoitem = 'X'.
*           im_item->set_data( EXPORTING im_data = ls_mepoitem ).
          h_text = text-001.
          mmpur_metafield mmmfd_gr_ind .       "WE-Kennzeichen - Cursor setzen
*           message erst später ausführen!
*           mmpur_message_forced 'I' 'ME' '303' text-001 '' '' ''.
        ENDIF.

      WHEN 'IB'.
* Prüfung ob nicht gesetzt
* Wenn doch, dann entfernen und Daten übergeben
* Cursor auf Metafeld (aus Typgruppe MMMFD) für Fehlerbehandlung
        IF NOT ls_mepoitem-wepos IS INITIAL.
          ls_mepoitem-wepos = ' '.
          h_change_mepoitem = 'X'.
*            im_item->set_data( EXPORTING im_data = ls_mepoitem ).
          h_text = text-002.
          mmpur_metafield mmmfd_gr_ind .       "WE-Kennzeichen - Cursor setzen
*           message erst später ausführen!
*           mmpur_message_forced 'I' 'ME' '303' text-002 '' '' ''.
        ENDIF.
    ENDCASE.
  ENDIF.
* Ende Kennzeichen Wareneingang prüfen/ändern

* ______________________________________________________________________
* Kennzeichen aut. WE-Abrech. (Rechnung) prüfen/ändern
* (für autom. Gutschriftsverfahren Verpackungseinkauf)

* Kreditordaten
  DATA: it_lfm1 TYPE TABLE OF lfm1,
        wa_lfm1 TYPE lfm1.

  IF ls_mepoheader-ekorg = '1000' AND
     ls_mepoheader-bsart = 'NB'   OR
     ls_mepoheader-bsart = 'KA'.

    IF ls_mepoitem-xersy IS INITIAL AND
       ls_mepoitem-umson IS INITIAL.                    "kostenlose Lieferung
      SELECT * FROM lfm1 INTO CORRESPONDING FIELDS OF TABLE it_lfm1
               WHERE lifnr = ls_mepoheader-lifnr AND
                     ekorg = ls_mepoheader-ekorg.
      IF sy-subrc = 0.
        READ TABLE it_lfm1 INTO wa_lfm1 INDEX 1.

        IF wa_lfm1-xersy = 'X'.
          ls_mepoitem-xersy = 'X'.
          h_change_mepoitem = 'X'.
*          im_item->set_data( EXPORTING im_data = ls_mepoitem ).
          h_text = text-005.
          mmpur_metafield mmmfd_ers.       " Kennz. aut.WE-Abrechnung - Cursor setzen
*            message erst später ausführen!
*            mmpur_message_forced 'I' 'ME' '303' text-005 '' '' ''.
        ENDIF.
      ENDIF.
    ENDIF.

  ENDIF.
* Ende Kennzeichen aut. WE-Abrech. (Rechnung) prüfen/ändern

* ______________________________________________________________________
* Kennzeichen WE-bezogene Rechnungsprüfung (Rechnung) prüfen/ändern
* (für autom. Gutschriftsverfahren Verpackungseinkauf)

* Kreditordaten bereits deklariert
*  DATA: it_lfm1 TYPE TABLE OF lfm1,
*        wa_lfm1 TYPE lfm1.

  IF ls_mepoitem-knttp IS INITIAL.
* nicht anwenden bei kontierten Bestellungen
    IF ls_mepoitem-pstyp = 0.
* nicht anwenden bei gefülltem Positionstyp (z.B. 'L' = Lohnbearbeitung, Preis 0,00 EUR)

      IF ls_mepoheader-ekorg = '1000' AND
         ls_mepoheader-bsart = 'NB'   OR
         ls_mepoheader-bsart = 'KA'.

        IF ls_mepoitem-webre IS INITIAL AND
           ls_mepoitem-umson IS INITIAL.                    "kostenlose Lieferung
          SELECT * FROM lfm1 INTO CORRESPONDING FIELDS OF TABLE it_lfm1
                   WHERE lifnr = ls_mepoheader-lifnr AND
                         ekorg = ls_mepoheader-ekorg.
          IF sy-subrc = 0.
            READ TABLE it_lfm1 INTO wa_lfm1 INDEX 1.

            IF wa_lfm1-webre = 'X'.
              ls_mepoitem-webre = 'X'.
              h_change_mepoitem = 'X'.
*          im_item->set_data( EXPORTING im_data = ls_mepoitem ).
              h_text = text-006.
              mmpur_metafield mmmfd_gr_based_iv.   "WE-bezogene RP - Cursor setzen
*            message erst später ausführen!
*            mmpur_message_forced 'I' 'ME' '303' text-006 '' '' ''.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

  ENDIF.
* Ende Kennzeichen WE-bezogene Rechnungsprüfung (Rechnung) prüfen/ändern

** ______________________________________________________________________
** Kennzeichen Auftragsbestätigungspflicht prüfen/ändern
** (bisher nur Natec)
*
** Infosatzdaten (Konditionen) deklarieren
** Verweis of Tabelle mit Kopfzeilen immer mit TYPE TABLE OF
*  DATA: it_ekomd TYPE TABLE OF ekomd,
*        wa_ekomd TYPE ekomd.
*
*  IF ls_mepoheader-ekorg = '1300' AND
*     ls_mepoheader-bsart = 'NB'   .
*
*    CALL FUNCTION 'ME_GET_INFORECORD_CONDITIONS'
*      EXPORTING
*        i_ekorg = ls_mepoheader-ekorg
*        i_esokz = '0'                                       " '0' = NB
*        i_infnr = ls_mepoitem-infnr
*        i_lifnr = ls_mepoheader-lifnr
*        i_matkl = ls_mepoitem-matkl
*        i_matnr = ls_mepoitem-matnr
*        i_werks = ls_mepoitem-werks
*      TABLES
*        tekomd  = it_ekomd.
*
*    SORT it_ekomd BY datbi DESCENDING.
*    READ TABLE it_ekomd INTO wa_ekomd INDEX 1.
*
*    CASE ls_mepoheader-ekorg.
*      WHEN '1300'.
**     Anforderung Natec: wenn Infosatz-Kondition
**       a)  leer o. nicht gültig  => AB setzen, wenn fehlt
**       b)  älter       2 Monate  => AB setzen, wenn fehlt
**       c)  nicht älter 2 Monate  => AB entfernen, wenn gesetzt
*
**     Hilfsvariablen
*        DATA: h_vgldat   TYPE sy-datum.   " Vergleichsdatum
*        DATA: h_ergebnis TYPE c.
**     Alter der Infosatzkondition ermitteln.
*        CALL FUNCTION 'CCM_GO_BACK_MONTHS'
*          EXPORTING
*            currdate   = sy-datum
*            backmonths = '002'
*          IMPORTING
*            newdate    = h_vgldat.
*
*        IF wa_ekomd-datbi < sy-datum OR    " gefunden Kondition nicht gültig oder
*           wa_ekomd-datbi IS INITIAL.      " keine Kondition gefunden
*          h_ergebnis = 'a'.
*        ENDIF.
*        IF wa_ekomd-datab < h_vgldat.
*          h_ergebnis = 'b'.
*        ENDIF.
*        IF wa_ekomd-datab > h_vgldat.
*          h_ergebnis = 'c'.
*        ENDIF.
*
**       Prüfung ob nicht gesetzt
*        IF ls_mepoitem-kzabs = ' ' AND
*                  h_ergebnis = 'a' OR
*                  h_ergebnis = 'b' .
*          ls_mepoitem-kzabs = 'X'.
*          h_change_mepoitem = 'X'.       "Merker setzen, geändert wird am Schluss
**               im_item->set_data( EXPORTING im_data = ls_mepoitem ).
*          h_text = text-003.
**               message erst später ausführen!
**               mmpur_message_forced 'I' 'ME' '303' text-004 '' '' ''.
*        ENDIF.
**       Prüfung ob gesetzt
*        IF ls_mepoitem-kzabs = 'X' AND
*           h_ergebnis        = 'c' .
*          ls_mepoitem-kzabs = ' '.
*          h_change_mepoitem = 'X'.       "Merker setzen, geändert wird am Schluss
**               im_item->set_data( EXPORTING im_data = ls_mepoitem ).
*          h_text = text-004.
**               message erst später ausführen!
**               mmpur_message_forced 'I' 'ME' '303' text-003 '' '' ''.
*        ENDIF.
*
*
*    ENDCASE.
*  ENDIF.
** Ende Kennzeichen Auftragsbestätigungspflicht prüfen/ändern


* ______________________________________________________________________
* Bestell-/Bestellpreis-Mengeneinheit prüfen/setzen
  DATA: h_txz01 TYPE mepoitem-txz01.   " Materialkurztext

  IF   ( ls_mepoheader-ekorg = '1000' OR
         ls_mepoheader-ekorg = '1500' ) AND
         ls_mepoheader-bsart = 'IB' AND
     NOT ls_mepoitem-knttp IS INITIAL.

* Vergleichen ob eingegebene Mengeneinheit in Kurztext "avisiert"
    CONCATENATE '(' ls_mepoitem-meins ')' INTO h_txz01.
    IF ls_mepoitem-txz01 CS h_txz01.
      IF NOT ls_mepoitem-meins IS INITIAL.
        mmpur_metafield mmmfd_unit .       "Steuer-Kennz. - Cursor setzen
        mmpur_message_forced 'W' 'ME' '303' 'ME' ls_mepoitem-meins
                                                 text-031 ''.
      ENDIF.
* sonst standarmäßig 'LE' setzen wegen Problemen bei Obligo
    ELSE.
      IF NOT ls_mepoitem-meins = 'LE'.
        ls_mepoitem-meins = 'LE'.
        ls_mepoitem-bprme = 'LE'.
        h_change_mepoitem = 'X'.
*      im_item->set_data( EXPORTING im_data = ls_mepoitem ).
        h_text = text-030.
        mmpur_metafield mmmfd_unit .             "Steuer-Kennz. - Cursor setzen
*      message erst später ausführen!
*      mmpur_message_forced 'I' 'ME' '303' text-030 '' '' ''.
      ENDIF.
    ENDIF.
  ENDIF.
* Ende Bestell-Mengeneinheit prüfen/ändern


* ______________________________________________________________________
* Steuerkennzeichen prüfen/setzen (für EK-Gruppe 500,501)

  IF ls_mepoheader-ekorg = '5000' AND
     ls_mepoitem-matnr IS INITIAL.
    CASE ls_mepoheader-ekgrp.
      WHEN '500' OR '501'.
        IF ls_mepoitem-mwskz IS INITIAL.
          ls_mepoitem-mwskz = 'V4'.
          h_change_mepoitem = 'X'.
*    "      im_item->set_data( EXPORTING im_data = ls_mepoitem ).
*          h_text = text-020.
*          mmpur_metafield mmmfd_tax_code .       "Cursor Steuer-Kennz.
*    "      message erst später ausführen!
*    "      mmpur_message_forced 'I' 'ME' '303' text-020 '' '' ''.
        ENDIF.
    ENDCASE.
  ENDIF.
* Ende Steuerkennzeichen prüfen/ändern
*
*
* ********
* zu 3.
* ______________________________________________________________________
* zum Schluss noch die geänderten mepoitem-xxxx setzen
* + gleiche Meldungen (I ME 303) ausgeben

  IF h_change_mepoitem = 'X'.
    im_item->set_data( EXPORTING im_data = ls_mepoitem ).
  ENDIF.
  IF NOT h_text IS INITIAL.
    mmpur_message_forced 'I' 'ME' '303' h_text '' '' ''.
  ENDIF.

* Ende Daten prüfen/ändern -> setzen
* ####

ENDMETHOD.                    "IF_EX_ME_PROCESS_PO_CUST~PROCESS_ITEM

Former Member
0 Kudos

I ave tried your code..when i m debuuging its shows the change value in debug but the value is not getting updated..please help me i m in so trouble its so urgent..Your help is so much appreciated.

METHOD IF_EX_ME_PROCESS_REQ_CUST~POST.


   DATA I_ITEMS   TYPE  MMPUR_REQUISITION_ITEMS.
   DATA: WA_ITEM LIKE LINE OF I_ITEMS,
   LV_IF_ITEM TYPE REF TO IF_PURCHASE_REQUISITION_ITEM,
   LT_ITM_DATA TYPE MEREQ_ITEM,
   LT_ITM_DATAX TYPE MEREQ_ITEMX.


   DATA : PRIO_FLAG TYPE PRIO_URG,
         INDEX  TYPE SY-TABIX.

   BREAK DEVELOPER.

   CALL METHOD IM_HEADER->GET_ITEMS
     RECEIVING
       RE_ITEMS = I_ITEMS.

   LOOP AT I_ITEMS INTO WA_ITEM.

     INDEX = SY-TABIX .
     LV_IF_ITEM = WA_ITEM-ITEM.



     CALL METHOD LV_IF_ITEM->GET_DATA
       RECEIVING
         RE_DATA = LT_ITM_DATA.



     IF INDEX = 1.
       PRIO_FLAG = LT_ITM_DATA-PRIO_URG .
     ELSE.
       LT_ITM_DATA-PRIO_URG = PRIO_flag.


       CALL METHOD LV_IF_ITEM->SET_DATA
         EXPORTING
           IM_DATA = LT_ITM_DATA.


     ENDIF.

   ENDLOOP.





ENDMETHOD.