Skip to content

BKPF / BSEG — FI Accounting Document Header and Line Items

BKPF holds one row per accounting document; BSEG holds one row per line item. The unique key is always MANDT + BUKRS + BELNR + GJAHR.

Purpose

BKPF and BSEG are the foundational FI tables. Every financial posting — vendor invoice, customer payment, manual journal entry, or SD/MM document transfer — creates one BKPF header row and at least two BSEG line items (debit and credit). Auditors, reconciliation jobs, and month-end reports all read from these tables.

Key fields

BKPF — Header

Field Type Description
MANDT CLNT(3) Client
BUKRS CHAR(4) Company code
BELNR CHAR(10) Accounting document number
GJAHR NUMC(4) Fiscal year
BLART CHAR(2) Document type (SA=GL KR=vendor invoice DR=customer invoice ZP=payment)
BLDAT DATS(8) Document date (date on the original document)
BUDAT DATS(8) Posting date (determines the period)
USNAM CHAR(12) User name of the person who posted
BKTXT CHAR(25) Document header text

BSEG — Line Items

Field Type Description
MANDT CLNT(3) Client
BUKRS CHAR(4) Company code
BELNR CHAR(10) Accounting document number (FK to BKPF)
GJAHR NUMC(4) Fiscal year
BUZEI NUMC(3) Line item number within the document
KOART CHAR(1) Account type: D=Customer K=Vendor S=GL A=Asset M=Material
HKONT CHAR(10) GL account number
KUNNR CHAR(10) Customer number (populated when KOART = 'D')
LIFNR CHAR(10) Vendor number (populated when KOART = 'K')
DMBTR CURR Amount in local (company code) currency
SHKZG CHAR(1) Debit/credit indicator: S=Debit H=Credit
SGTXT CHAR(50) Line item text

Common queries

All line items for a specific accounting document

SELECT k~bukrs, k~belnr, k~gjahr, k~blart, k~budat, k~bktxt,
       s~buzei, s~koart, s~hkont, s~dmbtr, s~shkzg, s~sgtxt
  INTO TABLE @DATA(lt_doc_lines)
  FROM bkpf AS k
  INNER JOIN bseg AS s ON s~mandt = k~mandt
                       AND s~bukrs = k~bukrs
                       AND s~belnr = k~belnr
                       AND s~gjahr = k~gjahr
  WHERE k~mandt = @sy-mandt
    AND k~bukrs = @lv_bukrs
    AND k~belnr = @lv_belnr
    AND k~gjahr = @lv_gjahr.

Customer open items (debit postings not yet cleared)

SELECT belnr, gjahr, buzei, kunnr, dmbtr, shkzg, sgtxt
  INTO TABLE @DATA(lt_cust_items)
  FROM bseg
  WHERE mandt  = @sy-mandt
    AND bukrs  = @lv_bukrs
    AND gjahr  = @lv_gjahr
    AND koart  = 'D'
    AND kunnr  = @lv_kunnr
    AND shkzg  = 'S'.

All GL postings for a period (by posting date range)

SELECT k~belnr, k~gjahr, k~budat, k~blart, k~usnam,
       s~buzei, s~hkont, s~dmbtr, s~shkzg
  INTO TABLE @DATA(lt_gl_postings)
  FROM bkpf AS k
  INNER JOIN bseg AS s ON s~mandt = k~mandt
                       AND s~bukrs = k~bukrs
                       AND s~belnr = k~belnr
                       AND s~gjahr = k~gjahr
  WHERE k~mandt  =  @sy-mandt
    AND k~bukrs  =  @lv_bukrs
    AND k~gjahr  =  @lv_gjahr
    AND k~budat  >= @lv_date_from
    AND k~budat  <= @lv_date_to
    AND s~koart  =  'S'.

Joins

Join target Key fields Purpose
BSEG MANDT + BUKRS + BELNR + GJAHR Line items for the document
KNA1 MANDT + KUNNR (from BSEG) Customer name
LFA1 MANDT + LIFNR (from BSEG) Vendor name
SKA1 MANDT + KTOPL + SAKNR GL account description

Pitfalls

NEVER select BSEG without BUKRS + BELNR + GJAHR

BSEG is one of the largest tables in any SAP system. A full table scan or a query with only GJAHR will cause severe performance problems and may time out. Always supply all three key fields: BUKRS, BELNR, and GJAHR together.

BELNR alone is not unique

Document numbers reset per company code and fiscal year. The unique key is the combination BUKRS + BELNR + GJAHR. Querying on BELNR alone will return rows from multiple company codes and years.

Prefer BSIS / BSAS or ACDOCA for period reporting

For reporting across many documents (e.g., all postings in a month), use the index tables BSIS (open GL items) and BSAS (cleared GL items), or ACDOCA on S/4HANA. These are optimised for range selects and avoid full BSEG scans.

See also

  • t001.md — Company code configuration (BUKRS master data)
  • vbak-vbap.md — SD sales orders that generate FI documents on billing

Comments