# Condition Table in SAP SD and MM: Condition Record Query Generator (Axxx + KONP)

> Source: https://netray.co/tools/sap-ecc-condition-records-a-table-konp-abap-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Pick the application, condition table, condition type and key values to get ABAP that returns the valid condition records with rate, unit, validity and scales.

## Category

developer

## Erp

SAP ECC 6.0

## Audience

- ABAP developer
- SAP SD consultant
- SAP MM consultant

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Application (KAPPL)

**Key:** kappl

**Type:** select

**Options:**

- V
- M

**Default:** V

**Help:** V = sales, M = purchasing

#### Condition table

**Key:** kotab

**Type:** text

**Default:** A004

**Help:** A004 sales org / channel / material, A005 sales org / channel / customer / material, A017 and A018 purchasing info record.

#### Condition type

**Key:** kschl

**Type:** text

**Default:** PR00

#### Key field 1 name (- to skip)

**Key:** f1_name

**Type:** text

**Default:** vkorg

#### Key field 1 value

**Key:** f1_val

**Type:** text

**Default:** 1000

#### Key field 2 name (- to skip)

**Key:** f2_name

**Type:** text

**Default:** vtweg

#### Key field 2 value

**Key:** f2_val

**Type:** text

**Default:** 10

#### Key field 3 name (- to skip)

**Key:** f3_name

**Type:** text

**Default:** matnr

#### Key field 3 value (internal format)

**Key:** f3_val

**Type:** text

**Default:** 000000000000100100

#### Valid on (YYYYMMDD)

**Key:** valid_on

**Type:** text

**Default:** 20261022

#### Max rows

**Key:** max_rows

**Type:** number

**Default:** 200

**Blocks:**

#### ABAP report: condition table + KONP + KONM

**Body:** REPORT z_condition_record_query.

* Reads condition records from a condition table (Axxx) joined to KONP.
* Find the condition table(s) for a condition type:
*   SELECT kozgf FROM t685
*     WHERE kvewe = 'A' AND kappl = '{{kappl}}' AND kschl = '{{kschl}}'.
*   SELECT kolnr kotabnr FROM t682i
*     WHERE kvewe = 'A' AND kappl = '{{kappl}}' AND kozgf = <access sequence>.
*   Table name = 'A' + KOTABNR, e.g. 004 -> A004.
* Document conditions (ECC): KONV WHERE knumv = VBAK-KNUMV or EKKO-KNUMV.
*   In S/4HANA document conditions are in PRCD_ELEMENTS instead.

TYPES: BEGIN OF ty_cond,
         knumh    TYPE konp-knumh,
         datab    TYPE konh-datab,
         datbi    TYPE konh-datbi,
         kopos    TYPE konp-kopos,
         kbetr    TYPE konp-kbetr,
         konwa    TYPE konp-konwa,
         kpein    TYPE konp-kpein,
         kmein    TYPE konp-kmein,
         loevm_ko TYPE konp-loevm_ko,
       END OF ty_cond.

DATA: lt_cond   TYPE STANDARD TABLE OF ty_cond,
      ls_cond   TYPE ty_cond,
      lt_scale  TYPE STANDARD TABLE OF konm,
      ls_scale  TYPE konm,
      lv_tab    TYPE tabname VALUE '{{kotab}}',
      lv_fields TYPE string,
      lv_from   TYPE string,
      lv_where  TYPE string,
      lv_pct    TYPE p DECIMALS 3,
      lx_sql    TYPE REF TO cx_sy_dynamic_osql_error,
      lv_msg    TYPE string.

START-OF-SELECTION.

  lv_fields = 'a~knumh a~datab a~datbi p~kopos p~kbetr p~konwa p~kpein p~kmein p~loevm_ko'.

  CONCATENATE lv_tab 'AS a INNER JOIN konp AS p ON p~knumh = a~knumh'
    INTO lv_from SEPARATED BY space.

* Key values must be in internal format (leading zeros for MATNR, KUNNR, LIFNR)
  CONCATENATE 'a~kappl = ''{{kappl}}'' AND a~kschl = ''{{kschl}}'''
              'AND a~datab <= ''{{valid_on}}'' AND a~datbi >= ''{{valid_on}}'''
              'AND p~loevm_ko = '' '''
    INTO lv_where SEPARATED BY space.

  IF '{{f1_name}}' <> '-'.
    CONCATENATE lv_where 'AND a~{{f1_name}} = ''{{f1_val}}'''
      INTO lv_where SEPARATED BY space.
  ENDIF.
  IF '{{f2_name}}' <> '-'.
    CONCATENATE lv_where 'AND a~{{f2_name}} = ''{{f2_val}}'''
      INTO lv_where SEPARATED BY space.
  ENDIF.
  IF '{{f3_name}}' <> '-'.
    CONCATENATE lv_where 'AND a~{{f3_name}} = ''{{f3_val}}'''
      INTO lv_where SEPARATED BY space.
  ENDIF.

  TRY.
      SELECT (lv_fields)
        FROM (lv_from)
        INTO CORRESPONDING FIELDS OF TABLE lt_cond
        UP TO {{max_rows}} ROWS
        WHERE (lv_where).
    CATCH cx_sy_dynamic_osql_error INTO lx_sql.
      lv_msg = lx_sql->get_text( ).
      WRITE: / 'Dynamic SQL error:', lv_msg.
      RETURN.
  ENDTRY.

  LOOP AT lt_cond INTO ls_cond.
    IF ls_cond-konwa = '%'.
* Percentages are stored in per mille: 100.00 in KBETR means 10 %
      lv_pct = ls_cond-kbetr / 10.
      WRITE: / ls_cond-knumh, ls_cond-datab, ls_cond-datbi, lv_pct, '%'.
    ELSE.
      WRITE: / ls_cond-knumh, ls_cond-datab, ls_cond-datbi,
               ls_cond-kbetr CURRENCY ls_cond-konwa, ls_cond-konwa,
               'per', ls_cond-kpein, ls_cond-kmein.
    ENDIF.

* Quantity scales (KONM). Value scales are stored in KONW.
    SELECT * FROM konm INTO TABLE lt_scale
      WHERE knumh = ls_cond-knumh
        AND kopos = ls_cond-kopos
      ORDER BY klfn1.
    LOOP AT lt_scale INTO ls_scale.
      WRITE: /10 'Scale from qty', ls_scale-kstbm, 'rate', ls_scale-kbetr.
    ENDLOOP.
  ENDLOOP.

  IF lt_cond IS INITIAL.
    WRITE: / 'No valid records in', lv_tab, 'for', '{{kschl}}', 'on', '{{valid_on}}'.
  ENDIF.

**Notes:** Check the key fields of your condition table in SE11 before running: customer-created tables (A501 and up) have their own keys. A017 keys are LIFNR, MATNR, EKORG, WERKS, ESOKZ; A018 omits WERKS. The select list uses only KAPPL, KSCHL, DATAB, DATBI and KNUMH, which every Axxx pricing table has. This reads ECC; in S/4HANA condition tables still exist but document conditions moved from KONV to PRCD_ELEMENTS.

## Content

**Intro:** This generator writes ABAP for SAP ECC 6.0 that reads master condition records from a condition table such as A004, A005, A017 or A018, joins KONP for the rate and unit, and lists KONM quantity scales. Use it to answer which price, discount or info record condition is valid on a given date for a given key.

**Sections:**

#### Where condition records live

**Body:** Every condition record has a header and a variable key. The variable key sits in a generated condition table named A plus a three-digit number: A004 for sales org, distribution channel and material, A005 for sales org, distribution channel, customer and material, A017 and A018 for purchasing info record conditions with and without plant. Each row carries KAPPL, KSCHL, the key fields, DATBI, DATAB and KNUMH. KNUMH is the condition record number that links to KONH (header) and KONP (item with KBETR, KONWA, KPEIN, KMEIN, LOEVM_KO). Scales sit in KONM for quantity and KONW for value.

**Bullets:**

- T685: condition type to access sequence (KOZGF).
- T682I: access sequence to condition tables (KOTABNR), in access order KOLNR.
- KONV: conditions copied into sales and purchasing documents in ECC.

#### How to use it

**Body:** Choose application V for sales or M for purchasing, enter the condition table and type, then up to three key fields with values. Use - for a key you do not want to restrict; the query then returns all records for the remaining keys. Values must be in internal format, so material 100100 is 000000000000100100 in a system with 18-character numbering. Enter the validity date as YYYYMMDD. The report uses a dynamic FROM and WHERE because the table name changes, wrapped in TRY so a wrong table or field name shows a readable error.

**Bullets:**

- Run it first with only KAPPL and KSCHL keys to see how many records exist.
- Deleted records (LOEVM_KO = X) are excluded.

#### Reading the result and common gotchas

**Body:** For amount conditions KBETR is the rate per KPEIN KMEIN in currency KONWA, for example 245.50 USD per 1 EA. For percentage conditions KONWA is % and KBETR is stored in per mille, so 100.00 means 10 percent and -30.00 means a 3 percent discount: the code divides by 10. Overlapping validity periods are split by SAP when you maintain records, so normally one record is valid per key and date. If you see two, check whether they come from different condition tables in the access sequence; pricing searches the accesses in KOLNR order and stops at the first record found when the access is marked exclusive.

#### How to check in the system

**Body:** Compare the output with VK13 for sales conditions or MEK3 for purchasing conditions, using the same condition type, key combination and date. In a sales order, the pricing analysis in the conditions tab shows which access and table found the record. For purchase orders, ME23N conditions and the info record (ME13) should show the same rate. SE16 on the A table with the KNUMH, then KONP with that KNUMH, reproduces the join by hand. If VK13 shows a record the report misses, check the key format and the validity date first.

**Cta:** If your pricing team wants to ask ECC which condition is valid for a customer and material in plain English on your own servers, we can build that on top of queries like this one.

**Faq:**

#### What is a condition table in SAP SD and MM?

**Answer:** A condition table defines the key combination for condition records, for example sales org plus distribution channel plus material. SAP generates a database table named A plus its number (A004, A005, A017) holding the key, the validity dates and KNUMH. The rate itself is not in the A table; it is in KONP under that KNUMH.

#### Which table stores PO conditions in SAP ECC?

**Answer:** Conditions in a purchase order document are stored in KONV, linked from EKKO-KNUMV. Master conditions such as info record prices live in A017 or A018 plus KONP. In S/4HANA document conditions moved to PRCD_ELEMENTS, while master condition tables and KONP remain.

#### How do I find the condition table for a condition type?

**Answer:** Read T685 for the condition type to get its access sequence (KOZGF), then T682I for that access sequence to get each KOTABNR in access order. The table name is A plus KOTABNR. In customizing, V/07 shows access sequences for sales and M/07 for purchasing.

#### How do I create a condition table in SAP SD?

**Answer:** Use V/03 in sales (M/03 in purchasing), choose fields from the field catalog, and generate the table. Customer tables use numbers 501 to 999. Then add the table to an access sequence (V/07) and maintain records with VK11. This generator only reads records; it does not create tables.

## Search terms

condition table in sap sd, sap table for sd pricing condition records, po conditions table in sap, sap sd table of condition table, what is condition table in sap mm, a004 konp join, konp konm scale table, t682i access sequence tables

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