Developer ToolsFree generatorPDF, Excel, Word exportSAP S/4HANADiscrete Manufacturing

SAP QM Inspection Lot ABAP SELECT Generator (QALS and QAVE)

Custom QM reports usually start with the same join: the inspection lot in QALS and its usage decision in QAVE. This generator writes that query with your plant, inspection type and date filters so you can paste it into a report and extend it.

Fill in

Two character inspection type, for example 01 for goods receipt.

Your own code from the UD catalog. Not a fixed SAP value.

Generated code
Download:

Open SQL: lots with usage decision

REPORT z_qm_lots_with_ud.

TYPES: BEGIN OF ty_lot,
         prueflos TYPE qals-prueflos,
         werk     TYPE qals-werk,
         matnr    TYPE qals-matnr,
         art      TYPE qals-art,
         herkunft TYPE qals-herkunft,
         enstehdat TYPE qals-enstehdat,
         losmenge TYPE qals-losmenge,
         vcode    TYPE qave-vcode,
         vcodegrp TYPE qave-vcodegrp,
         vdatum   TYPE qave-vdatum,
       END OF ty_lot.

DATA lt_lots TYPE STANDARD TABLE OF ty_lot WITH EMPTY KEY.

SELECT a~prueflos, a~werk, a~matnr, a~art, a~herkunft,
       a~enstehdat, a~losmenge, b~vcode, b~vcodegrp, b~vdatum
  FROM qals AS a
  INNER JOIN qave AS b ON b~prueflos = a~prueflos
  WHERE a~werk = '1000'
    AND a~art = '01'
    AND a~enstehdat >= '20260101'
    AND b~vcode = 'A'
  ORDER BY a~prueflos
  INTO TABLE @lt_lots
  UP TO 500 ROWS.

IF sy-subrc <> 0.
  WRITE / 'No inspection lots found.'.
  RETURN.
ENDIF.

LOOP AT lt_lots ASSIGNING FIELD-SYMBOL(<ls_lot>).
  WRITE: / <ls_lot>-prueflos, <ls_lot>-matnr, <ls_lot>-vcode, <ls_lot>-vdatum.
ENDLOOP.

Variant: lots still without a usage decision

SELECT a~prueflos, a~werk, a~matnr, a~art, a~enstehdat
  FROM qals AS a
  LEFT OUTER JOIN qave AS b ON b~prueflos = a~prueflos
  WHERE a~werk = '1000'
    AND a~art = '01'
    AND a~enstehdat >= '20260101'
    AND b~prueflos IS NULL
  INTO TABLE @DATA(lt_open)
  UP TO 500 ROWS.

Uses the newer Open SQL syntax with @ host variables, which needs ABAP 7.40 SP05 or later (all S/4HANA releases). Verify field names in SE11 for your release. A rejected lot is not identified by a fixed code: the codes come from your own usage decision catalog. Lots flagged for deletion should be excluded by reading status in JEST. Run in a sandbox first.

Skip the custom report

An optional review of whether a read-only natural-language layer would replace your Z reports for quality.

Optional. The tool and every export work without this. No spam.

How to use the generator

Enter the plant, the inspection type, the earliest creation date in YYYYMMDD form and the usage decision code you want. The generator fills a complete report skeleton with typed fields, an inner join and a loop. Copy it into SE38 or ADT, activate and run. The second block flips the join to a left outer join to find lots that have no usage decision yet, which is the common backlog report for quality managers.

Why a join on PRUEFLOS

QALS holds one row per inspection lot and QAVE holds the usage decision for that lot, so the inspection lot number PRUEFLOS is the join key. Using an inner join returns only decided lots; a left outer join with an IS NULL test on the QAVE side returns only undecided ones. Filtering on QALS date fields keeps the join small, which matters because QALS grows quickly in plants that inspect every goods receipt.

  • Inner join: lots with a usage decision
  • Left outer join with IS NULL: lots awaiting a decision
  • Filter on WERK, ART and ENSTEHDAT first for speed
  • Use UP TO n ROWS while testing

Extending the query

Typical next steps are adding the material description from MAKT, the vendor from the lot header, or the lot status from JEST using the object number OBJNR. Add an authority check on plant using the standard QM authorization object before you release a report to users, and consider a CDS view if the data will feed analytics. If the lot quantity is needed in another unit, convert it with the standard unit conversion function rather than dividing by hand.

Common mistakes

Hard coding a rejection code, forgetting that material numbers can be longer in S/4HANA, selecting without a date filter on a large QALS and skipping the authority check are the main risks. Also remember that a lot can be reset after the decision is changed, so the report shows the state at run time.

Frequently Asked Questions

How do I join inspection lots to usage decisions in ABAP?

Join QALS to QAVE on the inspection lot number PRUEFLOS. An inner join returns lots that have a usage decision. A left outer join with a test for NULL on the QAVE key returns lots that do not yet have one.

Which date field should I filter on in QALS?

ENSTEHDAT holds the creation date of the inspection lot and is a good general filter. Other date fields exist for the start and end of inspection, so pick the one that matches the report question and check names in SE11 for your release.

Can I run this query on ECC as well as S/4HANA?

The tables exist in both, but the @ host variable syntax needs ABAP 7.40 SP05 or higher. On older systems, remove the @ signs, declare the target explicitly and move the INTO clause as the older syntax requires.

How do I exclude deleted inspection lots?

Deletion flags are statuses, not columns in QALS. Join JEST on OBJNR and exclude lots that carry the deletion status, or use a standard function to read the status text. Check the exact status code in your system before filtering.

If you would rather let quality managers ask for open lots or rejected lots in plain language, we can build a read-only layer over your SAP data that shows the query it ran.