SAPFree generatorPDF, Excel, Word exportSAP ECC and S/4HANA

SAP SD Sales Order Item ABAP SELECT Generator

Almost every SD reporting request begins with the same join of the sales document header and item tables. This generator produces a clean, modern ABAP report you can drop into a Z program and extend.

Fill in

Generated code
Download:

Report

REPORT ZSD_ORDER_ITEMS.

* Sales order items by sales organization, document type and order date.
* Adapt the field list and the WHERE clause to your requirement.

START-OF-SELECTION.

  SELECT h~vbeln, h~audat, h~auart, h~vkorg, h~vtweg, h~spart, h~kunnr, h~waerk,
         p~posnr, p~matnr, p~kwmeng, p~vrkme, p~netwr
    FROM vbak AS h
    INNER JOIN vbap AS p ON p~vbeln = h~vbeln
    WHERE h~vkorg = '1000'
      AND h~auart = 'OR'
      AND h~audat BETWEEN '20260101' AND '20261231'
      AND p~abgru = ''
    ORDER BY h~vbeln, p~posnr
    INTO TABLE @DATA(lt_items)
    UP TO 5000 ROWS.

  IF sy-subrc <> 0.
    WRITE / 'No sales order items found.'.
    RETURN.
  ENDIF.

  LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<ls_item>).
    WRITE: / <ls_item>-vbeln, <ls_item>-posnr, <ls_item>-matnr,
             <ls_item>-kwmeng, <ls_item>-vrkme, <ls_item>-netwr, <ls_item>-waerk.
  ENDLOOP.

Requires ABAP 7.40 SP05 or later for the inline declaration and the host variable syntax. VBAK is the sales document header and VBAP the item table. The condition p~abgru = '' excludes items with a rejection reason. Add authority checks (for example on object V_VBAK_VKO) and test with a small row limit in a quality system before production use.

Natural language SD reporting

Want to ask questions about sales orders in plain English, read-only?

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

How to use it

Fill in a report name, your sales organization, the document type and the order date range. Keep the maximum row limit low while testing. Copy the generated code into transaction SE38 or into ADT in Eclipse, activate it and run it with a small range first. Then extend the field list, add selection screen parameters and an ALV output as needed.

What the query does

It joins VBAK, the sales document header, with VBAP, the item data, on the document number. The header supplies the order date, document type, organization data and customer. The item supplies the item number, material, order quantity, unit and net value. Rejected items are excluded through the rejection reason field, and the result is sorted by document and item.

  • VBAK-AUDAT is the document date
  • VBAP-KWMENG is the cumulative order quantity in sales units
  • VBAP-NETWR is the net value of the item in document currency

Performance and safety

Filter on indexed or selective fields where possible. The sales organization and date are usually selective enough with the standard secondary indexes, but check with the SQL trace on large systems. Always limit rows during development, and never write directly into SD tables. For status information, use the standard status tables or the released CDS views for your release.

Common mistakes

Developers often forget the authority check, hard-code values that should be selection parameters, or select all columns with SELECT star on wide tables. Another frequent issue is that status fields moved between releases, so check your version before relying on header or item status fields.

Frequently Asked Questions

Does this work on ECC and S/4HANA?

The tables exist in both. The inline syntax needs ABAP 7.40 SP05 or newer, which most ECC systems on recent enhancement packs and all S/4HANA systems support.

Why join rather than two selects?

A join reads both tables in one database round trip and avoids loops with selects inside, which are the biggest performance problem in many custom SD reports.

How do I add the customer name?

Join table KNA1 on KUNNR, or read it with a separate select for all distinct customers using FOR ALL ENTRIES, taking care that the driver table is not empty.

Is there a standard alternative?

Yes. Standard reports such as VA05 for the list of sales orders, or released CDS views, may be enough, and are preferable to custom code when they meet the need.

If business users keep asking for new variants of this report, we can build a natural language layer over your read-only SD data so they can ask without a developer.