# SAP Usage Decision BAPI Skeleton (BAPI_INSPLOT_SETUSAGEDECISION)

> Source: https://netray.co/tools/sap-qm-usage-decision-bapi-skeleton
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

An ABAP skeleton for recording an inspection lot usage decision through the standard BAPI, with error handling and a commit only when no error is returned.

## Category

developer

## Erp

SAP S/4HANA

## Industry

Discrete Manufacturing

## Audience

- ABAP developer
- SAP QM consultant
- Integration developer

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Inspection lot number

**Key:** lot

**Type:** text

**Default:** 010000001234

#### Plant

**Key:** plant

**Type:** text

**Default:** 1000

#### Selected set

**Key:** sel_set

**Type:** text

**Default:** SS01

**Help:** Selected set of the usage decision catalog. Your own value.

#### UD code group

**Key:** code_group

**Type:** text

**Default:** QM01

**Help:** Code group in your UD catalog. Your own value.

#### UD code

**Key:** code

**Type:** text

**Default:** A

**Help:** Code that means accepted in your catalog. Your own value.

**Blocks:**

#### Record the usage decision

**Body:** 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 = '{{lot}}'.

ls_ud-ud_selected_set = '{{sel_set}}'.
ls_ud-ud_plant        = '{{plant}}'.
ls_ud-ud_code_group   = '{{code_group}}'.
ls_ud-ud_code         = '{{code}}'.

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.

**Notes:** 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.

## Content

**Intro:** 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.

**Sections:**

#### How to use the skeleton

**Body:** 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

**Body:** 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.

**Bullets:**

- 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

**Body:** 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

**Body:** 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.

**Cta:** 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.

**Faq:**

#### Which BAPI records a usage decision in SAP QM?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

BAPI_INSPLOT_SETUSAGEDECISION, SAP usage decision BAPI, record usage decision ABAP, SAP QM BAPI list, BAPI_TRANSACTION_COMMIT usage decision, SAP QM integration BAPI, automate usage decision SAP, SAP inspection lot BAPI

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
