Use of Field-symbols vs Work area

By | December 15, 2009 | Performance | 108,371 | 13

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:

More Performance Tuning tips in ABAP

Check out the other threads to learn more Performance Tuning in ABAP:

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

13 Comments

  • Anonymous

    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!

  • christian

    Nice Test!
    Thank you for the hint!

  • Anonymous

    This is a good one for new comers…..
    Ultimate results….
    Hoping for other readings …….

  • Anonymous

    Thanks a ton!!!!

  • Sriram Murthy

    hai ,,,

    i copied the whole code what u have given in abap editor but it is showing all the values as zeros….

  • Naimesh Patel

    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.

    Do 100 times.
      append wa_bseg to i_bseg.
    enddo.
    

    Regards,
    Naimesh Patel

  • Sriram Murthy

    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.

  • Naimesh Patel

    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

  • Sriram Murthy

    thanks dude….

  • Suresh

    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

  • Ffposts

    Great article and well written ABAP code snippet.

  • rahul

    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.

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.