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 doubt ?

Former Member
0 Kudos

Hi,

Can any one explain the essence of usage of field symbols?

Please provide your deep understanding?

Vijayanand.

Note:

1) Please don't cut and paste your answers.

2) Please don't provide the link, which has not be realised or learned.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi adding to above points,

if u see & execute following code....

field-symbols : <f>.

data : a type i,

b type c,

c type f.

a = 5.

b = 'Z'.

c = '1.5'.

assign a to <f>.

write 😕 <f>.

assign b to <f>.

write 😕 <f>.

assign c to <f>.

write 😕 <f>.

u can observe that this field symbol <f> can store any data type unlike variables a,b&c ( in above example) which can store only corresponding data types.

This is advantage with field symbols.

Regards

Vasu

8 REPLIES 8

Former Member
0 Kudos

hi,

Field symbols are placeholders or symbolic names for other fields.Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol.

Field symbols provide greater flexibility when you address data objects:

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.

Regards

Sudheer

Former Member
0 Kudos

Hi adding to above points,

if u see & execute following code....

field-symbols : <f>.

data : a type i,

b type c,

c type f.

a = 5.

b = 'Z'.

c = '1.5'.

assign a to <f>.

write 😕 <f>.

assign b to <f>.

write 😕 <f>.

assign c to <f>.

write 😕 <f>.

u can observe that this field symbol <f> can store any data type unlike variables a,b&c ( in above example) which can store only corresponding data types.

This is advantage with field symbols.

Regards

Vasu

0 Kudos

Hi Vasu,

In this program, whatz the use. If I have already declared the work area, why should I create a field-symbols, which will do the operation?

Vijayanand.

-


TYPES: BEGIN OF TY_AUFK,

AUFNR TYPE AUFNR,

KTEXT TYPE KTEXT,

OBJNR TYPE OBJNR,

END OF TY_AUFK.

TYPES: BEGIN OF TY_VBAK,

VBELN TYPE VBELN_VA,

ERNAM TYPE ERNAM,

ERDAT TYPE ERDAT,

END OF TY_VBAK.

DATA: WA_AUFK TYPE TY_AUFK,

WA_VBAK TYPE TY_VBAK.

PARAMETERS: P_AUFNR TYPE AUFK-AUFNR,

P_VBELN TYPE VBAK-VBELN.

FIELD-SYMBOLS <FS1> TYPE TY_AUFK.

ASSIGN WA_AUFK TO <FS1>.

SELECT SINGLE AUFNR KTEXT OBJNR

FROM AUFK

INTO <FS1>

WHERE AUFNR = P_AUFNR.

WRITE:/ 'With field symbols, We have got AUFNR:', <FS1>-AUFNR, 'KTEXT:', <FS1>-KTEXT, 'OBJNR:', <FS1>-OBJNR.

FIELD-SYMBOLS <FS2> TYPE TY_VBAK.

ASSIGN WA_VBAK TO <FS2>.

SELECT SINGLE VBELN

FROM VBAK

INTO <FS2>

WHERE VBELN = P_VBELN.

WRITE:/ 'With field symbols, We have got VBELN:',<FS2>-VBELN, 'ERNAM:', <FS2>-ERNAM, 'ERDAT:', <FS2>-ERDAT.

-


0 Kudos

Hello Vijay,

You may know definition of field symbole ,see the below simple example :

PERFORM down_load TABLES table1.

PERFORM down_load TABLES table1.

PERFORM down_load TABLES table1.

FORM down_load TABLES p_tab_data.

FIELD-SYMBOLS: <wa> TYPE ANY.

OPEN DATASET adress IN TEXT MODE

ENCODING DEFAULT FOR OUTPUT.

IF sy-subrc = 0.

no_file = ' '.

LOOP AT p_tab_data ASSIGNING <wa>.

TRANSFER <wa> TO adress.

ENDLOOP.

CLOSE DATASET adress.

ELSE.

no_file = 'X'.

ENDIF.

ENDFORM.

Here i am using field symbol within form routine since i do not know what table structure i have to use.

Here i am downloading the data from SAP Tables to Files,i have many tables,so can't write big code,i just use one form routine for all perform routine,here field symbol is major thing.

Thanks

Seshu

0 Kudos

Hi Seshu,

I have asked a doubt in my program, which I had asked in my previous question(Please Refer).

TYPES: BEGIN OF TY_AUFK,

AUFNR TYPE AUFNR,

KTEXT TYPE KTEXT,

OBJNR TYPE OBJNR,

END OF TY_AUFK.

TYPES: BEGIN OF TY_VBAK,

VBELN TYPE VBELN_VA,

ERNAM TYPE ERNAM,

ERDAT TYPE ERDAT,

END OF TY_VBAK.

DATA: WA_AUFK TYPE TY_AUFK,

WA_VBAK TYPE TY_VBAK.

PARAMETERS: P_AUFNR TYPE AUFK-AUFNR,

P_VBELN TYPE VBAK-VBELN.

FIELD-SYMBOLS <FS1> TYPE TY_AUFK.

ASSIGN WA_AUFK TO <FS1>.

Assume this as as a sample code, where whats the use of Field-symbols <FS1>, when I have already declared WA_AUFK and assigning it to <FS1>.

Memory allocation is same right?

Please comment?

Vijayanand.

Former Member
0 Kudos

hi vijayanand,

simple definition to field symbols:

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

Think of the pointers thing in C, place holders play the same role.

Regards....

Arun.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

Hi Vijaya,

Not sure why don't want cut/paste document. Anyway you will find SAP Documentation is the best explaination.

I couldn't paste the link, so pasting the details.

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 a field symbol before you can address it in a program.

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.

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:

For more detail refer this link -:

http://help.sap.com/saphelp_46c/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

-> ABAP Programing - baisc Statements - Field Symbols

Sample Program:

TYPES: BEGIN OF LINE,

COL1,

COL2,

END OF LINE.

DATA: WA TYPE LINE,

ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1,

KEY(4) VALUE 'COL1'.

FIELD-SYMBOLS <FS> TYPE ANY TABLE.

ASSIGN ITAB TO <FS>.

READ TABLE <FS> WITH TABLE KEY (KEY) = 'X' INTO WA.

The internal table ITAB is assigned to the generic field symbol <FS>, after which it is possible to address the table key of the field symbol dynamically. However, the static address

READ TABLE <FS> WITH TABLE KEY COL1 = 'X' INTO WA.

is syntactically not possible, since the formal parameter P does not adopt the key of table ITAB until runtime. In the program, the type specification ANY TABLE only indicates that <FS> is a table. If the type had been ANY (or no type had been specified at all), even the specific internal table statement READ TABLE <FS> would not have been possible.

If you adopt a structured type generically (a structure, or a table with structured line type), the individual components cannot be addressed in the program either statically or dynamically. In this case, you would have to work with further field symbols and the method of assigning structures component by component.

Specifying the Type Fully

When you use the following types, the technical attributes of the field symbols are fully specified. The technical attributes of the data objects must correspond to those of the field symbol.

Type specification

Technical attributes of the field symbol

TYPE D, F, I, or T

The field symbol has the technical attributes of the predefined elementary type

TYPE <type>

The field symbol has the type <type>. This is a data type defined within the program using the TYPES statement, or a type from the ABAP Dictionary

TYPE REF TO <cif>

The field symbol is a reference variable (ABAP Objects) for the class or interface <cif>

TYPE LINE OF <itab>

The field symbol has the same type as a line of the internal table <itab> defined using a TYPES statement or defined in the ABAP Dictionary

LIKE <f>

The field symbol has the same type as an internal data object <f> or structure, or a database table from the ABAP Dictionary

When you use a field symbol that is fully typed, you can address its attributes statically in the program, since they are recognized in the source code. If you fully specify the type of a field symbol as a reference or structured data object, you can address it as you would the data object itself once you have assigned an object to it. So, for example, you could address the components of a structure, loop through an internal table, or create an object with reference to a field symbol.

DATA: BEGIN OF LINE,

COL1,

COL2 VALUE 'X',

END OF LINE.

FIELD-SYMBOLS <FS> LIKE LINE.

ASSIGN LINE TO <FS>.

MOVE <FS>-COL2 TO <FS>-COL1.

The field symbol <FS> is fully typed as a structure, and you can address its components in the program.

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

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.

The output is:

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.

<b><REMOVED BY MODERATOR></b>

<b>Manish</b>

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

Hi

FIELD-SYMBOLS

<b>FIELD-SYMBOLS <fs></b>

1)After its declaration, a field symbol is initial - that is, it does not reference a memory area.

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

3)The FIELD-SYMBOLS statement declares a field symbol <fs>.

4)The name conventions apply to the name fs.

5)The angle brackets of the field symbols indicate the difference to data objects and are obligatory.

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

7)You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo