Use of field symbols in SAP ABAP programming, using field symbols in SAP ABAP
Use of field symbols in SAP ABAP programming, using field symbols in SAP ABAP
the declaration operator FIELD-SYMBOL declares a field symbol <fs> to which a memory area is assigned in the current operand position. The declared field symbol is visible statically in the program from FIELD-SYMBOL(<fs>) and is valid in the current context. The declaration is made when the program is compiled, regardless of whether the statement is actually executed.The syntax for declaring a field symbol.
FIELD-SYMBOLS: <FIELD_SYMBOL> TYPE MARA-MATNR. "here MARA-MATNR is a variable typeFIELD-SYMBOLS: <FIELD_SYMBOL> TYPE MARA. "here MARA is a structure
FIELD-SYMBOLS: <FIELD_SYMBOL> TYPE REF TO DATA . "here DATA is a reference type
ASSIGNING and ASSIGN are the keywords that are used to assign a value to the field symbol.
Example of using field symbol as a work area
In the below example we are going to use the field symbol as a work area.
REPORT ZSAPN_FIELDSYMBOLS.
DATA: IT_MARA TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.
FIELD-SYMBOLS: <FS_MARA> TYPE MARA.
SELECT * FROM MARA
INTO TABLE IT_MARA UP TO 40 ROWS.
LOOP AT IT_MARA ASSIGNING <FS_MARA>.
IF <FS_MARA> IS ASSIGNED.
WRITE :/ <FS_MARA>-MATNR, <FS_MARA>-MTART, <FS_MARA>-MEINS.
ENDIF.
ENDLOOP.
Check whether the field symbol is assigned or not before processing the field symbol, it is very important to check the field symbol, if it is not assigned it will get a run-time error, use the below syntax to check the field symbol assignment.
IF <FS_MARA> IS ASSIGNED.
**process field symbol
ENDIF.
Increase performance using field symbols in SAP ABAP
I believe there are always performance differences between reference variables(work area) and memory pointing(field symbols), here I want to add some proof for that.
Below you will find two programs one with a work area and another one with field symbols, execute them and see the time difference at the end of the program( will display at the bottom of output), you will find differences.
program1
REPORT ZSAPN_FIELDSYMBOLS1.
DATA: IT_MARA TYPE TABLE OF MARA. "internal table
FIELD-SYMBOLS: <FS_MARA> TYPE MARA. "field symbols
DATA: LV_TIME_START TYPE TIMESTAMPL. "time at the start of the loop
DATA: LV_TIME_END TYPE TIMESTAMPL. "time at the end of the loop.
ABAP Syntax
ABAP Statements
ABAP Program Types
SAP ABAP Workbench Tools
SAP ABAP Tutorials
SAP ABAP Tutorial
SAP ERP Technical and Functional Modules List
SAP Storage Location Table
SAP Transaction codes
SAP Consultant Salary
Data types in SAP ABAP
ABAP Statements
ABAP Program Types
SAP ABAP Workbench Tools
SAP ABAP Tutorials
SAP ABAP Tutorial
SAP ERP Technical and Functional Modules List
SAP Storage Location Table
SAP Transaction codes
SAP Consultant Salary
Data types in SAP ABAP
ABAP Control Statements
ABAP Function Modules
ABAP Select Statements
ABAP Field Symbols
Comments
Post a Comment