To use the Field-symbols against the Work Area for Internal table processing. We’ll also measure the difference between both of the techniques.
Basics
Internal table processing is essential part of any ABAP program. Generally, we use the explicit work area to process the internal table like appending & modifying records. We can reduce the time and improve the performance of the program by using the field-symbols.
Check out Code Snippet ABAP Field Symbols usage to know basics from usage from declaration, append, insert, read, modify to check using IS ASSIGNED. Also check out ABAP Field Symbols usage – Advanced use to know bit more advanced usage of Field-Symbols.
When we use the LOOP construct with the explicit work area, system need to engage the resources to put the required record in the work area, process it and move it back to the table if the needed. This additional processing time could be saved by using the field-symbol. By using the field-symbols we can save this additional time and improve the performance. Field-symbols are similar to de-referenced pointers in C. While using the field-symbol, system uses the same memory allocated to that particular field in the record instead of moving it to work area and processing. More on field-symbols can be found at: Field-Symbols on SAP Help.
This code snippet shows how to use the field-symbols to process the loop with time measurement.
Demo to measure performance
Check out this demo application to measure the performance while using Field-Symbols and workares.
*&---------------------------------------------------------------------* *& Illustrate the performance gain by using the field-symbols *& over header areas *&---------------------------------------------------------------------* * REPORT ztest_np_loop_fs. * DATA: i_bseg TYPE STANDARD TABLE OF bseg, wa_bseg LIKE LINE OF i_bseg. * DATA: lv_flag TYPE flag, lv_sta_time TYPE timestampl, lv_end_time TYPE timestampl, lv_diff_w TYPE p DECIMALS 5, lv_diff_f LIKE lv_diff_w, lv_save LIKE lv_diff_w. * FIELD-SYMBOLS: <fs_bseg> LIKE LINE OF i_bseg. * * data selection = 10,000 records SELECT * FROM bseg INTO TABLE i_bseg UP TO 100 ROWS. * * Begin - Processing with Work area GET TIME STAMP FIELD lv_sta_time. LOOP AT i_bseg INTO wa_bseg. IF lv_flag = 'X'. wa_bseg-sgtxt = 'TEST'. MODIFY i_bseg FROM wa_bseg. ENDIF. CLEAR wa_bseg. IF lv_flag IS INITIAL. lv_flag = 'X'. ENDIF. ENDLOOP. GET TIME STAMP FIELD lv_end_time. lv_diff_w = lv_end_time - lv_sta_time. WRITE: /(15) 'Work area', lv_diff_w. * End - Processing with Work Area * CLEAR: lv_flag, lv_sta_time, lv_end_time. * Begin - Processing with Field-Symbols GET TIME STAMP FIELD lv_sta_time. LOOP AT i_bseg ASSIGNING <fs_bseg>. IF lv_flag = 'X'. <fs_bseg>-sgtxt = 'TEST'. ENDIF. IF lv_flag IS INITIAL. lv_flag = 'X'. ENDIF. ENDLOOP. GET TIME STAMP FIELD lv_end_time. lv_diff_f = lv_end_time - lv_sta_time. WRITE: /(15) 'Field-Symbol', lv_diff_f. * End - Processing with Work Area * * Net time saving lv_save = lv_diff_w - lv_diff_f. WRITE: /(15) 'Total Save', lv_save. WRITE: / 'Done'.
Some statistics:
In this performance measurement, time taken by the work area to process is considered as the 100%. By using the field-symbols, we can definitely improve the performance.
More Field-Symbol articles
Here are few more Field-symbol articles:
- Code Snippet ABAP Field Symbols usage
- Code Snippet ABAP Field Symbols usage – Advanced use
More Performance Tuning tips in ABAP
Check out the other threads to learn more Performance Tuning in ABAP:
- Write Green Programs
- ABAP Performance for DELETE on ITAB
- FOR ALL ENTRIES – Why you need to include KEY fields
- Use of REFERENCE variable vs Workarea vs Field-Symbols
- ABAP Parallel Cursor – Things to Remember
- ABAP build a table with Unique Keys – Performance Comparison
- ABAP Internal Table Secondary Key Performance comparison
- ABAP Internal Table Performance for STANDARD, SORTED and HASHED Table
- Performance of Using Keys in SELECT with FOR ALL ENTRIES
- Performance of ITAB Copy
- READ-ONLY attribute vs GETTER methods
- Measure the Performance between Break-Points using SE30
- Use of Field-symbols vs Work area
- Parallel Cursor – 2: without using READ
- Parallel Cursor – To speed up performance of Nested LOOP
Hi Naimesh,
thank's for your work. Great benchmark
serge
I have enjoyed both of the loop posts. Although I use your techiques, these posts are an excellent way to show the newer ABAPPERs.
Thanks!
Nice Test!
Thank you for the hint!
This is a good one for new comers…..
Ultimate results….
Hoping for other readings …….
Thanks a ton!!!!
hai ,,,
i copied the whole code what u have given in abap editor but it is showing all the values as zeros….
Hello Sriram,
Probably, you don’t have data in the table BSEG. If you don’t have data, you can replace the select query with DO… ENDDO.
Regards,
Naimesh Patel
thanks buddy for u quick reply. i tried to open the contents of the bseg table but it is showing the run time error that storage error. like sap r/3 has requested os ****bytes of memory with malloc but it is not there . at the time of installtion blablabla….
what can i do now to check the contents of bseg.
I am not much familiar with that problem. Looks like you need help from BASIS / DBA.
If you want to test the program, you can replace I_BSEG with any other internal table. Replace the SELECT query and also make sure you change other references accordingly.
Regards,
Naimesh Patel
thanks dude….
Need simple way of understanding the concept behind Radio Button , Radio button group by index and Radio button group by key in Web Dynpro with simple example please. Define their differences and also when to use what?
regards
suresh
Great article and well written ABAP code snippet.
when i created report the header and footer is displayed but when the report is ended before the line count as mentioned in the program the footer is not displayed then how to display the footer in the program when the report is ended before the line count.