Application Development and Automation 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: 
Read only

Example code of BADI

former_member182337
Participant
0 Likes
2,463

Hello,

I am trying to find out the example code of BADI /BEV1/NE_ITEM_PO so that we can modify the same for our requirement.

In the link, http://help.sap.com/saphelp_erp60_sp/helpdata/en/19/ad1d3a81a1e572e10000000a11405a/frameset.htm
it states that we can re-modify the example code based on our reqirement. When i go in to SE18 i dont find any example code. Can someone help me find out where it could be?

Thanks,

Prem

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,585

The class /BEV1/CL_EX_NE_ITEM_PO contains the sample code for your badi. Create your own implementation refering the code in example class.

2 REPLIES 2
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,586

The class /BEV1/CL_EX_NE_ITEM_PO contains the sample code for your badi. Create your own implementation refering the code in example class.

Read only

0 Likes
1,585

Hi Prem,

Go to SE18 and give the BADI name.

On the right side(down) you will see example classes.Example Implementation for Empties Management BAdI.

Double click on it and then you will find 3 meathods in it

/BEV1/IF_NE_ITEM~ITEM_CREATE

/BEV1/IF_NE_ITEM~ITEM_CHANGE

/BEV1/IF_NE_ITEM~ITEM_ACCOUNT_CHANGE

After you double click on them you can see the coding. Modify the coding as per your requirement by looking into the importing and exporting parameters of the meathods.

For your help i am posting the codes below:

   METHOD /bev1/if_ne_item~item_create.

  DATA: ls_itemdata TYPE mepoitem.

* Get current item data
  CALL METHOD im_item->get_data
    RECEIVING
      re_data = ls_itemdata.

* Set accounting type of line item
  ls_itemdata-knttp = 'K'.          " Cost center accounting

* Set new item data
  CALL METHOD im_item->set_data
    EXPORTING
      im_data = ls_itemdata.

ENDMETHOD.

   METHOD /bev1/if_ne_item~item_account_change.

  DATA: lref_item TYPE REF TO if_purchase_order_item_mm.
  DATA: ls_accountdata TYPE mepoaccounting.
  DATA: ls_itemdata TYPE mepoitem,
        ls_itemdata_fullgood TYPE mepoitem.

* Do nothing if not the first change (i.e. creation)
  CALL METHOD im_account->get_previous_data
*    IMPORTING
*      EX_DATA =
    EXCEPTIONS
      no_data = 1
      OTHERS  = 2.
  IF sy-subrc <> 0.

* Get line item data
    CALL METHOD im_account->get_item
      RECEIVING
        re_item = lref_item.
    CALL METHOD lref_item->get_data
      RECEIVING
        re_data = ls_itemdata.

* Get actual accounting data
    CALL METHOD im_account->get_data
      RECEIVING
        re_data = ls_accountdata.

* Set cost center if needed
    IF ls_accountdata-kostl IS INITIAL.

* Is it a generated empties line item?
      IF ls_itemdata-/bev1/negen_item = mmpur_yes.

        ls_accountdata-kostl = '0000001100'. " Cost center

      ELSE" ls_itemdata-/bev1/negen_item = mmpur_yes

* Get full good line item data
        CALL METHOD im_item_fullgood->get_data
          RECEIVING
            re_data = ls_itemdata_fullgood.

* Is the full good a structured empty?
        IF ls_itemdata_fullgood-/bev1/nestruccat =
                                /bev1/if_ne_item~gc_struccat_struc.

          ls_accountdata-kostl = '0000001000'. " Cost center

        ENDIF" ls_itemdata-/bev1/nestruccat = gc_struccat_struc

      ENDIF" ls_itemdata-/bev1/negen_item = mmpur_yes

* Set new accounting data
      IF NOT ls_accountdata-kostl IS INITIAL.

        CALL METHOD im_account->set_data
          EXPORTING
            im_data = ls_accountdata.

      ENDIF" NOT ls_accountdata-kostl IS INITIAL

    ENDIF" ls_accountdata-kostl IS INITIAL

  ENDIF" sy-subrc <> 0 (CALL METHOD im_account->get_previous_data)

ENDMETHOD.