Current Poll
ABAP Field Symbols are very powerful. Usage of Field-Symbols would provide performance gain, but for that you must use it correctly otherwise you may run into issues.
Field-symbols can provide great performance over using workarea as I have mentioned in my earlier article – Use of Field-symbols vs Work area. I have mentioned many articles using Field-Symbols but wanted to note down the basics as part of this code snippet.
Page Contents
Declare a Field Symbols
TYPES: tt_mara TYPE STANDARD TABLE OF mara. DATA: t_mara TYPE tt_mara. * FIELD-SYMBOLS: <lfs_mara> LIKE LINE OF t_mara. " << * " Field symbol without type FIELD-SYMBOLS: <lfs_any_tab> TYPE ANY TABLE, <lfs_any> TYPE ANY.
APPEND and INSERT using Field Symbols
* Append line APPEND INITIAL LINE TO t_mara ASSIGNING <lfs_mara>. <lfs_mara>-matnr = '123456'. * * insert table INSERT INITIAL LINE INTO t_mara ASSIGNING <lfs_mara> INDEX 2. <lfs_mara>-matnr = 'ABCDEF'.
Access ITAB rows using Field Symbols
* Read table READ TABLE t_mara ASSIGNING <lfs_mara> WITH KEY matnr = '123456'. IF sy-subrc EQ 0. WRITE: <lfs_mara>-matnr. ENDIF. * * Access via Loop LOOP AT t_mara ASSIGNING <lfs_mara>. WRITE: <lfs_mara>-matnr. ENDLOOP.
Modify an entry using Field-Symbols:
* READ and MODIFY READ TABLE t_mara ASSIGNING <lfs_mara> WITH KEY matnr = '123456'. IF sy-subrc EQ 0. <lfs_mara>-ersda = sy-datum. ENDIF. * * LOOP and MODIFY LOOP AT t_mara ASSIGNING <lfs_mara>. <lfs_mara>-ersda = sy-datum + 1 ENDLOOP.
CHECK field Symbols using IS ASSIGNED
Check if Field Symbol is assigned to a valid reference
* Check if Field-Symbol is assigned IF <lfs_mara> IS ASSIGNED. WRITE: 'Assigned'. ELSE. WRITE: 'Unassigned'. ENDIF.
Remove the Reference of the Field Symbols
"remvoe the reference UNASSIGN <lfs_mara>.
Do you have a Code Snippet which you want to share, Submit Code Snippet here
Your blog is very nice!
=]
Gud one to give a start to usage of field symbols…
An awesome knowledge on field-symbols. Thank you for giving a very good clear understanding.
Hello Padro, Avinash & Varun,
Glad you guys like the Code snippet on Field Symbols.
Thanks,
Naimesh Patel