Parallel Cursor Method in ABAP

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.

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.

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 <Header Internal Table> BY <Key Field> ASCENDING.
SORT <Item Internal Table> BY <Key Field> <Key Field> ASCENDING.
 
CLEAR: <Header Work Area>.
GET RUN TIME FIELD <Begin Time>
LOOP AT <Header Internal Table> INTO <Header Work Area>.
    CLEAR: <Item Work Area>.
    LOOP AT <Item Internal Table> INTO <Item Work Area>.
                         WHERE <Key Field> EQ <Header Key Field>.
        Process the Header and Item data.
    ENDLOOP.	
ENDLOOP.
GET RUN TIME FIELD <End Time>
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 <Header Internal Table> BY <Key Field> ASCENDING.
SORT <Item Internal Table> BY <Key Field> <Key Field> ASCENDING.
 
CLEAR: <Header Work Area>.
INITIALIZE Index Variable
GET RUN TIME FIELD <Begin Time>
LOOP AT <Item Internal Table> INTO <Item Work Area>.
    CLEAR: <Header Work Area>.
     LOOP AT <Header Internal Table> INTO <Item Work Area>.
                         FROM <Index Number>
        IF <Item Key Field> Greater Than <Header Key Field>
	No Data found in the item internal table. 
            Exit.
        ELSE <Item Key Field> Equal to  <Header Key Field>	
            Store the Index of the item internal table into a variable.
            Process the Header and Item data.
       ENDIF.
    ENDLOOP.	
ENDLOOP.
GET RUN TIME FIELD <End Time>
Total Time = End Time – Begin Time.

back to abap tutorials.

Comments