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 r field symbols ..wht's it's use ..it's importance in smart forms?

4 REPLIES 4

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

Reward if helpful.

Regards,

Haini.S

Former Member
0 Kudos

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.

Advantages:

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

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

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

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

Check these links on Field Symbols.

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

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

A sample program on Field Symbols:

FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE i.

DATA: text(20) TYPE c VALUE 'Hello, how are you?',

num TYPE i VALUE 5,

BEGIN OF line1,

col1 TYPE f VALUE '1.1e+10',

col2 TYPE i VALUE '1234',

END OF line1,

line2 LIKE line1.

ASSIGN text TO <f1>.

ASSIGN num TO <f2>.

DESCRIBE FIELD <f1> LENGTH <f2>.

WRITE: / <f1>, 'has length', num.

ASSIGN line1 TO <f1>.

ASSIGN line2-col2 TO <f2>.

MOVE <f1> TO line2.

ASSIGN 'LINE2-COL2 =' TO <f1>.

WRITE: / <f1>, <f2>.

Eg:2

FIELD-SYMBOLS : Field symbols are symbolic names to which a memory area can be assigned during program runtime. A field symbol can be used instead of data objects at operand positions of statements.

Syntax

FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.

Extras:

1. ... typing

2. ... STRUCTURE struc DEFAULT dobj

Effect

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.

Addition 1

... typing

Effect

You can use the addition typing to type the field symbol. The syntax of typing is described under Syntax of Typing. The typing specifies which memory areas can be assigned to the field symbol (see Checking the Typing) and in which operand positions it can be used.

Note

You can omit the addition typing outside of methods. In this case, the field symbol has the complete generic type any and is implicitly assigned the predefined constant space during the declaration.

Addition 2

... STRUCTURE struc DEFAULT dobj

Effect

If you specify the addition STRUCTURE instead of typing for a field symbol, and struc is a local program structure (a data object, not a data type) or a flat structure from the ABAP Dictionary, this structure is cast for the field symbol <fs>. You have to specify a data object dobj that is initially assigned to the field symbol.

The field symbol copies the technical attributes of structure struc as if it were completely typed. When you assign a data object using the addition DEFAULT, or later using ASSIGN, its complete data type is not checked in non- Unicode programs. Instead, the system merely checks whether it has at least the length of the structure and its alignment.

In Unicode programs, we differentiate between structured and elementary data objects. For a structured data object dobj, its Unicode fragment view has to match the one of struc. In the case of an elementary data object, the object must be character-type and flat, and struc must be purely character-type. The same applies to assignments of data objects to field symbols typed using STRUCTURE when using the ASSIGN statement.

Note

Field symbols declared using the addition STRUCTURE are a mixture of typed field symbols and a utility for casting structured data types. You should use the additions TYPE or LIKE for the FIELD-SYMBOLS statement to type field symbols, while the addition CASTING of the ASSIGN statement is used for casting.

Example

The first example shows the obsolete usage of the addition STRUCTURE.

DATA wa1(512) TYPE c.

FIELD-SYMBOLS STRUCTURE scarr DEFAULT wa1.

-carrid = '...'.

The second example shows the replacement of STRUCTURE with the additions TYPE and CASTING.

DATA wa2(512) TYPE c.

FIELD-SYMBOLS TYPE scarr.

ASSIGN wa2 TO CASTING.

-carrid = '...'.

Award points if it helps.

0 Kudos

For Smart forms:

Please give me reward point If it is useful

Thanks

Murali Poli

raymond_giuseppi
Active Contributor
0 Kudos

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

Regards