For modify itab transporting F1... An interesting test of FN statements

Source: Internet
Author: User

Original post address: http://abaper.blogbus.com/logs/2705034.html

First look at the following two procedures. Which one do you think is faster?

Data Definition and extraction:
Data: Begin of it_marc occurs 0,
Matnr like Marc-matnr,
Werks like Marc-werks,
Dispo like Marc-dispo,
Plifz like Marc-plifz,
End of it_marc.

Select matnr werks
Into Table it_marc
From Marc.

Procedure 1:
Loop at it_marc.
It_marc-dispo = 'g00 '.
It_marc-plifz = 5.
Modify it_marc.
Endloop.

Procedure 2:
Loop at it_marc.
It_marc-dispo = 'g00 '.
It_marc-plifz = 5.
Modify it_marc transporting dispo plifz.
Endloop.

The only difference between the two programs is the use of the modify statement. In program 2, the transporting clause is used,
Only the dispo and plifz fields are updated when updating internal table records.

My intuition is that program 2 should run faster. After all, there is less updated data.

However, the running result is unexpected. The 10 running times are as follows:
Procedure 1, Procedure 2
122,167 128,485
120,686 128,306
120,732 128,273
120,737 128,273
120,725 128,278
120,418 128,323
120,648 128,267
121,187 128,246
120,741 128,023
120,647 128,012

Obviously, a program runs faster than Program 2, which is about 6% faster. Why? I really don't understand.

In SAP's official documentation, the transporting clause provides the following explanation:
With the modify variant "Modify itab... transporting F1 F2 ..."
The task of updating a line of an internal table can be accelerated.
The longer the table line is, the larger the speed-up is.
The effect increases for tables with complex structured line types.

From the above explanation, the larger the structure of the internal table, the more effective the transporting clause is,
So I modified the definition of it_marc as follows:

Data: it_marc like table of MARC with header line.

Run again. The 10 running times are as follows:
Procedure 1, Procedure 2
341,469 311,265
340,983 311,268
341,285 311,432
341,364 311,395
341,630 311,928
341,324 311,358
341,280 311,439
341,328 311,247
341,577 311,269
341,312 311,227

In this case, Program 2 is more efficient than program 1, which is about 9% faster.

Of course, in most cases, the internal table we use is not as big as Marc, and it seems necessary to seek a balance point.
I did a test to gradually increase the structure of the internal table. When the internal table size is 150 bytes,
The running time of programs 1 and 2 is basically the same.

In fact, for the above functions, the modification speed with field-symbols is the fastest, and the speed is about doubled. The following is an example:
Field-Symbols: <FS> like line of it_marc.
Loop at it_marc assigning <FS>.
<FS>-dispo = 'g00 '.
<FS>-plifz = 5.
Endloop.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.