Simplify SAP R/3 development with Excel VBA/VB RFC  
Home> UserExit>MB_CF001



Customer Functions: Inventory Management
The user exit MB_CF001 includes a function module that is called up immediately before the COMMIT WORK when a goods movement is posted.

All the material document data is passed on to this function module from the following tables:

  • MKPF (Material document header)
  • MSEG (Material document items)
  • VM07M (Update data)

This data can be passed on to other programs.


The user exit does not write any data to the material document, that is, it is not possible to change material document data before the update posting takes place.

If the enhancement MB_CF001 (component: Function module EXIT_SAPLMBMB_001 with Include ZXMBCU01) is implemented incorrectly an inconsistency may occur between documents and stocks as well as between material documents and accounting documents. Such inconsistencies can be caused by the following elements in the user exit, for example:

  • Remote function call (CALL FUNCTION .. DESTINATION)
  • Separate updates on the document or stock tables (for example, an update on table MBEW, MARD, MSEG)
  • Unlocking data (for example, through DEQUEUE_ALL)

The enhancement MB_CF001 is called in the update function module MB_POST_DOCUMENT. If a COMMIT WORK or a Remote Function Call are set in the enhancement, a complete ROLL BACK is not possible in the case of an update termination since data is already written until the COMMIT or the remote function call in the database. Consequently an asynchronous status (for example, a material document without accounting document), which can only be repaired with considerable effort, can result.

The enhancement MB_CF001 is not suited for customer-specific updates on the stock tables since such updates can destroy the standard inventory update if they are not programmed incrementally (see Note 6899) or do not take the material blocks into account.

An unlocking of data (for example using DEQUEUE_ALL) is also a very high priority since the data to be updated is no longer protected against external updates and inconsistencies can result from parallel updates.

Before you activate an enhancement, carefully check that the user exit does not contain a high priority source code positions.

If data inconsistencies already occurred in your system, which can be traced back to the user exits, remove the high priority source code positions immediately before they cause further inconsistencies.

The following example illustrates how you can use this user exit if you have a link to an external system. All the goods movements of a particular movement type are passed on to an external system via IDOC using the ALE link. An existing IDOC structure is used. In addition to the following coding, you must also specify a destination and a partner link for the output in the ALE Customizing section.

* INCLUDE ZXMBCU01/ (Create the Include by activating the
* user-exit with transaction /nCMOD)
*"*"Local interface:
data: p_varia like t327a-varia. "helper, of no use here
data: flg_continue_work type c value 0.

loop at xmseg.
if xmseg-bwart = 501.
flg_continue_work = 1.
delete xmseg.
check flg_continue_work = 1.

tables: edidd, edidc, e1mbxyh, e1mbxyi.
data: begin of comm_idoc_control occurs 10.
include structure edidc.
data: end of comm_idoc_control.

* Data send to ALE
*........Giving data to ALE-interface..............................
call function 'L_IDOC_HEADER_CREATE'
i_mestyp = 'WMMBXY'
i_mescod = p_varia
i_idoctp = 'WMMBID01'
i_rcvprn = 'P30CLNT003'.

*........Prepare 1.Segment............................................
clear edidd.
loop at xmkpf.
move-corresponding xmkpf to e1mbxyh.
move sy-tcode to e1mbxyh-tcode.
move e1mbxyh to edidd-sdata.
call function 'L_IDOC_SEGMENT_CREATE'
i_segnam = 'E1MBXYH'
i_sdata = edidd-sdata.

*........Prepare Itemdata .............................................
loop at xmseg.
clear edidd.
move-corresponding xmseg to e1mbxyi.
move e1mbxyi to edidd-sdata.
call function 'L_IDOC_SEGMENT_CREATE'
i_segnam = 'E1MBXYI'
i_sdata = edidd-sdata.

*.......Send IDOC ............................................

call function 'L_IDOC_SEND'
t_comm_idoc = comm_idoc_control
error_distribute_idoc = 01.


  • EXIT_SAPLMBMB_001: Customer Function Exit in the Case of Updating a Material Document