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: 

requirement of field symbols

Former Member
0 Kudos

can anyone pls tel me when wil we use field symbols in coding.

i mean eact use of field symbol with coded example.

<b></b>

6 REPLIES 6

Former Member
0 Kudos

Hi,

We use field symbols to dynamically assign or read the variables in a program or fields from a table.

here is an example by Anand.

DATA: LV_FIELDNAME(9) TYPE C,

LV_PREFIX(7) TYPE C VALUE 'G_LINE_' LV_LINE_NUMBER(2) TYPE N VALUE '12'.

FIELD-SYMBOLS : <FS_GLOBAL_VARIABLE>.

IF VAR1 IS NOT INITIAL.

PERFORM MOVE_VARIABLE USING VAR1.

ENDIF.

IF VAR2 IS NOT INITIAL.

PERFORM MOVE_VARIABLE USING VAR1.

ENDIF.

IF VAR3 IS NOT INITIAL.

PERFORM MOVE_VARIABLE USING VAR1.

ENDIF.

IF VAR3 IS NOT INITIAL.

PERFORM MOVE_VARIABLE USING VAR1.

ENDIF.

IF VAR3 IS NOT INITIAL.

PERFORM MOVE_VARIABLE USING VAR1.

ENDIF.

FORM MOVE_VARIABLES USING VAR1.

ADD 1 TO LV_LINE_NUMBER.

CONCATENATE LV_PREFIX LV_LINE_NUMBER INTO LV_FIELDNAME.

ASSIGN (LV_FIELDNAME) TO <FS_GLOBAL_VARIABLE>. <FS_GLOBAL_VARIABLE> = VAR1.ENDFORM

Please go throug this.

Cheers,

Sam

Former Member
0 Kudos

Hi,

Basic form:

============

FIELD-SYMBOLS <fs>.

Additions:

1. ... TYPE type

2. ... TYPE REF TO cif

3. ... TYPE REF TO DATA

4. ... TYPE LINE OF type

5. ... LIKE s

6. ... LIKE LINE OF s

7. ... TYPE tabkind

8. ... STRUCTURE s DEFAULT wa

In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See Untyped field symbols not allowedand Field symbols not allowed as components of classes.

It's effect:

===========

Declares a symbolic field with the name <fs>. At runtime, you can assign a concrete field to it using the ASSIGN statement. Any operations that you then perform using the field symbol directly affect the field that is assigned to it.

You may only use one of the additions specified above.

Cheers,

Venkat

Example

Displaying the aircraft type from SFLIGHT using a field symbol:

FIELD-SYMBOLS <PT> TYPE ANY.

TABLES SFLIGHT.

...

ASSIGN SFLIGHT-PLANETYPE TO <PT>.

WRITE <PT>.

Former Member
0 Kudos

Hi,

Basic form:

============

FIELD-SYMBOLS <fs>.

Additions:

1. ... TYPE type

2. ... TYPE REF TO cif

3. ... TYPE REF TO DATA

4. ... TYPE LINE OF type

5. ... LIKE s

6. ... LIKE LINE OF s

7. ... TYPE tabkind

8. ... STRUCTURE s DEFAULT wa

In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See Untyped field symbols not allowedand Field symbols not allowed as components of classes.

It's effect:

===========

Declares a symbolic field with the name <fs>. At runtime, you can assign a concrete field to it using the ASSIGN statement. Any operations that you then perform using the field symbol directly affect the field that is assigned to it.

You may only use one of the additions specified above.

Example

Displaying the aircraft type from SFLIGHT using a field symbol:

FIELD-SYMBOLS <PT> TYPE ANY.

TABLES SFLIGHT.

...

ASSIGN SFLIGHT-PLANETYPE TO <PT>.

WRITE <PT>.

Cheers,

Venkat

Former Member
0 Kudos

Check this out

&----


*& Chapter 24: Working with Field Symbols

&----


REPORT CHAP2401.

  • Defining a Field Symbol

FIELD-SYMBOLS <FS>.

  • Variable for later use

DATA FIELD VALUE 'X'.

  • Assigning a field to a Field Symbol

ASSIGN FIELD TO <FS>.

  • Using a Field Symbol which has an assigned field

WRITE <FS>.

Hope this helps.

Thanks & Regards,

Judith.

Former Member
0 Kudos

Hi karthik,

1 )A field symbol is a place holder for a field(i.e. a pointer). A field symbol does not reverse space for the field , but points to the field (i.e., a field symbol assumes the address of the field, not the value).

2 )Field symbols are used while runtime rendering of any field. The example below demonstrates the use of field symbols.

PARAMETERS field(8) DEFAULT sy-uzeit.
FIELD-SYMBOLS <fsymbol>.
ASSIGN (field) TO <fsymbol>.
IF sy-subrc = 0.
  WRITE : / 'the contents of field ',field, <fsymbol>.
ELSE.
  WRITE : / 'failure assigning field ', field , ' TO field symbol'.
ENDIF.

Thanks & Regards,

Kingshuk Dutta.

PS: Consider awarding points for helpful answers.