This presentation shows how performance optimization was conducted on a certain ABAP source code that ran very, very slow (several hours to even days or weeks). It shows how the problem was detected and provides recommendations on how to tweak the code for faster performance. The following is an unformatted, plain-text transcription of the presentation:
Performance Analysis on an ABAP code that runs extremely slow.
Outline
• The First Problem
– The First Recommendation
• The Second Problem
– The Second Recommendation
The First Problem
• Analyzing the hit list of the THE_SLOW_SOURCE_CODE reveals that the “Fetch MARC” statement consumes about 70-80% of total run time.
The First Problem
The First Problem
• The “Fetch MARC” statement:
The First Problem
• So what’s so special with the “Fetch MARC” statement?
• Assuming THE_SLOW_SOURCE_CODE runs for 10 hours in Server6P, this single statement consumes around 7-8 hours.
• It accesses 3 massive tables that are growing really fast in Server6P. Next slide shows a comparison of the number of entries in Server6A and Server6P which is about 6-12 months difference since last synchronization (refresh).
The First Problem
The First Problem
• Analyzing the trace list of the “Fetch MARC” statement reveals the following:
The First Problem
The First Problem
The First Problem
• Analyzing the T_WERKS table...
The First Problem
The First Problem
• Based on the trace list, we see that the “for all entries” addition is split into chunks of 5, so that the 500 entries in T_WERKS are split into 100 native SQL statements containing 5 plant codes each.
The First Problem
The First Recommendation
• Remove the “for all entries” addition in “Fetch MARC” statement. Then use a “delete table” statement to filter out unwanted plant codes.
• Add range R_WERKS to hold T_WERKS data
• Add WERKS field in T_MDBS internal table
• DELETE TABLE t_mdbs WHERE werks NOT IN r_werks.
The First Recommendation
• We experiment with the original “Fetch MARC” statement against the first recommendation:
– Source code of first problem (abench)
– Source code of first recommendation (ctrial)
The First Recommendation
• Testing reveals a 90% drop in response time in Server6A.
The First Recommendation
• Non-negative impact testing also passed, as long as we sort T_MDBS by the same fields in the first problem and in the first recommendation, and delete duplicate adjacent entries.
The First Recommendation
• Trace list reveals a marked improvement of a 1:1 correspondence between Open SQL and native SQL statements, compared to the 1:100 ratio in the original “Fetch MARC” statement.
The First Recommendation
The First Recommendation
• Assuming, “Fetch MARC” statement consumes 70-80% of THE_SLOW_SOURCE_CODE total run time, then a 90% decrease in the statement through this first recommendation should ideally translate to a 63-72% decrease in THE_SLOW_SOURCE_CODE total run time.
The First Recommendation
• Testing the first recommendation on the actual tool in Server6A shows a decline of about 30%.
The Second Problem
• When the THE_SLOW_SOURCE_CODE tool is modified with the first recommendation, running a run time analysis yields the following hit list:
The Second Problem
The Second Problem
• “Fetch MARC” statement is now reduced to 10% of run time compared to the previous 75%.
• “Fetch EKKO” statement consumes 70% of run time.
• “Fetch EKKO” statement comes from 2 sources:
– Form F2000_103_105 (Fetch_EKKO_F2000)
– Form F4000_ISTO_RISTO (Fetch_EKKO_F4000)
The Second Problem
• Comparing Fetch_EKKO_F2000 and Fetch_EKKO_F4000 reveals several similarities in the statements.
The Second Problem
The Second Recommendation
• Merge Fetch_EKKO_F2000 and Fetch_EKKO_F4000 into a single statement: Fetch_EKKO_F1500.
• In forms F2000_103_105 and F4000_ISTO_RISTO, filter out unwanted records.
• In this way, fetching from EKKO is done only once instead of twice.
The Second Recommendation
The Second Recommendation
The Second Recommendation
• We experiment with the original “Fetch EKKO” statement and the second recommendation:
– Original (cbench)
– The second recommendation (ftrial)
The Second Recommendation
• Testing reveals 16-31% drop in run time in the “Fetch EKKO” statement.
The Second Recommendation
• Non-negative impact testing also passed, as long as:
– T_PO table is sorted with the same fields in both the original and in the second recommendation
– Adjacent duplicate entries in T_PO are deleted in both original and in the second recommendation using the same fields used for sorting
Showing posts with label EKKO. Show all posts
Showing posts with label EKKO. Show all posts
Tuesday, August 7, 2012
Performance optimization
Labels:
ABAP,
EKKO,
for all entries,
hit list,
MARC,
MDBS,
performance optimization,
SAP,
SQL,
trace list
Condition records
Condition records are used for pricing. They breakdown the details of the cost of a product. In addition to the gross price of a product, they can include other costs such as taxes, freight costs, surcharges, discounts, inspection fees, forwarding fees, handling fees, insurance fees, customs, brokerage fees, etc.
Let us take an example. Consider a purchase document as viewed via transaction ME23 as shown in Figure 1.
Figure 1. Purchase items in a purchase document viewed through ME23.
Figure 1 lists the purchase items of the purchasing document with number 4500000574. When we click on record item 2, then press the Item Conditions button as encircled in Figure 1, the condition records for purchase item 2 will be shown as displayed in Figure 2.
Let us take an example. Consider a purchase document as viewed via transaction ME23 as shown in Figure 1.
Figure 1. Purchase items in a purchase document viewed through ME23.
Figure 1 lists the purchase items of the purchasing document with number 4500000574. When we click on record item 2, then press the Item Conditions button as encircled in Figure 1, the condition records for purchase item 2 will be shown as displayed in Figure 2.
Figure 2. Sample display of condition records viewed through ME23.
From Figure 2, we are able to view the gross price, non-deductable tax, freight and cash discount conditions. The gross price costs 13,888 EUR per tone. Since the purchase item has a quantity of 3 tones, the condition value is 13,888 EUR x 3 = 41,664 EUR. The condition records also shows a freight cost which is a fixed amount of 540.61 EUR regardless of the quantity of the purchase item. Hence the total cost of the purchase item for crossing the country border is the gross price plus the freight cost: 41,664 + 540.61 = 42,204.61 EUR.
Conditions are stored in SAP through the KONV table. Figure 3 shows a description of the KONV table definition as viewed via SE11.
Figure 3. KONV table definition as seen through SE11.
To be able to find the condition records of Figure 2 in the KONV table, we need to know the KNUMV or the document condition number of the condition. (The KNUMV is a key field in the KONV table as shown in Figure 3.) To be able to know the KNUMV of a given condition, we can search this via transaction SE16 using the purchasing document header table or EKKO. In SE16, we search the EKKO table using the purchasing document number of 4500000574 or EKKO-EBELN = 4500000574. Doing this results to the table record shown in Figure 4.
Figure 4. Accessing the document condition through the EKKO table via transaction SE16.
From Figure 4, we find that the document condition number for purchase document with number 4500000574 is 1000008695. This means that EKKO-KNUMV = KONV-KNUMV = 1000008695.
We can then use this KNUMV value to access the condition records for the purchase document with number 4500000574 via transaction SE16 using table KONV. To access the condition records corresponding to the records shown in Figure 2, we note that the purchase item under consideration has value of 2. The purchase item number, technically the EBELP field of the EKPO table (EKPO-EBELP), corresponds to the condition item number, KPOSN, of the KONV table as shown in Figure 3.
Therefore to view the condition records in Figure 2, in the selection screen for the KONV table in SE16, we use a document condition number (KONV-KNUMV) of 1000008695 and an item number (KNUMV-KPOSN) of 2. Doing this results to the records in Figure 5.
Figure 5. Condition records viewed via SE16 through the KONV table.
Notice how the records in Figure 5 correspond to the records shown in Figure 2.
For the example of Figure 2, in ABAP terms, we can select the condition records through a code similar to the following.
SELECT EKKO~FIELD1
EKKO~FIELD2
EKKO~FIELD3
EKPO~FIELD1
EKPO~FIELD2
EKPO~FIELD3
KONV~FIELD1
KONV~FIELD2
KONV~FIELD3
FROM EKKO
INNER JOIN EKPO
ON EKKO-EBELN EQ EKPO-EBELN
INNER JOIN KONV
ON EKKO-KNUMV EQ KONV-KNUMV
AND EKPO-KPOSN EQ KONV-KPOSN
WHERE EKKO-EBELN EQ ‘4500000574’
AND EKPO-EBELP EQ ‘2’.
In doing so, we are able to link the EKKO, EKPO and KONV tables.
Subscribe to:
Posts (Atom)




