Application Development and Automation 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: 
Read only

general

Former Member
0 Likes
910

what are field symbols ?may u plz explain with simple example.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
880

Hi Naga Mrudula,

These r like pointer in C language

data a type i value 10.

field-symbol <f>.

assign a to <f>.

<f> = 20.

write a.

(no u will get the result 20 we r modifing 'a' using the field symbol <f>)

field-symbols are place holders for existing fields. It doesn't physically reserve any space for the fields, but points to the field.

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.

Simple program.

data : letter(10) .

field-symbols : <fs> type any.

assign letter to <fs> type 'X'.

write <fs>.

Simple program.

TYPES: BEGIN OF NAME,

NEXTNAME(10),

FIRSTNAME(10),

LASTNAME(10),

END OF NAME.

FIELD-SYMBOLS <F> TYPE NAME.

DATA: LINE(30).

LINE = 'JOHN SMITH SHRI'.

ASSIGN LINE TO <F> CASTING.

WRITE: / 'Lastname:', <F>-LASTNAME,

'Firstname:', <F>-FIRSTNAME,

'Nextname :', <F>-NEXTNAME.

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

https://forums.sdn.sap.com/click.jspa?searchID=167714&messageID=2392744

http://help.sap.com/saphelp_46c/helpdata/en/34/8e72ce6df74873e10000009b38f9b8/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb38c8358411d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/75/b6b53af5f711d195220000e8353423/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

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.

For more details go thru this link.

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

If you want more examples on field symbols then go to transaction ABAPDOCU.

Hi,

A field symbol is a place holder for a field.A simple program to show the usage of field symbols.You can avoid using work areas:

Report Sample.

FIELD-SYMBOLS: <FS> TYPE SPFLI.

DATA: I_SPFLI TYPE TABLE OF SPFLI .

SELECT * FROM SPFLI INTO TABLE I_SPFLI.

LOOP AT I_SPFLI ASSIGNING <FS>.

WRITE: / <FS>-CARRID, <FS>-CONNID, <FS>-CITYFROM, <FS>-CITYTO.

ENDLOOP.

We have declared a field symbol of type SPFLI and thus we need not use a work area while looping through the internal table.

Refer:

http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/frameset.htm

Hope this resolves your query.

Reward all the helpful answers.

Regards

9 REPLIES 9
Read only

Former Member
0 Likes
880

field symbols are abap counter parts for pointers in other languages.

They point to the memory locations of the variables they are assigned to.

field-symbols <fs> type any.

data: v_var(1) value 'X'.

assign v_var1 to <fs>.

This statement will make the field symbol <fs> point to the memory location of the variable v_var1.

Regards,

Ravi

Read only

Former Member
Read only

Former Member
0 Likes
880

hi,

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.

chk here.

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

Rgds

reshma

Read only

Former Member
0 Likes
880

Hi Naga,

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.

Field symbols are similar to dereferenced pointers in C.

Consider the Simple Example for the Field Symbols.

DATA : A TYPE I,

B TYPE I,

c type i.

A = '100'.

B = '50'.

FIELD-SYMBOLS <F1>.

FIELD-SYMBOLS <F2>.

FIELD-SYMBOLS <F3>.

ASSIGN A TO <F1>.

WRITE : <F1>.

WRITE : A.

ASSIGN A TO <F2>.

WRITE : <F2>.

<F2> = <F1> + <F2>.

*

**C = <F1> + <F2>.

WRITE : <F1>.

WRITE : <F2>.

Thanks.

Reward Points If helpful.

Read only

0 Likes
880

thanks viji

Read only

0 Likes
880

Hi Naga,

Its Ok.

Reward points if helpful.

Read only

0 Likes
880

here u have given <f2> = <f1> + <f2>.

after execution of this code i am getting both f1 and f2 as 200.

what is the reason may u explain it clearly

Read only

Former Member
0 Likes
881

Hi Naga Mrudula,

These r like pointer in C language

data a type i value 10.

field-symbol <f>.

assign a to <f>.

<f> = 20.

write a.

(no u will get the result 20 we r modifing 'a' using the field symbol <f>)

field-symbols are place holders for existing fields. It doesn't physically reserve any space for the fields, but points to the field.

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.

Simple program.

data : letter(10) .

field-symbols : <fs> type any.

assign letter to <fs> type 'X'.

write <fs>.

Simple program.

TYPES: BEGIN OF NAME,

NEXTNAME(10),

FIRSTNAME(10),

LASTNAME(10),

END OF NAME.

FIELD-SYMBOLS <F> TYPE NAME.

DATA: LINE(30).

LINE = 'JOHN SMITH SHRI'.

ASSIGN LINE TO <F> CASTING.

WRITE: / 'Lastname:', <F>-LASTNAME,

'Firstname:', <F>-FIRSTNAME,

'Nextname :', <F>-NEXTNAME.

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

https://forums.sdn.sap.com/click.jspa?searchID=167714&messageID=2392744

http://help.sap.com/saphelp_46c/helpdata/en/34/8e72ce6df74873e10000009b38f9b8/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb38c8358411d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/75/b6b53af5f711d195220000e8353423/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

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.

For more details go thru this link.

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

If you want more examples on field symbols then go to transaction ABAPDOCU.

Hi,

A field symbol is a place holder for a field.A simple program to show the usage of field symbols.You can avoid using work areas:

Report Sample.

FIELD-SYMBOLS: <FS> TYPE SPFLI.

DATA: I_SPFLI TYPE TABLE OF SPFLI .

SELECT * FROM SPFLI INTO TABLE I_SPFLI.

LOOP AT I_SPFLI ASSIGNING <FS>.

WRITE: / <FS>-CARRID, <FS>-CONNID, <FS>-CITYFROM, <FS>-CITYTO.

ENDLOOP.

We have declared a field symbol of type SPFLI and thus we need not use a work area while looping through the internal table.

Refer:

http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/frameset.htm

Hope this resolves your query.

Reward all the helpful answers.

Regards