Index Support for Determination of Segment Numbers 

When a document is posted to Profitability Analysis, the system has to find a profitability segment number for the combination of characteristic values supplied by that document. It is extremely important that the system be able to do this as quickly as possible; otherwise, the overall throughput can slow down considerably when you transfer external data or post collective invoices (cases in which you post to a large number of profitability segments at the same time).

This section describes from a technical point of view how the system finds the segment number and addresses potential problems. This information is valid for all releases beginning with 2.1A.

Data Structure of the Segment Table

The most important elements of the segment table CE4xxxx are the segment number, which is found in the key of the table, and the characteristics of your operating concern, which form the data part. Table CE4xxxx is structured as follows:

Field name

Key

Comment

MANDT

X

Client

AKTBO

X

currently always "X"

PAOBJNR

X

Profitability segment number

PASUBNR

X

currently always "0001"

KNDNR

 

Customer number

ARTNR

 

Material number

FKART

 

Record type

other fixed characteristics

characteristics defined in the operating concern in Customizing

additional technical fields

 

Each segment number represents a specific combination of characteristic values.

Selection from the Segment Table to Find the Segment Number

When a document (such as a billing document or document from order settlement or external data) is posted to Profitability Analysis, the system needs to determine the appropriate segment number based on the combination of characteristic values supplied by the document. To do this, the system selects from the segment table using all the values specified in the data part. The selection looks like this:

 

SELECT * FROM CE4xxxx

WHERE AKTBO = "X"

AND KNDNR = ...

AND ARTNR = ...

AND FKART = ...

AND (all other characteristics specified)

 

A client condition is also implicitly specified by the ABAP/4 runtime system!

The Standard Secondary Index

The speed with which the system finds segment numbers in the segment table is extremely important for overall system performance in transferring collective invoices, external data or postings (such as order settlement, direct postings from FI) to profitability segments.

The primary index (index ID 0) to the key of the segment table is not well-suited for the above selection. Consequently, SAP tries to support this special access by means of a suitable secondary index (index ID 1). In the standard system, this index contains some of fixed characteristics which are found in every operating concern:

 

Use of indexes for search queries

An index contains a copy of just a few fields of a database table. In the index these fields are sorted -- in contrast to the data in the table itself. This makes it possible for the system to access the data in the index more quickly. Furthermore, each index entry "points" to the corresponding data record in the table.

When conditions are specified for fields contained in an index during a search request, the system can process part of the search request simply using the data contained in the index. As a result, certain index entries -- and their corresponding data records -- can be ruled out without the system having to read the table directly.

The system then needs to read the data records in the table which correspond to the remaining index entries. Only then can it be determined whether a data record also fulfills the rest of the search request, that is, whether it makes the hit list. The time needed to read complete data records is long, compared with that needed to read the index.

Consequently, one should try to define the index so that the number of data records that need to be read from the table is not much larger than the number of records that fulfill the search condition. This kind of index is referred to as a selective index, since it performs most of the selection for the search request.

1: Profitability Analysis at the customer/product level

If you are using the characteristics "Customer" and "Product" in the segment level, the system automatically transfers billing documents from SD to CO-PA with that level of detail. Thus when the system searches for the profitability segment number for a billing document item, values for both characteristics "Customer" (KNDNR) and "Product" (ARTNR) are found in the SELECT command. Both of these characteristics have a very large number of values in the segment table (they are selective fields in the segment table). As a result, the secondary index MANDT, AKTBO, KNDNR, ARTNR, BUKRS, WERKS, VTWEG is also selective, and it is possible to determine the profitability segment number quickly.

2: Profitability Analysis at a higher level

Now let us look at a system in which the characteristics "Customer" and "Product" are not segment level characteristics. (See also the chapter Master Data ® Structures ® Define Profitability Segment Characteristics (Segment-Lvl Characteristics) in Customizing).

In this case the fields KNDNR and ARTNR are empty in all the records in the segment level CE4xxxx. As a result, the aforementioned index is not selective. In this case the selection for finding the profitability segment number reads:

SELECT * FROM CE4xxxx

WHERE AKTBO = "X"

AND KNDNR = "          "

AND ARTNR = "                           "

AND FKART = fixed value

AND (all other characteristics specified)

 

The problem here is that the selective independent fields (in this case maybe the customer group and division) are specified in the selection but do not occur in the secondary index used. On the other hand, the comparatively less selective fields -- MANDT (usually one value), AKTBO (always "X"), KNDNR and ARTNR (always blank), BUKRS, WERKS and VTWEG (usually only a few different values) -- are contained in the secondary index. When the system reads this index (index range scan), it also has to read all the records of the segment table which contain the specified values for MANDT, AKTBO, KNDNR, ARTNR, BUKRS, WERKS, and VTWEG. In a worst case scenario, this could even be the entire segment table. As a result, the system may read far too much, making the request extremely slow. This in turn affects the runtimes for billing documents considerably.

These examples yield the following rule:

Rule:

A secondary index is useful for supporting segment number determination if it contains the logically unrelated, restrictive characteristics from the segment table. The fields MANDT and AKTBO must be the first fields in the secondary index, otherwise the database system reads the primary index instead.

3: A well-suited secondary index

If your system uses the characteristics "Customer" and "Product" in the segment level, you should use an index which contains the fields MANDT, AKTBO, KNDNR and ARTNR. On the other hand, if you are not using "Customer" and "Product", and if the customer group (KDGRP) and division (SPART) are the independent characteristics, it would make much more sense to use an index with the fields MANDT, AKTBO, KDGRP and SPART. Thus in order to create a suitable secondary index, you need to know the logical hierarchy of characteristics in your operating concern.

Postings to Several Hierarchical Levels

The secondary index proposed in the above rule would make it possible for the system to determine the segment number for billing documents quickly. However, another problem arises when you post data from other transactions to another hierarchical level.

3.1: External transfer of planning data at a higher level

We will now look at an operating concern which has the customer and product in the segment level, but where planning is done at the customer group (KDGRP) and division (SPART) level. Here too, the secondary index indicated above (MANDT, AKTBO, KNDNR, ARTNR) is adequate for transferring billing documents.

However, when you create plan documents at a higher level, you might have performance problems when the system tries to find the segment numbers. To do that, the system needs to read all the segment table records in which the fields KNDNR and ARTNR are blank. If a large number of these records exists, performance worsens considerably.

3.2: Account-based Profitability Analysis

A similar problem arises if you work at the customer/product level in costing-based CO-PA and these characteristics are not used in account-based CO-PA.

As a result, we need to amend the rule stated above. You should not only include the logically unrelated characteristics in the secondary index. Therefore:

Rule:

An "optimal" index for supporting segment number determination must contain -- after MANDT and AKTBO -- all the logically unrelated, restrictive characteristics for all the segment number selections (including those on higher levels).

Notes

4: Optimal secondary index

In the above example (actual data at the customer/product level and planning at the customer group/division level), a secondary index consisting of MANDT, AKTBO, KNDNR, ARTNR, KDGRP, SPART would be sufficient. If you also need profitability segments at higher levels (for example, due to cost center assessment), you need to extend this index again.

It does not make sense to create additional indexes (e.g. an index 1 with MANDT, AKTBO, KNDNR, ARTNR and index 2 with MANDT, AKTBO, KDGRP, SPART) instead of extending the first index. Since the selection condition for finding the profitability segment number is always completely specified, the system always uses the same index.

SAP strongly recommends that you replace the SAP example secondary index (index code 001) with a secondary index which is optimized for your particular circumstances.

You can check whether the secondary index you created is actually being used to find segment numbers in transaction ST05 (SQL trace) and with the pushbutton Explain SQL. See also How to Check Whether an Index Is Being Used.

The function Explain SQL shows the database’s access strategy when it processes a SELECT statement. Search for an OPEN or a REOPEN statement for table CE4xxxx in the list view of the SQL trace. Based on the time indicated there (which should lie well below 100 milliseconds), you can obtain an idea of the absolute efficiency of the selected access path.