You are on page 1of 4

ZEVOLVING

7/2/2019 Use of REFERENCE variable vs Workarea vs Field-Symbols | ABAP Help

e.g. ABAP Objects

> Home > Performance Use of REFERENCE variable vs Workarea vs Field-Symbols

Use of REFERENCE variable vs Workarea vs Field-Symbols


By Naimesh Patel | March 13, 2014 | Performance |  22,323 |  4

Along with ASSIGNING addition for the itab processing, we have REFERENCE INTO. Let’s take a deep dive into its usage.

REFERENCE INTO
Since ABAP release 610 , we can specify the REFERENCE INTO with Internal table operations like LOOP, READ etc. In order to use the reference
variable, you need to define the variable using REF TO. The variable than be declared as the data reference object. Since you define the variable with
specific type, it has all the components of that type. Once the variable is referenced, you can then use the operator -> to access the individual components,
same as you try to access any attribute of an object.

Sample code to work with REFERENCE INTO

DATA: t_t100 TYPE STANDARD TABLE OF t100.


DATA: lr_t100 TYPE REF TO t100. " << Reference variable

SELECT *
FROM t100 INTO TABLE t_t100 UP TO 10 ROWS.

LOOP AT t_t100 REFERENCE INTO lr_t100. " << working with it


WRITE: / lr_t100->msgnr. " << Accessing the component
lr_t100->msgnr = '999'.

ENDLOOP.

LOOP AT t_t100 REFERENCE INTO lr_t100.


WRITE: / lr_t100->msgnr.
ENDLOOP.

Performance Comparison
Since you can also access the itab records using Workarea and Field-Symobls, I thought of extending the earlier program used in the article Use of Field-
Symbol vs WA to include the performance measurement of working with the Reference variable as well.

Demo Program - Performance Comparison

REPORT ztest_np_loop_reference.

*
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_diff_r LIKE lv_diff_w,
lv_save LIKE lv_diff_w.
*
FIELD-SYMBOLS: <fs_bseg> LIKE LINE OF i_bseg.

DATA: o_bseg TYPE REF TO 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: /(30) 'Work area', lv_diff_w. TOP
* End - Processing with Work Area
*
CLEAR: lv_flag,
zevolving.com/2014/03/use-of-reference-variable-vs-workarea-vs-field-symbols/ 1/4
lv_sta_time,
7/2/2019 Use of REFERENCE variable vs Workarea vs Field-Symbols | ABAP Help
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: /(30) 'Field-Symbol', lv_diff_f.
* End - Processing with FS
*
* Net time saving
lv_save = lv_diff_w - lv_diff_f.
WRITE: /(30) 'Total Save (FS-WA)', lv_save.
*
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 REFERENCE INTO o_bseg.
IF lv_flag = 'X'.
o_bseg->sgtxt = 'TEST'.
ENDIF.
IF lv_flag IS INITIAL.
lv_flag = 'X'.
ENDIF.
ENDLOOP.
GET TIME STAMP FIELD lv_end_time.
lv_diff_r = lv_end_time - lv_sta_time.
WRITE: /(30) 'Reference', lv_diff_r.
* End - Processing with FS
*
* Net time saving
lv_save = lv_diff_f - lv_diff_r.
WRITE: /(30) 'Total Save(Ref-FS)', lv_save.

WRITE: / 'Done'.

Average Results on Graph:

Verdict
Field-symbols gives highest performance improvement compared to Workarea and Reference variable. Field-Symbols is still a winner of the race, when
there more data. So, if you are using FS, keep using it. If you want to use more object oriented like data access, use the REFERENCE INTO.

Tags

Field-Symbol ITAB ITAB Performance Performance

Naimesh Patel {273 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 :
TOP
Explore all of his 273 articles.

zevolving.com/2014/03/use-of-reference-variable-vs-workarea-vs-field-symbols/ 2/4
4 Comments
7/2/2019 Use of REFERENCE variable vs Workarea vs Field-Symbols | ABAP Help

Steve Oldner
# March 14th, 2014 at 5:19 am

This is where the cool people learn!

Thanks for the performance compare. Now I need to try this myself!

Himansu Gyala
# March 19th, 2014 at 11:21 pm

I always try to use field symbols in my programs, but REFERENCE INTO is a new for me as I never used in my program. Like your this
post too

Regards,
Himansu

Kris @ How ABAP


# March 20th, 2014 at 3:09 am

Hai Naimesh thank you for this code benchmark test, I learn so much from this tutorial. I think the reason why field symbol is faster is
because it doesn’t have to use modify to update afield, such as modify itab from ld_itab, whenever we assign a new value into -col
then it will automatically update the field.

bilen Cekic
# March 28th, 2014 at 12:35 am

on internal table looping, reference into is only for ppl who likes OO fetish.
field symobol is deferenced version of reference. To use reference on displaying, reading,writng you need to derefere (which means
converting to field symbol).
So be a good boy and use field symbol.

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

Subscribe
Keep in touch. We would do great working together.
1400
Subscribe to Email

Follow @zevolving

your email

ABAP Help Blog


3,847 likes

Like Page Contact Us

Be the first of your friends to like this

Current Poll
Do you like Quality Assurance of your Build/Design?
YES. I live for it!
I don't mind
NO. I hate it

Vote
TOP
View Results
zevolving.com/2014/03/use-of-reference-variable-vs-workarea-vs-field-symbols/ 3/4
7/2/2019 Use of REFERENCE variable vs Workarea vs Field-Symbols | ABAP Help

Search
Search in Zevolving

Easy to carry, BPA Free & FDA


Premium Lunchboxes Approved Lunchboxes keep
from Vaya food fresh and warm up to 6
hours

zevolving.com is founded by and maintained by Naimesh Patel. You can help by submitting your articles via Write a Post. The site is built on Wordpress.

Happy Designing!

About Subscribe Advertise Licence

All product names are trademarks of their respective companies. zevolving.com is not affiliated with SAP AG.

TOP

zevolving.com/2014/03/use-of-reference-variable-vs-workarea-vs-field-symbols/ 4/4

You might also like