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: 

field symbols

Former Member
0 Kudos

What is this field symbols ? where exactly we can use? Can u send material for this field symbols ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

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. (For more information, see Data References).

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.

For defining field symbols check the following link:

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

For Assigning Data Objects to Field Symbols :

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

Regards,

Bhaskar

4 REPLIES 4

Former Member
0 Kudos

Hi

Goto the transaction abapdocu. double click on keyword help and then search for field symbols. You will get to see the detail description with example code.

Cheers

Sudip

Former Member
0 Kudos

Hi Bhagavan,

Field symbols offer functionlity similar to pointers in other programming languages. It does not occupy memory for the data object, it points to the object that has been assigned to the field symbol. You use the assign command to relate to the data object. After the assign operation you can work with field symbol in the same way as with the object itself.

You define the field symbol as: field-symbols <fs>.

Consider this:

field-symbol <fs>.

data field value 'X'.

asssign field to <fs>.

The field symbol <fs> now inherits all the properties from the assigned field, and you can work with the field symbol in the same way as with the field itself.

Take a look at the examples given here for working with field symbols:

http://www.sapgenie.com/abap/code/chap2401.txt

http://www.sapgenie.com/abap/code/chap2402.txt

http://www.sapgenie.com/abap/code/chap2403.txt

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

Simple program.

data : letter(10) .

field-symbols : <fs> type any.

assign letter to <fs> type 'X'.

write <fs>.

Check This sample code,

DATA: wa(20) VALUE 'ABCDEFGHIJKLYJJYJJ'.

DATA: BEGIN OF line1,

COL1(1),

col2(1),

col3(1),

col4(1),

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, <F1>-COL4,

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

Reward if useful.

Thanks

Aneesh.

Former Member
0 Kudos

hi bhagavan,

Field symbols offer functionlity similar to pointers in other programming languages. It does not occupy memory for the data object, it points to the object that has been assigned to the field symbol. You use the assign command to relate to the data object. After the assign operation you can work with field symbol in the same way as with the object itself.

You define the field symbol as: field-symbols <fs>.

Consider this:

field-symbol <fs>.

data field value 'X'.

asssign field to <fs>.

The field symbol <fs> now inherits all the properties from the assigned field, and you can work with the field symbol in the same way as with the field itself.

Take a look at the examples given here for working with field symbols:

http://www.sapgenie.com/abap/code/chap2401.txt

http://www.sapgenie.com/abap/code/chap2402.txt

http://www.sapgenie.com/abap/code/chap2403.txt

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

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.

regards,

seshu.

Former Member
0 Kudos

Hi,

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. (For more information, see Data References).

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.

For defining field symbols check the following link:

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

For Assigning Data Objects to Field Symbols :

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

Regards,

Bhaskar