BAdIs and their relevance:

  • /SCWM/EX_MSL_FILL_PRD_INB - Inbound delivery
  • /SCWM/EX_MSL_FILL_FD - Outbound delivery
  • /SCWM/EX_MSL_FILL_PRD_OUTB - Outbound delivery order

Example code for outbound delivery order :

  method /SCWM/IF_EX_MSL_FILL~DET_ERP_MESSAGES.
    BREAK-POINT ID ZEWM.

* This class contains an example for creating custom messages
* about deliveries.
* How does it work?
* The class works with the business object of the document
* already in memory, so the previous and current version of
* the delivery items can be compared. For every item where
* the quantity has been altered, a new message log entry is
* created: OBDLV_CHANGE. After saving the delivery PPF
* processes these messages and send an ERP update message
* for every changed item.

*/M.Ozgur Unal - sap note : 1281404 - Customer message log determination
  DATA:
    ls_msg_append       TYPE        /scwm/dlv_badi_msl_str,
    lo_bom              TYPE REF TO /scdl/cl_bo_management,
    lo_bo               TYPE REF TO /scdl/if_bo,
    lt_item             TYPE        /scdl/dl_item_tab,
    lo_item_curr        TYPE REF TO /scdl/cl_dl_item_prd,
    lo_item_prev        TYPE REF TO /scdl/cl_dl_item_prd,
    ls_qty_curr         TYPE        /scdl/dl_qty_str,
    ls_qty_prev         TYPE        /scdl/dl_qty_str.

  FIELD-SYMBOLS:
    <ls_key>            TYPE        /scwm/dlv_docid_str,
    <ls_item>           TYPE        /scdl/dl_item_str.

* Get business object manager instance, already in memory
  lo_bom = /scdl/cl_bo_management=>get_instance( ).

  IF lo_bom IS NOT BOUND.
    RETURN.
  ENDIF.

* Build message log structure, this will be added to the result
* table
* Insert into DB
  ls_msg_append-db_mode
    = /scwm/if_dlv_message_log=>sc_insert.

* Change to outbound delivery (order)
  ls_msg_append-message
    = /scwm/if_mapping_constants=>sc_m_obdlv_change.

* Change outbound delivery (order) item
  ls_msg_append-action_code
    = /scwm/if_mapping_constants=>sc_a_obdlv_change.

* Loop over received keys
  LOOP AT it_keys ASSIGNING <ls_key>.

*   Get business object of delivery
    lo_bo = lo_bom->get_bo_by_id( iv_docid = <ls_key>-docid ).
    CHECK lo_bo IS BOUND.

*   Get item table of the delviery
    lo_bo->get_item_tab(
      EXPORTING
        iv_objectstate
          = /scdl/if_dl_object_c=>sc_object_state_curr
        iv_docid
          = <ls_key>-docid
      IMPORTING
        et_item
          = lt_item ).

*   Loop on items
    LOOP AT lt_item ASSIGNING <ls_item>.

      CHECK <ls_item>-itemid IS NOT INITIAL.

*     Get item's current version
      lo_item_curr ?= <ls_item>-item.
      CHECK lo_item_curr IS BOUND.

*     Get item's previous version
      lo_item_prev ?= lo_bo->get_item(
          iv_itemid
            = <ls_item>-itemid
          iv_objectstate
            = /scdl/if_dl_object_c=>sc_object_state_db ).
      CHECK lo_item_prev IS BOUND.

*     Get quantities
      ls_qty_curr
        = lo_item_curr->/scdl/if_dl_item_readonly~get_qty( ).
      ls_qty_prev
        = lo_item_prev->/scdl/if_dl_item_readonly~get_qty( ).

*     Check if quantity changed
      CHECK ls_qty_curr-qty <> ls_qty_prev-qty
        OR ls_qty_curr-uom <> ls_qty_prev-uom.

*     Append message to messagelog
      ls_msg_append-itemid = <ls_item>-itemid.

      APPEND ls_msg_append TO rt_messages.

    ENDLOOP.

  ENDLOOP.

  endmethod.