# SAP SD Sales Order Item ABAP SELECT Generator

> Source: https://netray.co/tools/sap-sd-sales-order-item-abap-select-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in the sales organization, order type and dates, and get a ready-to-adapt ABAP report that lists sales order items.

## Category

sap

## Erp

SAP ECC and S/4HANA

## Audience

- ABAP developer
- SAP SD consultant
- Reporting analyst

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Report name

**Key:** report

**Type:** text

**Default:** ZSD_ORDER_ITEMS

#### Sales organization

**Key:** sales_org

**Type:** text

**Default:** 1000

#### Sales document type

**Key:** doc_type

**Type:** text

**Default:** OR

#### Order date from (YYYYMMDD)

**Key:** date_from

**Type:** text

**Default:** 20260101

#### Order date to (YYYYMMDD)

**Key:** date_to

**Type:** text

**Default:** 20261231

#### Maximum rows

**Key:** max_rows

**Type:** number

**Default:** 5000

**Blocks:**

#### Report

**Body:** REPORT {{report}}.

* 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 = '{{sales_org}}'
      AND h~auart = '{{doc_type}}'
      AND h~audat BETWEEN '{{date_from}}' AND '{{date_to}}'
      AND p~abgru = ''
    ORDER BY h~vbeln, p~posnr
    INTO TABLE @DATA(lt_items)
    UP TO {{max_rows}} 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.

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

## Content

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

**Sections:**

#### How to use it

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

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

**Bullets:**

- 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

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

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

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

**Faq:**

#### Does this work on ECC and S/4HANA?

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

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

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

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

## Search terms

abap select vbak vbap, sap sales order items report abap, sap vbak vbap join example, abap open sql join sales order, sap sales order extract abap, vbak vbap fields, sap sd custom report template

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