04-03-2008 5:07 PM
Hi,
I need to increase the performance of an abap report using the field-symbols. More exactly the code is the following.
TYPES:
BEGIN OF itab_structure.
INCLUDE STRUCTURE nameofstructure.
TYPES:
RECNO LIKE sy-tabix,
END OF itab_structure.
DATA:
itab TYPE STANDARD TABLE OF itab_structure
WITH HEADER LINE
WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
SORT itab ASCENDING BY f1.
LOOP AT itab WHERE f1 = '10'.
...
itab-fn= value-n.
...
MODIFY itab
TRANSPORTING fx fy fz ft
WHERE f1 = c1_filed AND
f2 = c2_field.
ENDLOOP.
I need your suggestions in this kind of conversion or solution.
SORT itab ASCENDING BY f1 (<-- I don't know if in this case the better performances should be obtained using field symbols and in which way)
FIELD-SYMBOLS: <fs_itab_line> TYPE LINE OF itab.
LOOP AT itab ASSIGNING <fs_itab_line> WHERE
...
<fs_itab_line>-f1 = '10'.
...
MODIFY itab
TRANSPORTING fx fy fz ft
WHERE f1 = c1_filed AND
f2 = c2_field.
(I don't know if in this case the better performances should be obtained using field symbols and in which way)
ENDLOOP.
I wish to implement the field symbols or the better performance in terms of execution time in all my abap code, where it is possible.
Any suggestion will be well appreciated.
Thanks in advance for your kind support.
Regards,
Giovanni
04-03-2008 6:03 PM
Hi Giovanni.
Yes, field symbols will improve the performance, when you are modifying internal table lines. A field symbol points to the line value, and that means that you don't need to transfer the value from the itab line to work area (into wa), and then from the work area to the itab line (modify).
The sort, won't make it better.
Now, remember that if you are using LOOP .. ASSIGNING, you don't need to use MODIFY.
Loop AT itab ASSIGNING <fs>.
<fs>-variable = '123'.
ENDLOOP.
This makes, all lines of itab having '123' in column 'variable'.
Best regards.
Valter Oliveira.
04-04-2008 12:46 AM
Hello Giovanni,
Your first loop run can be simplified and improved by using field-symbols:
LOOP AT itab WHERE f1 = '10' ASSIGNING <pointer>.
...
<pointer>-fn= value-n.
...
ENDLOOP.
This technique saves time and coding!
Regards,
Heinz
04-04-2008 6:54 AM
Hi,
Field symbols are a type of pointer to the memory location. So using field symbol in loops, modify etc is always faster then loop with header line or with a work area. In the latter case data has to be copied from the table to the header line/work area. But with field symbol you can directly go to the specified record in the internal table.
-Regards
ashim
04-04-2008 11:05 AM
Dear All,
I have appeciated your suggestions and I can conclude these points in my case:
1) The "sort" statement is not optimized in a different way using filed-symbols
2) The loop with "where" condition on a standard table is performed using filed-symbols
But ... my last point to investigate is about the statement MODIFY table TRANSPORTING f1, f2 WHERE conditions.
More exactly, in my code the execution logic of the abap code expects a global modification of the same table at the end of every (primary) loop, using the MODYFY statement.
In other words in my code I can locate two loops on the same table in the following logic:
LOOP AT table1 WHERE f1 = '10'. (#1)
...
updates to table1
set c1_filed, c2_filed
...
LOOP AT table1. (#2)
IF f1 = c1_filed AND
f2 = c2_filed.
table1-fx = 'x'.
table1-fy = 'y'.
table1-fz = 'z'.
table1-ft = 't'.
ENDIF.
MODIFY table1.
ENDLOOP. (#2)
ENDLOOP. (#1)
In better way (maybe more fast in terms of execution time) to modify a set of lines (MODIFY...TRANSPORTING...WHERE):
LOOP AT table1 WHERE f1 = '10'.
...
table1-fx= 'x'.
table1-fy= 'y'.
table1-fz= 'z'.
table1-ft= 't'.
...
MODIFY itab
TRANSPORTING fx fy fz ft
WHERE f1 = c1_filed AND
f2 = c2_field.
ENDLOOP.
My aim is to use field-symbols everywhere possible for speeding up the execution of my code,by maintaining this logic.
My proposal should be the following but I need your kind opinion.
FIELD-SYMBOLS: <fs_#1_line> TYPE LINE OF table1.
FIELD-SYMBOLS: <fs_#2_line> TYPE LINE OF table1.
LOOP AT table1 WHERE f1 = '10' ASSIGNING <fs_#1_line>. (#1)
...
updates to table1
set c1_filed, c2_filed
...
LOOP AT table1 ASSIGNING <fs_#2_line>. (#2)
IF <fs_#2_line>-f1 = c1_filed AND
<fs_#2_line>-f2 = c2_filed.
<fs_#2_line>-fx = 'x'.
<fs_#2_line>-fy = 'y'.
<fs_#2_line>-fz = 'z'.
<fs_#2_line>-ft = 't'.
ENDIF.
ENDLOOP. (#2)
ENDLOOP. (#1)
Your kind support is very important for me.
Thanks in advance.
Regards,
Giovanni
04-24-2008 8:54 AM
Hi!
Using field symbols is always a good idea, when you can use them: if your internal tables are not write-protected.
But if your internal tables start to grow, you will probably see more benefit from using sorted tables with keys f1 and f2, because LOOP AT WHERE and MODIFY WHERE are only optimized when used on sorted tables. You can sort standard tables, but the compiler does not rely on this to optimized read access.
I would prefer to use MODIFY WHERE, because most of the processing work is done by the kernel directly.
But as nearly always, the right answer for performance questions can only be found by measuring different approaches, because there is a great dependency on size and runtime environment.