Use field symbols for better performance in internal tables

Do you want to squeeze more performance out of your Internal Table processing? Here's how!

This Content Component encountered an error
This Content Component encountered an error

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.

See the code example below for further detail. The code was written in R/3 4.6C and should work for all 4.x versions.
 

 REPORT z_cnv_zshipto_from_hist NO STANDARD PAGE HEADING LINE-SIZE 132 LINE-COUNT 65 MESSAGE-ID z1. ************************************************************************ * Program Name: ZSHIPTO from History Creation: 07/23/2003 * * * * SAP Name : Z_CNV_ZSHIPTO_FROM_HIST Application: SD * * * * Author : James Vander Heyden Type: 1 * *______________________________________________________________________* * Description : This program reads tables VBAK & VBPA and populates * * ZPARTNER. ZPARTNER table is read in by ZINTSC06. ZINTSC06 updates * * the ZSHIPTO relationships. * *______________________________________________________________________* * Inputs: Selection Screen * * * * Outputs: * *______________________________________________________________________* * External Routines * * Function Modules: * * Transactions : * * Programs : * *______________________________________________________________________* * Return Codes: * * * *______________________________________________________________________* * Ammendments: * * Programmer Date Req. # Action * * ================ ========== ====== ===============================* * J Vander Heyden 07/23/2003 PCR Initial Build * ************************************************************************ *----------------------------------------------------------------------* * DATA DICTIONARY TABLES * *----------------------------------------------------------------------* TABLES: zpartner. *----------------------------------------------------------------------* * SELECTION SCREEN LAYOUT * *----------------------------------------------------------------------* PARAMETERS: p_load RADIOBUTTON GROUP a1 DEFAULT 'X', p_deltab RADIOBUTTON GROUP a1. SELECTION-SCREEN SKIP 2. SELECT-OPTIONS: s_vkorg FOR zpartner-vkorg MEMORY ID vko OBLIGATORY NO INTERVALS NO-EXTENSION, s_vtweg FOR zpartner-vtweg MEMORY ID vtw OBLIGATORY NO INTERVALS NO-EXTENSION, s_spart FOR zpartner-spart MEMORY ID spa OBLIGATORY NO INTERVALS NO-EXTENSION. *----------------------------------------------------------------------* * INTERNAL TABLES * *----------------------------------------------------------------------* 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. 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. DATA: it_zpartner TYPE TABLE OF zpartner. DATA: wa_zpartner TYPE zpartner. *----------------------------------------------------------------------* * STRUCTURES * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * VARIABLES * *----------------------------------------------------------------------* DATA: z_mode VALUE 'N', z_commit TYPE i, z_good TYPE i, z_bad TYPE i. *----------------------------------------------------------------------* * CONSTANTS * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * SELECTION-SCREEN HELP * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * INITIALIZATION * *----------------------------------------------------------------------* INITIALIZATION. *----------------------------------------------------------------------* * AT LINE SELECTION * *----------------------------------------------------------------------* AT LINE-SELECTION. *----------------------------------------------------------------------* * AT SELECTION SCREEN * *----------------------------------------------------------------------* AT SELECTION-SCREEN. *----------------------------------------------------------------------* * START-OF-SELECTION * *----------------------------------------------------------------------* START-OF-SELECTION. IF p_load = 'X'. PERFORM select_records. PERFORM process_itab. ELSE. PERFORM delete_table. ENDIF. *----------------------------------------------------------------------* * END-OF-SELECTION * *----------------------------------------------------------------------* END-OF-SELECTION. ********************************************************************** ********************************************************************** *&---------------------------------------------------------------------* *& Form DELETE_TABLE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM delete_table. DATA: w_answer. CLEAR: w_answer. CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING titlebar = text-002 * DIAGNOSE_OBJECT = ' ' text_question = text-003 text_button_1 = text-004 icon_button_1 = 'ICON_OKAY' text_button_2 = text-005 icon_button_2 = 'ICON_CANCEL' default_button = '2' display_cancel_button = '' * USERDEFINED_F1_HELP = ' ' * START_COLUMN = 25 * START_ROW = 6 * POPUP_TYPE = IMPORTING answer = w_answer. * TABLES * PARAMETER = * EXCEPTIONS * TEXT_NOT_FOUND = 1 * OTHERS = 2 . IF w_answer = 1. DELETE FROM zpartner WHERE vkorg IN s_vkorg AND vtweg IN s_vtweg AND spart IN s_spart. MESSAGE i398(00) WITH 'Records deleted from table: ' sy-dbcnt ' ' ' '. ENDIF. ENDFORM. " DELETE_TABLE *&---------------------------------------------------------------------* *& Form SELECT_RECORDS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM select_records. * get vbaks CLEAR: it_vbak. SELECT vbeln vkorg vtweg spart kunnr FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak WHERE vkorg IN s_vkorg AND vtweg IN s_vtweg AND spart IN s_spart AND auart = 'TA'. * get vbpa we's CLEAR: it_vbpa. SELECT * FROM vbpa INTO CORRESPONDING FIELDS OF TABLE it_vbpa FOR ALL ENTRIES IN it_vbak WHERE vbeln = it_vbak-vbeln AND posnr = '000000' AND parvw = 'WE'. ENDFORM. " SELECT_RECORDS *&---------------------------------------------------------------------* *& Form PROCESS_ITAB *&---------------------------------------------------------------------* * attempt post goods issue for all entries. *----------------------------------------------------------------------* FORM process_itab. LOOP AT it_vbak ASSIGNING <it_vbak_line>. * look at records--populate it_zpartner READ TABLE it_vbpa ASSIGNING <it_vbpa_line> WITH TABLE KEY vbeln = <it_vbak_line>-vbeln. IF sy-subrc = 0. CLEAR: wa_zpartner. wa_zpartner-mandt = sy-mandt. 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. APPEND wa_zpartner TO it_zpartner. ENDIF. * ENDLOOP. SORT it_zpartner BY mandt vkorg vtweg spart kunag kunwe.. DELETE ADJACENT DUPLICATES FROM it_zpartner. * do a mass table update. INSERT zpartner FROM TABLE it_zpartner. IF sy-subrc = 0. MESSAGE s398(00) WITH 'Inserted records: ' sy-dbcnt. ENDIF. ENDFORM. " PROCESS_ITAB
This was first published in August 2003

Dig deeper on SAP ABAP

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close