Full text & code of this article on: Use field symbols for better performance in internal tables.
Author:
James Vander Heyden
Do you want to squeeze more performance out of your Internal Table processing? The new ABAP object extensions in SAP require internal table definitions to look a little different. With this new style of definition comes many options for better performance like hash tables and sorted tables. The use of field symbols takes this performance concept one step further.
The new style of definition of internal tables usually doesn’t include a header area for the internal table. Furthermore, ABAP Objects will not allow internal tables with header lines. For added performance, instead of declaring a work area–use a field symbol. The work area concept and header line format both require data to be moved from the internal table to the work area or header area. A field symbol is just a pointer that will point to the proper line of the itab. With field symbols, no data needs to be moved. The field symbol just stores the proper memory address to point at the right line. The field symbol can have structure and be made up of fields similar to a work area or header line. Because no data needs to be copied, processing is much faster.
The keys to the usage are:
1) Defining the table records and the field symbol in a similar type.
* just an ordinary standard table
TYPES: BEGIN OF it_vbak_line,
vbeln LIKE vbak-vbeln,
vkorg LIKE vbak-vkorg,
vtweg LIKE vbak-vtweg,
spart LIKE vbak-spart,
kunnr LIKE vbak-kunnr,
END OF it_vbak_line.DATA: it_vbak TYPE TABLE OF it_vbak_line.
FIELD-SYMBOLS: <it_vbak_line> TYPE it_vbak_line.
* or as a screaming fast hash table for keyed reads
TYPES: BEGIN OF it_vbpa_line,
vbeln LIKE vbak-vbeln,
kunnr LIKE vbak-kunnr,
END OF it_vbpa_line.DATA: it_vbpa TYPE HASHED TABLE OF it_vbpa_line
WITH UNIQUE KEY vbeln.
FIELD-SYMBOLS: <it_vbpa_line> TYPE it_vbpa_line.
2) In ITAB processing, utilize the ASSIGNING command.
* loop example
LOOP AT it_vbak ASSIGNING <it_vbak_line>.
* look at records – populate it_zpartner
* read example
READ TABLE it_vbpa ASSIGNING <it_vbpa_line> WITH TABLE KEY vbeln = <it_vbak_line>-vbeln.
3) Refer to the field symbol’s fields in the loop or after the read.
wa_zpartner-vkorg = <it_vbak_line>-vkorg.
wa_zpartner-vtweg = <it_vbak_line>-vtweg.
wa_zpartner-spart = <it_vbak_line>-spart.
wa_zpartner-kunag = <it_vbak_line>-kunnr.
wa_zpartner-kunwe = <it_vbpa_line>-kunnr.
