Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
sebastian_hockmann2
Participant

In OSS note 2073607 two BADIs were described to handle alloy surcharges in an incoming ORDSP Idoc.


  • ME_MMPUR_EINM_CUST with method PROCESS_SEGMENT
  • ME_PROCESS_PO_CUST with method PROCESS_ITEM


SAP does not give any recommendation how to connect these 2 BADIs to get the alloy surcharges
from segment E1EDP05 updated in purchase order position.

I would like to share my experience how i did solve this problem.

First of all we need to implement the method PROCESS_IDOC_DATA_IN in BADI ME_MMPUR_EINM_CUST.

In here we identify the idoc number and send it to MEMORY for later processing in BADI ME_PROCESS_PO_CUST.


data:

 

   ls_edidc type edidc.

   clear ls_edidc.

   loop at im_idoc_control into ls_edidc.

     case ls_edidc-mestyp.

       when 'ORDRSP'.

         if ls_edidc-sndprt = 'LI' and ls_edidc-sndprn = '0002101208'.

           export edidc from ls_edidc to memory id 'EDIDC'.

         else.

         endif.

       when others.

     endcase.

   endloop.


Then we go the BADI ME_PROCESS_PO_CUST and implement method PROCESS_ITEM:

What is happening here ?

1) get purchase order item detail by calling method "get_data" of parameter im_item (IF_PURCHASE_ORDER_ITEM_MM)

2) get condition detail of purchase order item by calling method "get_conditions"

3) import idoc number from previus BADI ME_MMPUR_EINM_CUST from MEMORY

4) Read whole Idoc from Database by FM "IDOC_READ_COMPLETELY"

5) Loop on Idoc Segment E1EDP05 to identify alloy surcharges and update purchase order item and condition by calling
    method "set_data" and "set_condition".

data:

       re_data type mepoitem,

       ls_e1edp05 type e1edp05,

       re_conditions type mmpur_tkomv,

       ls_condition  type komv,

       ls_edidc type edidc,

       lt_edidd type edidd_tt,

       lt_edids type standard table of edids,

       ls_edidd type edidd,

       ls_e1edp01 type e1edp01,

       lt_e1edp05 type standard table of e1edp05.

*-----------------------------------------------------------------------

* get position detail

*-----------------------------------------------------------------------

   call method im_item->get_data

     receiving

       re_data = re_data.

*-----------------------------------------------------------------------

* get conditions

*-----------------------------------------------------------------------

   call method im_item->get_conditions

     importing

       ex_conditions = re_conditions.

*-----------------------------------------------------------------------

* get idoc data from BADI JE-119 (ME_MMPUR_EINM_CUS)

*-----------------------------------------------------------------------

   clear ls_edidc.

   import edidc to ls_edidc from memory id 'EDIDC'.

* read idoc from database

   call function 'IDOC_READ_COMPLETELY'

     exporting

       document_number                = ls_edidc-docnum

*    IMPORTING

*     IDOC_CONTROL                   =

*     NUMBER_OF_DATA_RECORDS         =

*     NUMBER_OF_STATUS_RECORDS       =

    tables

      int_edids                      = lt_edids

      int_edidd                      = lt_edidd

    exceptions

      document_not_exist             = 1

      document_number_invalid        = 2

      others                         = 3

             .

   if sy-subrc <> 0.

   endif.

* idoc segments are processed sequentially

   loop at lt_edidd into ls_edidd.

     case ls_edidd-segnam.

       when 'E1EDP01'.

*       ok, now we have a new position

         clear  ls_e1edp01.

         ls_e1edp01 = ls_edidd-sdata.

       when 'E1EDP05'.

         if ls_e1edp01 is initial.

*       this segment must be assigned to a prior

*       E1EDP01 segment

         else.

           clear ls_e1edp05.

           ls_e1edp05 = ls_edidd-sdata.

*       how we can identity a EDI position ?

           if ls_e1edp05-kschl+0(1) = 'Z'.

             loop at re_conditions into ls_condition.

*

               case ls_condition-kschl.

*

                 when ls_e1edp05-kschl.

                   ls_condition-kbetr = ls_e1edp05-betrg.

                   ls_condition-kwert = ls_e1edp05-krate.

                   modify re_conditions from ls_condition index sy-tabix.

                 when others.

*

               endcase.

             endloop.

           else.

           endif.

         endif.

       when others.

     endcase.

   endloop.

* update condition

   call method im_item->set_conditions

     exporting

       im_conditions = re_conditions.

* update position

   call method im_item->set_data

     exporting

       im_data = re_data.


And so the purchase order position is updated with information from E1EDP05 alloy surcharge information.