SlideShare a Scribd company logo
Dynamic Programming with Field Symbols
May 1, 2014 · ABAP Leave a comment
Tagged: dynamic programming, field symbols, performance, snippet
Introduction
Field Symbols allows you to access content of variable to which its point to. This pointing to a variable is done
using ASSIGN statement. Field Symbol does not store any value it simply point to the memory where variable
value is store. Any operation to change value direct affects variable. Field symbols are different in a way that one
field symbol can be assigned to different variable throughout the program life time and statement executed using
field symbol will affect different variable depending on where it point to.
You can declare field symbols using
FIELD-SYMBOLS : <fs_name> TYPE ANY.
FIELD-SYMBOLS : <fs_name> TYPE mara.
FIELD-SYMBOLS : <fs_name> TYPE i .
You can use ANY to define a generic field symbol which will then inherit properties of variable its assigned to or
you can use a specific type to restrict assignment to compatible variable. This means that if you have field symbol
defined as I (integer) and you try to assign it to any other kind of variable then you will get ‘type-incompatible’
syntaxerror.
ASSIGN
Assignment of field symbol is done using ASSIGN statement. Below is an example where I have declared a
generic field symbol and assigned it different component of MARA work area.
FIELD-SYMBOLS : <fs_field> TYPE ANY .
DATA : ls_mara TYPE mara .
SELECT SINGLE *
INTO ls_mara
FROM mara
WHERE matnr = 'A1' .
ASSIGN ls_mara-matnr TO <fs_field> .
WRITE : / <fs_field> .
ASSIGN ls_mara-matkl TO <fs_field> .
WRITE : / <fs_field> .
Caution
Accessing field symbol before its assigned to a variable is something which will trigger runtime error ‘Field
symbol has not yet been assigned’.An unassigned field symbol cannot be checked when you activate the program
and because of this reason programs using field symbol, if checks are not done properly, often produce runtime
error.
Whist using field symbols you have to take extra care to check if field symbol points to a variable before you start
any operation on it. If you are accessing field symbol ASSIGN statement you must check of assignment has
executed successfully.
ASSIGN ls_mara-matnr TO <fs_field> .
IF sy-subrc = 0 .
WRITE : / <fs_field> .
ENDIF.
or
ASSIGN ls_mara-matnr TO <fs_field> .
IF <fs_field> is ASSIGNED .
WRITE : / <fs_field> .
ENDIF.
Performance Gain
Field symbols can also be used to access internal table content and it particularly have performance advantage as
content of table is not moved to workarea instead field symbol is simply pointed to right record.
DATA : i_mara TYPE TABLE OF mara .
FIELD-SYMBOLS : <fs_mara> TYPE mara .
READ TABLE i_mara ASSIGNING <fs_mara> WITH KEY matnr = 'A1' .
IF sy-subrc = 0 .
WRITE : <fs_mara>-matnr .
ENDIF.
DATA : i_mara TYPE TABLE OF mara .
FIELD-SYMBOLS : <fs_mara> TYPE mara .
LOOP AT i_mara ASSIGNING <fs_field> .
WRITE : / <fs_field>-matnr .
ENDLOOP..
Note that if you change content of field symbol after READ internal table statement or within LOOP you are
modifying the content of field symbol as there is no work area.
Dynamic Stuff
ASSIGN COMPONENT statement has two variations which allows you to access field of workarea at runtime.
In first variantion you can specify field name in terms of number. It’s like saying assign first (or second,third or
so on) component of workarea to field symbol. In below code program simply access all component of work area
within WHILE loop and exit when assignment fail, which it will once it has accessed all component.
DATA : ls_mara TYPE mara .
FIELD-SYMBOLS : <fs_field> TYPE ANY.
SELECT SINGLE *
INTO ls_mara
FROM mara
WHERE matnr = 'A1' .
WHILE sy-subrc = 0.
ASSIGN COMPONENT sy-index OF STRUCTURE ls_mara TO <fs_field>.
IF sy-subrc = 0 .
WRITE : / <fs_field> .
ENDIF.
ENDWHILE.
In second variation, which I find more useful, you can specify component name instead of number to access that
field of work area.
DATA : ls_mara TYPE mara .
FIELD-SYMBOLS : <fs_field> TYPE ANY.
DATA : lv_compnent_name TYPE char10 VALUE 'MATNR' .
SELECT SINGLE *
INTO ls_mara
FROM mara
WHERE matnr = 'A1' .
ASSIGN COMPONENT lv_compnent_name OF STRUCTURE ls_mara TO <fs_field>.
IF sy-subrc = 0 .
WRITE : / <fs_field> .
ENDIF.

More Related Content

DOCX
Field symbols
skumar_sap
 
DOCX
Fieldsymbols
Nrushing Nayak
 
PPTX
SAS Macro
Sonal Shrivastav
 
PPTX
Validation and input formatting
Neha Kaurav
 
PPT
SAS Macros part 1
venkatam
 
DOC
Sap abap interview questions
kssr99
 
PPTX
Excel
Manoj Jhawar
 
PPTX
Using basic select statement in oracle database
Md. Mahbubul Alam
 
Field symbols
skumar_sap
 
Fieldsymbols
Nrushing Nayak
 
SAS Macro
Sonal Shrivastav
 
Validation and input formatting
Neha Kaurav
 
SAS Macros part 1
venkatam
 
Sap abap interview questions
kssr99
 
Using basic select statement in oracle database
Md. Mahbubul Alam
 

What's hot (20)

PPTX
Where conditions and Operators in SQL
Raajendra M
 
PPTX
Ma3696 Lecture 1
Brunel University
 
DOC
Complete list of all sap abap keywords
Prakash Thirumoorthy
 
PPT
SAS Macros part 3
venkatam
 
DOCX
MSc COMPUTER APPLICATION
MugdhaSharma11
 
PPT
Sql server select queries ppt 18
Vibrant Technologies & Computers
 
PPT
oracle-reports6i
CHANDRASEKHAR REDROUTHU
 
PPT
SAS Macros part 2
venkatam
 
PPT
Retrieving data using the sql select statement
Syed Zaid Irshad
 
PPT
SQL select statement and functions
Vikas Gupta
 
DOCX
Sap abap modularization interview questions
Pradipta Mohanty
 
PPTX
Formula in MS Excel
Muhammad Yasir Bhutta
 
PPTX
SAP Modularization techniques
Jugul Crasta
 
PPTX
03 Excel formulas and functions
Buffalo Seminary
 
PPTX
1. dml select statement reterive data
Amrit Kaur
 
PPTX
Microsoft excel 2010 useful formula & functions
NR Computer Learning Center
 
PPT
Abap course chapter 7 abap objects and bsp
Milind Patil
 
PDF
Casa lab manual
BHARATNIKKAM
 
Where conditions and Operators in SQL
Raajendra M
 
Ma3696 Lecture 1
Brunel University
 
Complete list of all sap abap keywords
Prakash Thirumoorthy
 
SAS Macros part 3
venkatam
 
MSc COMPUTER APPLICATION
MugdhaSharma11
 
Sql server select queries ppt 18
Vibrant Technologies & Computers
 
oracle-reports6i
CHANDRASEKHAR REDROUTHU
 
SAS Macros part 2
venkatam
 
Retrieving data using the sql select statement
Syed Zaid Irshad
 
SQL select statement and functions
Vikas Gupta
 
Sap abap modularization interview questions
Pradipta Mohanty
 
Formula in MS Excel
Muhammad Yasir Bhutta
 
SAP Modularization techniques
Jugul Crasta
 
03 Excel formulas and functions
Buffalo Seminary
 
1. dml select statement reterive data
Amrit Kaur
 
Microsoft excel 2010 useful formula & functions
NR Computer Learning Center
 
Abap course chapter 7 abap objects and bsp
Milind Patil
 
Casa lab manual
BHARATNIKKAM
 
Ad

Viewers also liked (8)

PPTX
School of Scholars,Amravati
sosamravati
 
DOCX
How head up displays in cars will help in reducing car accidents
Infernal Innovations
 
PDF
Top 6 apps for car gadget lovers
Infernal Innovations
 
PPT
Master management and textile engineering placement facts
Paola Fini
 
PDF
Infographic why to choose infernal innovations magnetic phone mount
Infernal Innovations
 
PDF
OPM Mock Decision
opmeag
 
PDF
Script details
Ashish Mohapatra
 
PDF
Best dashboard car phone holder
Infernal Innovations
 
School of Scholars,Amravati
sosamravati
 
How head up displays in cars will help in reducing car accidents
Infernal Innovations
 
Top 6 apps for car gadget lovers
Infernal Innovations
 
Master management and textile engineering placement facts
Paola Fini
 
Infographic why to choose infernal innovations magnetic phone mount
Infernal Innovations
 
OPM Mock Decision
opmeag
 
Script details
Ashish Mohapatra
 
Best dashboard car phone holder
Infernal Innovations
 
Ad

Similar to Fieldsymbols (19)

PDF
Applicative Functor - Part 3
Philip Schwarz
 
PDF
Getting started with Microsoft Excel Macros
Nick Weisenberger
 
PPT
Cursors.ppt
Karthick Panneerselvam
 
PDF
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
PDF
Abap 7.40
Pradeep Rao Jadav D
 
PPTX
LISP: Macros in lisp
LISP Content
 
PPTX
LISP: Macros in lisp
DataminingTools Inc
 
PDF
Applicative Functor - Part 2
Philip Schwarz
 
PPTX
Education Presentation ABAP Week-14.pptx
praveengkumarer1
 
PDF
MA3696 Lecture 9
Brunel University
 
PPTX
INTRODUCTION TO C PROGRAMMING - PART 2
JEENA SARA VIJU
 
PDF
Handout # 4 functions + scopes
NUST Stuff
 
PDF
Sap script system_symbol
moderngladiator
 
DOCX
Open sap ui51_week_2_unit_3_acdt_exercises
vikram sukumar
 
PPT
SAS Macros
guest2160992
 
PPTX
Inline functions & macros
Anand Kumar
 
PPT
Python-review1 for begineers to code.ppt
freyjadexon608
 
PDF
Python-review1.pdf
paijitk
 
PPTX
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 
Applicative Functor - Part 3
Philip Schwarz
 
Getting started with Microsoft Excel Macros
Nick Weisenberger
 
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
LISP: Macros in lisp
LISP Content
 
LISP: Macros in lisp
DataminingTools Inc
 
Applicative Functor - Part 2
Philip Schwarz
 
Education Presentation ABAP Week-14.pptx
praveengkumarer1
 
MA3696 Lecture 9
Brunel University
 
INTRODUCTION TO C PROGRAMMING - PART 2
JEENA SARA VIJU
 
Handout # 4 functions + scopes
NUST Stuff
 
Sap script system_symbol
moderngladiator
 
Open sap ui51_week_2_unit_3_acdt_exercises
vikram sukumar
 
SAS Macros
guest2160992
 
Inline functions & macros
Anand Kumar
 
Python-review1 for begineers to code.ppt
freyjadexon608
 
Python-review1.pdf
paijitk
 
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 

Recently uploaded (20)

PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Exploring AI Agents in Process Industries
amoreira6
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Activate_Methodology_Summary presentatio
annapureddyn
 

Fieldsymbols

  • 1. Dynamic Programming with Field Symbols May 1, 2014 · ABAP Leave a comment Tagged: dynamic programming, field symbols, performance, snippet Introduction Field Symbols allows you to access content of variable to which its point to. This pointing to a variable is done using ASSIGN statement. Field Symbol does not store any value it simply point to the memory where variable value is store. Any operation to change value direct affects variable. Field symbols are different in a way that one field symbol can be assigned to different variable throughout the program life time and statement executed using field symbol will affect different variable depending on where it point to. You can declare field symbols using FIELD-SYMBOLS : <fs_name> TYPE ANY. FIELD-SYMBOLS : <fs_name> TYPE mara. FIELD-SYMBOLS : <fs_name> TYPE i . You can use ANY to define a generic field symbol which will then inherit properties of variable its assigned to or you can use a specific type to restrict assignment to compatible variable. This means that if you have field symbol defined as I (integer) and you try to assign it to any other kind of variable then you will get ‘type-incompatible’ syntaxerror. ASSIGN Assignment of field symbol is done using ASSIGN statement. Below is an example where I have declared a generic field symbol and assigned it different component of MARA work area. FIELD-SYMBOLS : <fs_field> TYPE ANY . DATA : ls_mara TYPE mara . SELECT SINGLE * INTO ls_mara FROM mara WHERE matnr = 'A1' . ASSIGN ls_mara-matnr TO <fs_field> . WRITE : / <fs_field> . ASSIGN ls_mara-matkl TO <fs_field> . WRITE : / <fs_field> . Caution Accessing field symbol before its assigned to a variable is something which will trigger runtime error ‘Field symbol has not yet been assigned’.An unassigned field symbol cannot be checked when you activate the program and because of this reason programs using field symbol, if checks are not done properly, often produce runtime error. Whist using field symbols you have to take extra care to check if field symbol points to a variable before you start any operation on it. If you are accessing field symbol ASSIGN statement you must check of assignment has executed successfully.
  • 2. ASSIGN ls_mara-matnr TO <fs_field> . IF sy-subrc = 0 . WRITE : / <fs_field> . ENDIF. or ASSIGN ls_mara-matnr TO <fs_field> . IF <fs_field> is ASSIGNED . WRITE : / <fs_field> . ENDIF. Performance Gain Field symbols can also be used to access internal table content and it particularly have performance advantage as content of table is not moved to workarea instead field symbol is simply pointed to right record. DATA : i_mara TYPE TABLE OF mara . FIELD-SYMBOLS : <fs_mara> TYPE mara . READ TABLE i_mara ASSIGNING <fs_mara> WITH KEY matnr = 'A1' . IF sy-subrc = 0 . WRITE : <fs_mara>-matnr . ENDIF. DATA : i_mara TYPE TABLE OF mara . FIELD-SYMBOLS : <fs_mara> TYPE mara . LOOP AT i_mara ASSIGNING <fs_field> . WRITE : / <fs_field>-matnr . ENDLOOP.. Note that if you change content of field symbol after READ internal table statement or within LOOP you are modifying the content of field symbol as there is no work area. Dynamic Stuff ASSIGN COMPONENT statement has two variations which allows you to access field of workarea at runtime. In first variantion you can specify field name in terms of number. It’s like saying assign first (or second,third or so on) component of workarea to field symbol. In below code program simply access all component of work area within WHILE loop and exit when assignment fail, which it will once it has accessed all component. DATA : ls_mara TYPE mara . FIELD-SYMBOLS : <fs_field> TYPE ANY. SELECT SINGLE * INTO ls_mara FROM mara WHERE matnr = 'A1' . WHILE sy-subrc = 0. ASSIGN COMPONENT sy-index OF STRUCTURE ls_mara TO <fs_field>. IF sy-subrc = 0 . WRITE : / <fs_field> . ENDIF. ENDWHILE.
  • 3. In second variation, which I find more useful, you can specify component name instead of number to access that field of work area. DATA : ls_mara TYPE mara . FIELD-SYMBOLS : <fs_field> TYPE ANY. DATA : lv_compnent_name TYPE char10 VALUE 'MATNR' . SELECT SINGLE * INTO ls_mara FROM mara WHERE matnr = 'A1' . ASSIGN COMPONENT lv_compnent_name OF STRUCTURE ls_mara TO <fs_field>. IF sy-subrc = 0 . WRITE : / <fs_field> . ENDIF.