SAPHub

Performance in SAP SD Customer Developments.

Sometimes we experience bad performance while accessing the following SAP SD tables:
•         VBAK – Sales Document: Header Data
•         VBAP – Sales Document: Item Data
•         LIKP – SD Document: Delivery Header Data
•         LIPS – SD document: Delivery: Item data
•         VBRK – Billing: Header Data
•         VBRP – Billing: Item Data
•         VBFA – Sales Document Flow

The R/3 System contains no secondary indexes to the most important SD transaction data tables in the delivery. Instead, the R/3 System has proprietary index tables (sales document indexes, for example the tables VAKPA and VAPMA, matchcode tables for example M_VMVAB, M_VMVAC or matchcode views for example M_VMVAA, M_VMVAE), which allow an efficient access.

Consider the following NOTES mentioned in SAP Note 185530 while accessing SAP SD tables in order to improve the performance:

1. Search for deliveries with sales order number (preceding document, field LIPS-VGBEL):

Incorrect:

SELECT FROM lips WHERE vgbel = ...

Correct:

SELECT FROM vbfa WHERE VBELV = ... 
                   AND VBTYP_N = 'J' 

SELECT FROM lips WHERE vbeln = vbfa-vbeln                    
                   AND posnr = vbfa-posnn 

2. Search for invoices with delivery number (preceding document, field VBRP-VGBEL):

Incorrect:

SELECT FROM vbrp WHERE vgbel = ... 

Correct:

SELECT FROM vbfa WHERE vbtyp_n = 'M'                    
                   AND vbelv = ... 

SELECT FROM vbrp WHERE vbeln = vbfa-vbeln                    
                   AND posnr = vbfa-posnn  

3. Search for invoices with order number (preceding document, field VBRP-AUBEL):

Incorrect:

SELECT FROM vbrp WHERE aubel = ... 

Correct:

SELECT FROM vbfa WHERE vbtyp_n = 'M' 
                   AND vbelv = ... 

SELECT FROM vbrp WHERE vbeln = vbfa-vbeln                    
                   AND posnr = vbfa-posnn 

4. Document flow:

Incorrect:

SELECT vbelv FROM vbfa WHERE vbeln ...

In table VBFA only the preceding document is used to search for the subsequent document (for example, delivery for order). Searching the other way makes no sense with this table since the preceding documents (for example, order for delivery) are stored directly in the document tables. Thus reading in table VBFA is a one-way street.

Correct:

SELECT vgbel FROM lips WHERE vbeln = ...; or
SELECT vgbel FROM vbrp WHERE vbeln = ...; or
SELECT aubel FROM vbrp WHERE vbeln = ...

Search for shipping unit item with delivery

Incorrect:

SELECT FROM vepo WHERE vbtyp = 'J'
                   AND vbeln = i_lips-vbeln

Correct:

SELECT FROM vbfa WHERE vbtyp_n = 'X'
                   AND vbelv = i_lips-vbeln

SELECT FROM vepo WHERE venum = vbfa-vbeln

Refer to SAP Note 185530 for more information.