Monday, 5 January 2009

BSEG Table: Just avoid it

The BSEG Table, the "Accounting document segment" is a cluster table that, as far as I understand, stores all the information for almost every financial movement on the SAP system. As you can maybe guess, this can be (and IS) a huge table, and there is a lot of information there that, to be read takes HUGE amount of time. Because of this, programmers (and users) do not like to read (or use programs that read from) the BSEG table directly. As a cluster table, this is not a real DB table, but a somehow "logical" table and you can use the real DB tables that make this big monster, instead.

The structure for this is:

BKPF: Is the Accounting document header, therefore, the hub that links all the others...

And all the others are:
I (Open Items):
BSIK [K (Vendors)]
BSID [D (Customers)]
BSIS [S (G/L Accounts)]

A (Cleared Items)
BSAK [K (Vendors)]
BSAD [D (Customers)]
BSAS [S (G/L Accounts)]

This shows how all table relate to each other and how the name scheme works. It becomes much clearer now!

Another tip I just read: The key for the BSEG table is built from the BUKRS, BELNR, GJAHR and BUZEI fields. If you can get the first three fields, the fourth can be used in the select even if you don't have it. Just create an empty RANGES for that field and in the WHERE clause, use something like 'BUZEI IN EMPTY_RANGE' to give the whole key to the compiler.

1 comment:

Anonymous said...

Hi! Such tip you recommend is useless. There is no point to provide an emtpy range as a fourth key field in WHERE clause. Still only first three key fields will be used for index range scan performed by database.

Adrian