SAP采购申请ME51N允许0数量:调试及增强修改方案咨询
Got it, let's break down how to solve this requirement where you need to create a purchase requisition (ME51N) with a quantity of 0—something SAP standard blocks by default. Since you've already started debugging BAPI_REQUISITION_CREATE, let's build on that.
Step 1: Pinpoint the Standard Check Points
SAP enforces the "quantity > 0" rule in two key areas:
- Frontend (ME51N Screen): The dynpro input validation will throw an error when you enter 0.
- Backend (BAPI/Function Modules): Both ME51N and
BAPI_REQUISITION_CREATErely on underlying functions that validate the quantity.
Debugging the Frontend (ME51N)
- Open ME51N, enter your data, set quantity to 0, and hit save. When the error ("Quantity must be greater than 0") pops up, type
/hto start debugging. - Look up the error message ID (it’s usually
ME 021). Trace the code stack to find where this message is raised—you’ll likely land inME_REQUISITION_CHECKor the includeLMEREQFU01, which handles core PR validations.
Debugging the Backend (BAPI_REQUISITION_CREATE)
Since you’re already here, let’s dig deeper:
- Inside
BAPI_REQUISITION_CREATE, it callsBAPI_REQUISITION_CREATE1, which triggersME_REQUISITION_CREATE. - Follow the validation flow until you hit the check for
REQUISITION_ITEM-QUANTITY > 0. This is typically inLMEREQFU01(functionME_REQ_ITEM_CHECK) orLMEREQF05.
Step 2: Choose a Supported Enhancement (Skip Standard Code Modifications!)
Tweaking standard SAP code is risky (upgrades will overwrite it, plus support issues). Stick to these supported options:
Option 1: Use the BADI ME_PROCESS_REQ_CUST
This BADI is built for customizing PR processing. Here’s how to use it:
- Go to
SE18, enterME_PROCESS_REQ_CUST, and create an implementation viaSE19. - Implement the
CHECKmethod. Access PR item data withIM_ITEM->GET_DATA(). - Override the quantity check: if the quantity is 0, suppress the standard
ME 021error. For example:DATA(ls_item) = im_item->get_data( ). IF ls_item-quantity = 0. " Suppress the error message LOOP AT sy-mesg INTO DATA(ls_mesg) WHERE msgid = 'ME' AND msgno = '021'. CLEAR ls_mesg-msgty. MODIFY sy-mesg FROM ls_mesg. ENDLOOP. ENDIF.
Option 2: Add an Implicit Enhancement at the Validation Point
If the BADI doesn’t cover your case, add an implicit enhancement right after the standard quantity check:
- In the include where
ME 021is raised (e.g.,LMEREQFU01), find this block:IF ls_item-quantity <= 0. MESSAGE e021(me) WITH ls_item-item_no. ENDIF. - Place your cursor after this block, go to
Edit → Enhancement Operations → Create Implicit Enhancement. - Add custom logic to bypass the error for specific scenarios (e.g., only allow 0 quantity for certain material types):
" Allow quantity 0 for custom material type Z001 IF ls_item-mat_type = 'Z001'. CLEAR sy-msgty. " Convert error to no message ENDIF.
Option 3: Enhance the BAPI Directly
If you only use the BAPI to create PRs, add an enhancement in BAPI_REQUISITION_CREATE1 to skip the quantity check before passing data to core functions.
Step 3: Test Thoroughly
After implementing, verify these scenarios to avoid side effects:
- Create a 0-quantity PR via ME51N and BAPI—confirm it saves successfully.
- Check if downstream processes (PO conversion, MRP planning) handle the 0-quantity PR correctly.
- Ensure normal PRs with valid quantities still work as expected.
内容的提问来源于stack exchange,提问作者XAF

