SAP Usage Decision BAPI Skeleton (BAPI_INSPLOT_SETUSAGEDECISION)
Interfaces from MES, LIMS or test benches often need to set the usage decision in SAP without a person in QA11. This skeleton shows the standard pattern: fill the decision structure, call the BAPI, inspect RETURN and commit or roll back.
Fill in
Selected set of the usage decision catalog. Your own value.
Code group in your UD catalog. Your own value.
Code that means accepted in your catalog. Your own value.
Record the usage decision
DATA: ls_ud TYPE bapi2045ud,
lv_lot TYPE bapi2045l2-insplot,
ls_return TYPE bapiret2,
ls_stock TYPE bapi2045d3,
ls_udret TYPE bapi2045ud_return.
lv_lot = '010000001234'.
ls_ud-ud_selected_set = 'SS01'.
ls_ud-ud_plant = '1000'.
ls_ud-ud_code_group = 'QM01'.
ls_ud-ud_code = 'A'.
CALL FUNCTION 'BAPI_INSPLOT_SETUSAGEDECISION'
EXPORTING
number = lv_lot
ud_data = ls_ud
IMPORTING
return = ls_return
stock_data = ls_stock
ud_return_data = ls_udret.
IF ls_return-type CA 'EA'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
WRITE: / 'Error:', ls_return-message.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
WRITE: / 'Usage decision recorded for lot', lv_lot.
ENDIF.Starting point only. Structure names and field names of the BAPI parameters differ by release: open BAPI_INSPLOT_SETUSAGEDECISION in SE37 and confirm every parameter before activation. The selected set, code group and code are values from your own catalogs. Test in a sandbox: a successful call posts stock according to the code. Check that the lot has all required results and that no inspection is still open.
Planning an MES or LIMS interface to SAP QM?
An optional review of your interface design, controls and approval steps.
Optional. The tool and every export work without this. No spam.
How to use the skeleton
Enter the inspection lot, plant and the selected set, code group and code from your own usage decision catalog, then copy the block into a test program. The skeleton checks the RETURN structure for error and abort messages, rolls back on failure and commits with wait only when the call is clean. Open the function module in SE37 to confirm parameter names for your release before you activate it, since the structure fields can differ between versions.
What the call does
Recording a usage decision completes the quality inspection for the lot and triggers the follow-up actions configured for the code: stock posting from quality inspection stock to unrestricted use, blocked, scrap or return to vendor, quality score calculation, and dynamic modification of the sampling stage if a rule applies. Those follow-ups are why you test in a sandbox and why an automated decision should be rare and rule-based, not a default.
- Stock posting depends on the code configuration
- Quality score and dynamic modification may run
- The lot must be ready: results complete, no open mandatory characteristics
- The decision can fail if the lot is locked by another user
Controls and governance
A usage decision is a quality judgement with stock and compliance consequences. Automate only the clear cases, such as every characteristic within tolerance, and leave anything borderline to a person. Log who or what called the BAPI, run it under a dedicated technical user with narrow authorizations, and keep the record in the interface log. For regulated industries, make sure your validation approach covers the interface.
Common mistakes
Calling the BAPI without a commit leaves no change in the database. Committing after a returned error hides a failed decision. Hard coding catalog values breaks transports between systems that use different codes. Finally, running the BAPI in a loop for many lots without waiting for locks produces intermittent failures that are hard to reproduce.
Frequently Asked Questions
Which BAPI records a usage decision in SAP QM?
BAPI_INSPLOT_SETUSAGEDECISION records the usage decision for an inspection lot. Pass the lot number and a decision structure with the selected set, plant, code group and code, check RETURN, then commit with BAPI_TRANSACTION_COMMIT.
Do I need BAPI_TRANSACTION_COMMIT after the call?
Yes. The BAPI does not commit by itself, so call BAPI_TRANSACTION_COMMIT when RETURN contains no error or abort message. If an error is returned, call BAPI_TRANSACTION_ROLLBACK so nothing half finished remains.
Can the BAPI reverse a usage decision?
Not through this skeleton. Changing or cancelling a decision is a separate process and in the GUI uses QA12 with its own rules and authorizations. Check the BAPI list in your release for change functions before you plan an interface for reversals.
Should an interface make usage decisions automatically?
Only for clear, rule-based cases agreed with quality and validated. Borderline results, first articles and regulated products should go to a person. Keep an audit trail of every automated decision and the data behind it.
If you are connecting test equipment, MES or a data platform to SAP QM, we can design the interface with human approval on any write-back and keep the logic on-premises.
Related Tools
SAP QM Transaction Codes Reference
A searchable list of the SAP QM transaction codes consultants and key users use every day, grouped by inspection, results, notifications and master data.
Developer ToolsSAP QM Inspection Lot ABAP SELECT Generator
Fill in plant, inspection type and date range and get a ready ABAP SELECT joining the inspection lot table QALS to the usage decision table QAVE.
SAPSAP QM Database Tables Reference
Searchable lookup of the core SAP Quality Management tables, what each one stores and its main key fields, for report writers and data migration teams.
SAPSAP QM Go-Live and Cutover Checklist
A checklist of what to confirm before switching on SAP Quality Management: master data, integration, authorizations, migration and hypercare.
More Developer Tools tools
See all- SAP Quality Notification Pareto SQL Query Generator
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator
- ABAP BAPI Return Handling and Commit Generator
- SAP ABAP AUTHORITY-CHECK Snippet Generator