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

What's hot

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

What's hot (20)

Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQL
 
Ma3696 Lecture 1
Ma3696 Lecture 1Ma3696 Lecture 1
Ma3696 Lecture 1
 
Complete list of all sap abap keywords
Complete list of all sap abap keywordsComplete list of all sap abap keywords
Complete list of all sap abap keywords
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
 
Ch13
Ch13Ch13
Ch13
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
 
Sql server select queries ppt 18
Sql server select queries ppt 18Sql server select queries ppt 18
Sql server select queries ppt 18
 
oracle-reports6i
oracle-reports6ioracle-reports6i
oracle-reports6i
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
 
Chapter.05
Chapter.05Chapter.05
Chapter.05
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Sap abap modularization interview questions
Sap abap modularization interview questionsSap abap modularization interview questions
Sap abap modularization interview questions
 
Formula in MS Excel
Formula in MS ExcelFormula in MS Excel
Formula in MS Excel
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniques
 
03 Excel formulas and functions
03 Excel formulas and functions03 Excel formulas and functions
03 Excel formulas and functions
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Microsoft excel 2010 useful formula & functions
Microsoft excel 2010   useful formula & functionsMicrosoft excel 2010   useful formula & functions
Microsoft excel 2010 useful formula & functions
 
Abap course chapter 7 abap objects and bsp
Abap course   chapter 7 abap objects and bspAbap course   chapter 7 abap objects and bsp
Abap course chapter 7 abap objects and bsp
 
Casa lab manual
Casa lab manualCasa lab manual
Casa lab manual
 

Viewers also liked

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

Viewers also liked (8)

School of Scholars,Amravati
School of Scholars,AmravatiSchool of Scholars,Amravati
School of Scholars,Amravati
 
How head up displays in cars will help in reducing car accidents
How head up displays in cars will help in reducing car accidentsHow head up displays in cars will help in reducing car accidents
How head up displays in cars will help in reducing car accidents
 
Top 6 apps for car gadget lovers
Top 6 apps for car gadget loversTop 6 apps for car gadget lovers
Top 6 apps for car gadget lovers
 
Master management and textile engineering placement facts
Master management and textile engineering    placement factsMaster management and textile engineering    placement facts
Master management and textile engineering placement facts
 
Infographic why to choose infernal innovations magnetic phone mount
Infographic why to choose infernal innovations magnetic phone mountInfographic why to choose infernal innovations magnetic phone mount
Infographic why to choose infernal innovations magnetic phone mount
 
OPM Mock Decision
OPM Mock DecisionOPM Mock Decision
OPM Mock Decision
 
Script details
Script detailsScript details
Script details
 
Best dashboard car phone holder
Best dashboard car phone holderBest dashboard car phone holder
Best dashboard car phone holder
 

Similar to Fieldsymbols

Applicative Functor - Part 3
Applicative Functor - Part 3Applicative Functor - Part 3
Applicative Functor - Part 3
Philip Schwarz
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
Nick Weisenberger
 
Cursors.ppt
Cursors.pptCursors.ppt
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
Abap 7.40
Abap 7.40Abap 7.40
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
DataminingTools Inc
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
LISP Content
 
Applicative Functor - Part 2
Applicative Functor - Part 2Applicative Functor - Part 2
Applicative Functor - Part 2
Philip Schwarz
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
Brunel University
 
INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2
JEENA SARA VIJU
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
NUST Stuff
 
Sap script system_symbol
Sap script system_symbolSap script system_symbol
Sap script system_symbol
moderngladiator
 
Open sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercisesOpen sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercises
vikram sukumar
 
SAS Macros
SAS MacrosSAS Macros
SAS Macros
guest2160992
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
Anand Kumar
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
paijitk
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 

Similar to Fieldsymbols (17)

Applicative Functor - Part 3
Applicative Functor - Part 3Applicative Functor - Part 3
Applicative Functor - Part 3
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
 
Cursors.ppt
Cursors.pptCursors.ppt
Cursors.ppt
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
 
Abap 7.40
Abap 7.40Abap 7.40
Abap 7.40
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
 
Applicative Functor - Part 2
Applicative Functor - Part 2Applicative Functor - Part 2
Applicative Functor - Part 2
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
 
Sap script system_symbol
Sap script system_symbolSap script system_symbol
Sap script system_symbol
 
Open sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercisesOpen sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercises
 
SAS Macros
SAS MacrosSAS Macros
SAS Macros
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
 

Recently uploaded

一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 

Recently uploaded (20)

一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 

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.