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: 

Reg : field symbols

Former Member
0 Kudos
128

Hi,

Will anybody please tell me how to use field symbols?

I just want to know what is the purpose of using the field symbols?

what are field symbols?

Why , when and where they are used exactly?

Thank you,

Sowmya.

10 REPLIES 10

Former Member
0 Kudos
101

Take a look here ...

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

Example using the obsolete STRUCTURE addition:

DATA: wa(10) VALUE '0123456789'.

DATA: BEGIN OF line1,

col1(3),

col2(2),

col3(5),

END OF line1.

DATA: BEGIN OF line2,

col1(2),

col2 LIKE sy-datum,

END OF line2.

FIELD-SYMBOLS: <f1> STRUCTURE line1 DEFAULT wa,

<f2> STRUCTURE line2 DEFAULT wa.

WRITE: / <f1>-col1, <f1>-col2, <f1>-col3,

/ <f2>-col1, <f2>-col2.

Example using the correct syntax (TYPE and CASTING):

DATA: wa(10) VALUE '0123456789'.

DATA: BEGIN OF line1,

col1(3),

col2(2),

col3(5),

END OF line1.

DATA: BEGIN OF line2,

COL1(2),

COL2 LIKE sy-datum,

END OF line2.

FIELD-SYMBOLS: <f1> LIKE line1.

ASSIGN wa TO <f1> CASTING.

FIELD-SYMBOLS: <f2> LIKE line2.

ASSIGN wa TO <f2> CASTING.

WRITE: / <f1>-col1, <F1>-col2, <F1>-col3,

/ <f2>-col1, <F2>-col2.

p291102
Active Contributor
0 Kudos
101

Hi,

FIELD-SYMBOLS

Basic form

FIELD-SYMBOLS <fs>.

Additions

1. ... STRUCTURE s DEFAULT wa

2. ... TYPE t

3. ... TYPE LINE OF t

4. ... LIKE s

5. ... LIKE LINE OF s

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>.

TABLES SFLIGHT.

...

ASSIGN SFLIGHT-PLANETYPE TO <PT>.

WRITE <PT>.

Addition 1

... STRUCTURE s DEFAULT wa

Effect

Assigns any (internal) field string or structure to the field symbol from the ABAP/4 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.

Addition 2

... TYPE t

Addition 3

... TYPE LINE OF t

Addition 4

... LIKE s

Addition 5

... LIKE LINE OF s

Effect

You can use additions 2 to 5 to type field symbols in the same way as FORM parameters (see also Type assignment of subroutine parameters). ASSIGN performs the same type checks as with USING parameters of FORM s.

Related ASSIGN , DATA

Thanks,

Shankar

Former Member
0 Kudos
101

Hi ,

Field symbols are like pointers to an object .

assume you have an internal table where you have a transfer and read the fieldnames and transfer values .

The FIELD-SYMBOLS statement declares a field symbol <fs>. The name conventions apply to the name fs. The angle brackets of the field symbols indicate the difference to data objects and are obligatory. You can declare field symbols in any procedure and in the global declaration section of an ABAP program, but not in the declaration section of a class or an interface. You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.

After its declaration, a field symbol is initial - that is, it does not reference a memory area. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand. Otherwise an exception will be triggered.

Please reward if useful.

0 Kudos
101

Hi,

without using the field symbols itself , I can transfer the values from the internal table.

Then why should I use the field symbols?

Pls clarify me.

Thanks,

Sowmya.

raviprakash
Product and Topic Expert
Product and Topic Expert
0 Kudos
101

Hi Sowmya,

Without using the field symbols itself , you can transfer the values from the internal table but then the plus point of using a Field Symbol is that it directly writes the value to the memory area, rather than transfering it to a variable and then to the memory.

Also its very fast and the number of statements written is also less :). When it comes to internal tables, please use mostly Field Symbols if the number entries in the table is HUGE, something like thousands and millions. But when is 5-10 then its not advicable to use field symbols. In that case use variables.

Thanks and regards,

Ravi.

Former Member
0 Kudos
101

hi,

plz go to this link

http://help.sap.com/search/highlightContent.jsp

hope this helps

regards

Former Member
0 Kudos
101

Hi Sowmaya,

field-symbol are just like pointers , and can be used when at run-time

you find , what to do .e.g.

at run time you got the table name , so you can use a field symbol so that you can assign it and also you have to create a work area of that table , i found field -symbol to great use in that case(which i used once).

*******data declartion****

DATA: dref TYPE REF to data.

FIELD-SYMBOLS: <fs_tname>, "type any.

<FS>.

******************************

i got the table value (from a funtion module) in field WA-ENTITYTAB

********code to assign*********

ASSIGN WA-ENTITYTAB TO <FS>.

CREATE DATA dref TYPE (<FS>).

assign dref->* to <fs_tname> .

SELECT * FROM (<FS>) INTO <fs_tname>.

WRITE 😕 <fs_tname>.

ENDSELECT.

****************************

regards

Deepak.

regards

Deepak.

0 Kudos
101

hi

sorry some mistake , i got the name of table not value

i got the table name (from a funtion module) in field WA-ENTITYTAB

ragds

Deepak

Former Member
0 Kudos
101

Hi,

FIELD-SYMBOLS

Field-symbols will occupy memory only at the run-time. Even u can define the type of a field-symbol at run-time also when u declare them using TYPE ANY addition. The different usage of Field-symbols can be get from various examples on ABAPDOCU tcode.

Basic form

FIELD-SYMBOLS <fs>.

Additions

1. ... STRUCTURE s DEFAULT wa

2. ... TYPE t

3. ... TYPE LINE OF t

4. ... LIKE s

5. ... LIKE LINE OF s

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>.

TABLES SFLIGHT.

...

ASSIGN SFLIGHT-PLANETYPE TO <PT>.

WRITE <PT>.

Addition 1

... STRUCTURE s DEFAULT wa

Effect

Assigns any (internal) field string or structure to the field symbol from the ABAP/4 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.

Addition 2

... TYPE t

Addition 3

... TYPE LINE OF t

Addition 4

... LIKE s

Addition 5

... LIKE LINE OF s

Effect

You can use additions 2 to 5 to type field symbols in the same way as FORM parameters (see also Type assignment of subroutine parameters). ASSIGN performs the same type checks as with USING parameters of FORM s.

Related ASSIGN , DATA

Regards,

U. Uma