This document describes creating an automatic usage decision for inspection lots upon specific business scenarios. It involves enhancing a BADI (MB_DOCUMENT_BADI) to automatically update the usage decision to "Accept" for trusted materials from trusted vendors during the goods receipt process, by calling a custom function module (ZUPDATE_UD). The function module checks a custom table (ZAUTO_UD) to determine if the material and vendor are trusted, and if so, calls the BAPI to update the usage decision without requiring a quality inspection. This allows inspection to be automated for trusted suppliers and materials.
Auto inspection lot creation and Auto Usage decision for required parts
1. Auto inspection lot creation and
Auto Usage decision for required
parts
Reusable Artifact Descriptions
Artifact Type Enhancement - BADI
Functional Area MM
Functional Sub-Area IM, QM
SAP System ECC
Objective:
This document is for creation of automatic usage decision upon specific business scenario.
In any business process regarding vendortransactions there will be trusted material in each transaction.There is a
common scenario that need of QA inspection for this material from that particular vendor (or trusted vendor)is null.
This scenario is not available or executed in standard SAP installation. The proposed approach as described below
will allow businesses to go for automatic inventory update under specific conditions.
Target Audience:
Both functional (MM & QM) and technical (ABAP developer) can use this document.
Requirement & Overview:
Normallyvendor sends their finished goods as partofbusiness process (like vendor consignmentprocess).Later on,
inspection will be done on the goods either manuallyor automaticallyby a third-party system.After the inspection is
completed,they postthe Goods receipt(GR) using the MIGO transaction.For trusted vendor and trusted material,
inspection will be done automaticallyand MIGO is posted.(But, UD update mustbe done automatically)
Needs to be created or Pre requisites:
Custom table ZAUTO_UD needs to be created. (To store trusted material and vendor details along with mapping
them).
Custom Function module ‘ZUPDATE_UD’ needs to be created. (To update Usage decision for inspection lot)
Technical design or steps to achieve a functionality:
2. In a standard SAP process,Inspection lot number (I-L no) and Material document number (M-doc-no) will be
generated once MIGO is done.During Quality inspection,I.L no will be accepted in IL02 transaction.
In our customer business process as perbusiness requirement, Quality inspection will be automated once M-doc-no
is generated. To achieve this, we need to enhance the BADI "MB_DOCUMENT_BADI" in the interface
“IF_EX_MB_DOCUMENT_BADI”.
BADI details:
BADI Description
BAdI Definition MB_DOCUMENT_BADI
Description BAdIs During Creation of a Material Document
Interface IF_EX_MB_DOCUMENT_BADI
Implementation Name ZMB_DOCUMENT_BADI
Description MB_DOCUMENT_BADI - QM Enhancement for auto UD for trusted Parts
Method:
Method Name Description
MB_DOCUMENT_BEFORE_UPDATE Exit After Writing a Material Document. Not in 'update task'
Functionality:
Implementbelow logic into method MB_DOCUMENT_BEFORE_UPDATE.
Get inspection lot number, material number and vendor number from the importing parameter of (XMSEG
–QPLOS, XMSEG-MATNR, and XMSEG-LIFNR).
Call custom update Function module ‘ZUPDATE_UD’ using below parameters via Update task.(CALL
FUNCTION 'ZUPDATE_UD' IN UPDATE TASK)
Below function module needs to be created:
Function module: ZUPDATE_UD
Description: UD update for inspection lot in MIGO
Importing parameters:
Parameter Name Reference Description and Mandatory
I_NUMBER BAPI2045UD-INSPLOT Inspection Lot
I_MATNR QALS-MATNR Material Number
I_LIFNR QALS-LIFNR Vendor Number
3. Function module: ZUPDATE_UD
Check if material and vendor exist in custom table ZAUTO_UD. If material and vendor combination has found
in the table then it’s a trusted transaction else normal transaction.
Note: Custom table ZAUTO_UD will hold the trusted material and vendor combination details.
If it’s a trusted transaction then call BAPI ‘BAPI_INSPLOT_SETUSAGEDECISION’ to updated Usage Decision
as A (A = Accept) else don’t update.
Process Flowchart:
Additional information:
We can use email functionality to trigger email to manager after User decision update.
We can trigger workflow for approvals.
Code snippet:
BADI Implementation : ZMB_DOCUMENT_BADI
4. ************************************************************************************************************
* Title : QM Enhancementfor auto UD for Req.Parts *
* BADI Definition Name : MB_DOCUMENT_BADI *
* Implementation ShortText : MB_DOCUMENT_BADI - QM Enhancementfor auto UD for Req.Parts *
* BADI Implementation Name :ZMB_DOCUMENT_BADI *
* Method : MB_DOCUMENT_BEFORE_UPDATE
(IF_EX_MB_DOCUMENT_BADI~MB_DOCUMENT_BEFORE_UPDATE) *
*----------------------------------------------------------------------------------------------------------*
*......next change..... *
************************************************************************************************************
METHOD if_ex_mb_document_badi~mb_document_before_update.
*Local Structures
DATA : ls_xvm07m LIKE LINE OF xvm07m, " Fields:Update Control of Module Pool SAPMM07M
ls_xmseg LIKE LINE OF xmseg, " Segmentof Material Document
*Clear Variables
CLEAR: ls_xvm07m,ls_xmseg.
*Read Inspection lotnumber
READ TABLE xvm07m INTO ls_xvm07m INDEX 1.
*Read material and vendor number
READ TABLE xmseg INTO ls_xmseg INDEX 1.
*Update Usage Decision as 'A - Accept'
CALL FUNCTION 'ZUPDATE_UD' IN UPDATE TASK
EXPORTING
i_number = ls_xvm07m-qplos
i_matnr = ls_xmseg-matnr
i_lifnr = ls_xmseg-lifnr.
IF sy-subrc <> 0.
MESSAGE 'Error while calling update function module'TYPE 'E'.
ENDIF.
ENDIF.
ENDMETHOD.
*******************************************************************************************
Function module: ZUPDATE_UD
FUNCTION zupdate_ud.
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
5. *" IMPORTING
*" VALUE(I_NUMBER) TYPE BAPI2045UD-INSPLOT
*" VALUE(I_MATNR) TYPE QALS-MATNR
*" VALUE(I_LIFNR) TYPE QALS-LIFNR
*" EXCEPTIONS
*" E_ERROR
*" E_SUCESS
*"----------------------------------------------------------------------
************************************************************************
* Title : QM Enhancementfor auto UD for Req.Parts *
* Author : Akshath L.T *
* Creation Date : 24/11/2014 *
* Description : UD update for insp.lotfrom MIGO *
************************************************************************
* Local Structures
DATA: ls_ud_data TYPE bapi2045ud, " Data for making the usage decision
ls_ud_return_data TYPE bapi2045ud_return,"Return structure after the usage decision is made
ls_stock_data TYPE bapi2045d_il2, " Stock Data for Inspection Lot
ls_return TYPE bapireturn1, " Return Parameter
* Local Internal Tables
lt_system_status TYPE STANDARD TABLE OF bapi2045ss,"Inspection lotsystem status
lt_user_status TYPE STANDARD TABLE OF bapi2045us,"Inspection lotuser status
l_insp_num TYPE bapi2045ud-insplot, " Inspection LotNumber
l_lifnr TYPE lifnr, " Vendor
l_matnr TYPE matnr. " Material
* Constants
CONSTANTS : lc_ud_selected_setTYPE bapi2045ud-ud_selected_setVALUE '01', " Selected Set of the Usage
Decision
lc_ud_code_group TYPE bapi2045ud-ud_code_group VALUE '01', " Code Group of the Usage Decision
lc_ud_code TYPE bapi2045ud-ud_code VALUE 'A', " Accept Usage Decision
lc_language TYPE bapi2045la VALUE 'E', " Language
lc_msgtyp_e TYPE c VALUE 'E', " Error
lc_werks TYPE werks VALUE '9999'.
* Clear variables
CLEAR:l_matnr,
l_lifnr,
l_insp_num,
ls_ud_data.
IF i_matnr IS NOT INITIAL AND
i_lifnr IS NOT INITIAL.
6. * Fetch Material and Vendor data from the table ZAUTOUD
SELECT SINGLE matnr
lifnr
FROM zauto_ud
INTO (l_matnr,l_lifnr)
WHERE matnr = i_matnr
AND lifnr = i_lifnr.
if sy-subrc = 0.
* Remove leading-zero of Vendor number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = i_lifnr
IMPORTING
output= l_lifnr.
* Populate data for BAPI updation
ls_ud_data-insplot = i_number.
ls_ud_data-ud_selected_set = lc_ud_selected_set.
ls_ud_data-ud_plant = lc_werks.
ls_ud_data-ud_code_group = lc_ud_code_group .
ls_ud_data-ud_code = lc_ud_code .
ls_ud_data-ud_stock_posting = abap_true.
l_insp_num = i_number.
* Update usage decision as Accept in inspection lot
CALL FUNCTION 'BAPI_INSPLOT_SETUSAGEDECISION'
EXPORTING
number = l_insp_num
ud_data = ls_ud_data
language = lc_language
IMPORTING
ud_return_data = ls_ud_return_data
stock_data = ls_stock_data
return = ls_return
TABLES
system_status = lt_system_status
user_status = lt_user_status.
IF ls_return-type = lc_msgtyp_e.
MESSAGE 'Error while updating Usage Decision'TYPE 'E'.
ENDIF.