FM/BAPI to post Physical Inventory
I found this issue in many requirements related to physical inventory so i thought to share with you all with easy option to resolve this. Other than using BDC, which I personally don’t prefer unless there is no other way available.
There are standard way’s to create MI01/MI04/MI07 using below Function modules,
BAPI_MATPHYSINV_CREATE_MULT -- Create Physical Inventory Doc MI01 BAPI_MATPHYSINV_COUNT --- Add Count MI04 BAPI_MATPHYSINV_POSTDIFF --- Post Difference
You need to call these BAPI’s in sequence and you must use commit work after each BAPI call.
This is will work perfect with happy scenario but there will be issue if 2nd or 3rd bapi fails by some reason. It is difficult to reverse or revert back the created physical inventory document.
To solve this you need to call below Function module to delete the document created.
You need to call this FM 2 times and then commit work.
MB_PHYSICAL_INVENTORY with SIIKF - which you can fill from IIKF table - pass DSTAT=LSTAT=ZSTAT = 'X' Inv action - 1 ctcod - 'MI02' t_iiseg - which you can fill from IISEG table - PASS XLOEK = 'X'
Step 2: Same as Step1 but just change in Inv Action
MB_PHYSICAL_INVENTORY with SIIKF - which you can fill from IIKF table - pass DSTAT=LSTAT=ZSTAT = 'X' Inv action - 2 ctcod - 'MI02' t_iiseg - which you can fill from IISEG table - PASS XLOEK = 'X'
Step 3: Commit Work
This will help in delete or changing anything from physical inventory document.
There are some more functions which you can explore with this FM as it allows you to create/count/post directly with MI10.
Hope this helps.