Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Why do we use Feild Symbols

Former Member
0 Kudos

Hi All

Breifly explain me why do we use field symbols. and how to use them and where to use them.

Thanks! in advance

4 REPLIES 4

Former Member
0 Kudos

hi,

Field Symbol:

The field symbol <FS> can have data objects of any type assigned to it. When you assign a data object, the field symbol inherits its technical attributes. The data type of the assigned data object becomes the actual data type of the field symbol. The static field symbol is only a pointer to the field in memory, and does not have the complex type attributes of a reference or structured field until runtime. You can only use the field symbol to address the whole field.

TYPES: BEGIN OF LINE,

COL1,

COL2,

END OF LINE.

DATA: WA TYPE LINE,

ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1,

KEY(4) VALUE 'COL1'.

FIELD-SYMBOLS <FS> TYPE ANY TABLE.

ASSIGN ITAB TO <FS>.

READ TABLE <FS> WITH TABLE KEY (KEY) = 'X' INTO WA.

regards,

theja

Former Member
0 Kudos

Hi, this may help you.

*Field Symbols *

Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects.

All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.

You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.

Field symbols provide greater flexibility when you address data objects:

If you want to process sections of fields, you can specify the offset and length of the field dynamically.

You can assign one field symbol to another, which allows you to address parts of fields.

Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.

You can also force a field symbol to take different technical attributes from those of the field assigned to it.

The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.

While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.

For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.

check the below links u will get the answers for your questions

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm

http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html

Syntax Diagram

FIELD-SYMBOLS

Basic form

FIELD-SYMBOLS <fs>.

Extras:

1. ... TYPE type

2. ... TYPE REF TO cif

3. ... TYPE REF TO DATA

4. ... TYPE LINE OF type

5. ... LIKE s

6. ... LIKE LINE OF s

7. ... TYPE tabkind

8. ... STRUCTURE s DEFAULT wa

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.

Effect

This statement declares a symbolic field called <fs>. At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.

You can only use one of the additions.

Example

Output aircraft type from the table SFLIGHT using a field symbol:

FIELD-SYMBOLS <PT> TYPE ANY.

DATA SFLIGHT_WA TYPE SFLIGHT.

...

ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.

WRITE <PT>.

Addition 1

... TYPE type

Addition 2

... TYPE REF TO cif

Addition 3

... TYPE REF TO DATA

Addition 4

... TYPE LINE OF type

Addition 5

... LIKE s

Addition 6

... LIKE LINE OF s

Addition 7

... TYPE tabkind

Effect

You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.

This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.

Effect

Assigns any (internal) field string or structure to the field symbol from the ABAP Dictionary (s). All fields of the structure can be addressed by name: <fs>-fieldname. The structured field symbol points initially to the work area wa specified after DEFAULT.

The work area wa must be at least as long as the structure s. If s contains fields of the type I or F, wa should have the structure s or at least begin in that way, since otherwise alignment problems may occur.

Example

Address components of the flight bookings table SBOOK using a field symbol:

DATA SBOOK_WA LIKE SBOOK.

FIELD-SYMBOLS <SB> STRUCTURE SBOOK

DEFAULT SBOOK_WA.

...

WRITE: <SB>-BOOKID, <SB>-FLDATE.

Related

ASSIGN, DATA

Additional help

Declaring Field Symbols

Reward If Helpful.

Regards Madhu.

Former Member
0 Kudos

Hi,

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.

Code

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

reward if helpful,

kushagra

Former Member
0 Kudos

hi,

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.

Hope this is helpful, Do reward.