Skip to Content
0
Nov 27, 2009 at 12:55 PM

Post changes of Purchase Order with BADI ME_PROCESS_PO_CUST

721 Views

Hello All,

I have to make changes to a Purchase Order when it is posted. In some cases I have to set the field WEBRE.

What i tried is the BADi - Method ME_PROCESS_PO_CUST~post.

Following Code I entered:

 DATA: position TYPE PURCHASE_ORDER_ITEM,
        tab_pos TYPE PURCHASE_ORDER_ITEMS,
        position_data TYPE mepoitem,
        xcheck TYPE MMPUR_BOOL,
        kopf TYPE REF TO CL_PO_HEADER_HANDLE_MM,
        position_check TYPE mepoitem.

  CLEAR: kopf.
  tab_pos = IM_HEADER->get_items( ).
  xcheck = IM_HEADER->IS_CHANGEABLE( ).
  TRY .
    kopf ?= IM_HEADER.
  CATCH cx_sy_move_cast_error.
  ENDTRY.

  IF kopf is  NOT INITIAL.
     kopf->MY_CUST_FIREWALL_ON = 'X'.
  ENDIF.
LOOP AT tab_pos INTO position.

  position_data = POSITION-item->get_data( ).
  xcheck = POSITION-item->IS_PERSISTENT( ).
  IF position_data-werks(1) EQ 'D' OR
     position_data-werks(1) EQ 'G' OR
     position_data-werks(1) EQ 'P' OR
     position_data-werks(1) EQ '1'.
  ELSE.
    IF position_data-wepos = 'X' and position_data-UMSON is initial.
      position_data-webre = 'X'.
      POSITION-item->set_data( position_data ).   "write data
    ENDIF.
  ENDIF.
   position_check = POSITION-item->get_data( ). " check if it is written
ENDLOOP.

Now my Problem is, that my changes in position_check are ok, but they are not written to database and I don't know why.

I have made the changes with TA ME22n.

I also tried ME_PROCESS_PO_CUSTcheck and ME_PROCESS_PO_CUSTprocess_item. With method process_item it is written to database, but it is not the right point of time. I just want these changes when the purchase order is posted.

Got anybody an idea, maybe another Exit, Badi or what I'm doing wrong?

Best regards,

Ronny