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: 

regarding field symbols

Former Member
0 Kudos

what are field symbols in abap ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Field-Symbols are place holders for existing fields.

A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.

Field-Symbols are like Pointers in Programming language ‘ C ‘.

Syntax check is not effective.

Syntax :

Data : v1(4) value ‘abcd’.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.

DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.

FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.

DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.

READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.

READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.

IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.

LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.

The output is:

1 1

2 100

4 16

Check the below Links :

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

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

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

http://help.sap.com/saphelp_nw04/helpdata/en/16/0dce0a0cf711d3b9360000e8353423/content.htm

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

Thanks.

6 REPLIES 6

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi

<b>Field Symbols</b>

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.

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

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

<b>Rewar dif usefull</b>

Former Member
0 Kudos

How to declare fields symbols and attaching structure to fields symbols ?

0 Kudos

Declaring Field Symbols

To declare a field symbol, use the statement

FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].

For field symbols, the angle brackets are part of the syntax. They identify field symbols in the program code.

If you do not specify any additions, 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.

Note: it is possible to assign reference variables and structured data objects to untyped field symbols. However, 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 (for example, in a MOVE statement). Specific statements such as CREATE OBJECT <FS> or LOOP AT <FS> are not possible.

Attaching a structure to a field symbol

The STRUCTURE addition forces a structured view of the data objects that you assign to a field symbol.

FIELD-SYMBOLS <FS> STRUCTURE <s> DEFAULT <f>.

The structure <s> is either a structured local data object in the program, or a flat structure from the ABAP Dictionary. <f> is a data object that must be assigned to the field symbol as a starting field. However, this assignment can be changed later using the ASSIGN statement.

When you assign a data object to the field symbol, the system only checks that it is at least as long as the structure. You can address the individual components of the field symbol. It has the same technical attributes as the structure <s>.

If <s> contains components with type I or F, you should remember the possible effects of alignment. When you assign a data object to a field symbol with a structure, the data object must have the same alignment, otherwise a runtime error may result. In such cases, you are advised to assign such data objects only to structured field symbols, which retain the same structure as the field symbol at least over the length of the structure.

The STRUCTURE is obsolete; you should no longer use it. Field symbols defined using the STRUCTURE addition are a mixture of typed field symbols and a utility for casting to either local or ABAP Dictionary data types. If you want to define the type of a field symbol, include the TYPE addition in a FIELD-SYMBOLS statement. If you want to use casting, include the CASTING addition in an ASSIGN statement.

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.

In both cases, the list appears as follows:

012 34 56789

01 2345/67/89

This example declares two field symbols to which different structures are attached. The string WA is then assigned to each of them. The output shows that the field symbols assign the strings component by component according to the type of the components.

0 Kudos

Hi

<b>FIELD-SYMBOLS</b>

<b>Basic form</b>

FIELD-SYMBOLS <fs>.

<b>Additions</b>

1. ... STRUCTURE s DEFAULT wa

2. ... TYPE t

3. ... TYPE LINE OF t

4. ... LIKE s

5. ... LIKE LINE OF s

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.

<b>You can only use one of the additions.</b>

<b>Example</b>

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

FIELD-SYMBOLS <PT>.

TABLES SFLIGHT.

...

ASSIGN SFLIGHT-PLANETYPE TO <PT>.

WRITE <PT>.

<b>Addition 1</b>

... STRUCTURE s DEFAULT wa

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.

<b>Example</b>

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.

<b>Addition 2</b>

... TYPE t

Addition 3

... TYPE LINE OF t

Addition 4

... LIKE s

Addition 5

... LIKE LINE OF s

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

<b>Reward if usefull</b>

Former Member
0 Kudos

Hi,

Field-Symbols are place holders for existing fields.

A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.

Field-Symbols are like Pointers in Programming language ‘ C ‘.

Syntax check is not effective.

Syntax :

Data : v1(4) value ‘abcd’.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.

DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.

FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.

DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.

READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.

READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.

IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.

LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.

The output is:

1 1

2 100

4 16

Check the below Links :

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

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

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

http://help.sap.com/saphelp_nw04/helpdata/en/16/0dce0a0cf711d3b9360000e8353423/content.htm

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

Thanks.