Parallel Cursor Method in SAP ABAP

alan9187 / Pixabay

ABAP Development Using Parallel Cursor Method

Performance is a very important point in program building. ABAP include, with each new version released, improved sentences for data base accessing, new kinds of internal tables… everything dedicated to get a better performance in the code built. There is a lot of investigation to be done as it is a complex and extremely wide area.

Although it is not always easy to have an adequate development environment to carry out acceptable volume test (as in real productive systems) that would help identify performance issues in the programs, there are some tools in the SAP Workbench that can be used to optimize the programs that are going to be delivered, mainly focused on database accessing. It is very important to analyze the SQL sentences to ensure the ones being used are the right ones. SAP provides with two powerful tools, such as the Runtime analysis (SE30) and the SQL Trace (ST05). They show how open SQL statements are converted into native SQL statements, measure database accesses and help to improve program performance. The correct use of the FOR ALL ENTRIES clause, the optimization in the selection of fields on SELECT clause and in the WHERE clause restriction, the use of indexes when accessing data… These are some of the important points that have to be taken into account. However, the ABAP program will handle and process the data after it is retrieved from the database. This is an important area that should not be forgotten when optimizing programs performance.

Parallel Cursor Program in SAP ABAP

This will explains the parallel cursor method (PCM), a method that can be used to improve the programs performance in this second important point, when handling header and position records together. This is explained with a real life example, comparing the results obtained with two different versions of source code, one with the traditional data handling and one applying the method. The white paper also gives technical instructions to apply the method in the special case when the tables have a different key.

Sequential Method

Get the starting Run time.
Loop the header internal table. Inside the master loop, item data will be looped and if any item data found, both the header and item data will be moved to another internal table.
Get the Ending Run Time.
The difference in End and Start run time is the actual time taken for sequential search.

SORT
BY ASCENDING. SORT BY ASCENDING. CLEAR:
. GET RUN TIME FIELD LOOP AT
INTO
. CLEAR: . LOOP AT INTO . WHERE EQ
. Process the Header and Item data. ENDLOOP. ENDLOOP. GET RUN TIME FIELD Total Time = End Time – Begin Time.

Parallel Method

Sort the header and item internal table.
Get the starting Run time.
Loop the header internal table. Inside the master loop, Item data will be looped by checking the index.
If the key field of item data is greater than the key field of header data, then there is no item data is found and exit from the detail loop.
If item data is equal to the key field of header data, move the header and item data to another internal table. Store the index of the item data. And continue the process.
Get the Ending Run Time.
The difference in End and Start run time is the actual time taken for Parallel Cursor.

SORT
BY ASCENDING. SORT BY ASCENDING. CLEAR:
. INITIALIZE Index Variable GET RUN TIME FIELD LOOP AT INTO . CLEAR:
. LOOP AT
INTO . FROM IF Greater Than
No Data found in the item internal table. Exit. ELSE Equal to
Store the Index of the item internal table into a variable. Process the Header and Item data. ENDIF. ENDLOOP. ENDLOOP. GET RUN TIME FIELD Total Time = End Time – Begin Time.A program with the right functionality and smartly written, but with poor performance will not satisfy the client requirements. Business programs usually handle huge amounts of data. ABAP programs in SAP implementations are not an exception to this, and they need to give the user acceptable response times before they can be delivered to the client. Therefore, every developer should pay special attention to performance when building programs. Although too many times the development environment will not have an adequate data volume (and nearly always not as in real productive systems), there is always a lot that can be done to deliver good programs from a performance standpoint.Database accesses are probably the first focus point; wrong sentences searching records in tables may lead to extremely poor response times, and this needs to be taken care of. However, there is another important area to bear in mind, which is forgotten more often that it could be thought: data processing within the program. This white paper, oriented to developers and technical designers, will explain an amazing alternative way of processing data (applicable when handling together header and position records) that will give great response times, making it possible to build complex programs that need to process big amounts of data in an acceptable time and achieving customer satisfaction.

back to abap tutorials.

3 thoughts on “Parallel Cursor Method in SAP ABAP

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: