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 symbol

Former Member
0 Kudos
85

Hi,

Can someone tell me what is the exaxt use of field symbols ?

I was trying to debug some code as follows and I encountered field symbol stuff:

FORM ARRANGE_DATA_FOR_SMARTFORM .

FIELD-SYMBOLS : <FS_FIELDNAME>,

<ZPLMECFORMS>.

DATA: SYTABIX LIKE SY-TABIX,

TABNAME LIKE DD02L-TABNAME VALUE 'ZPLMECFORMS',

DDFIELD LIKE DDFIELD OCCURS 50 WITH HEADER LINE,

T_DATE LIKE CAWN-ATWRT.

CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'

EXPORTING

  • KEYFIELDS = 'X'

  • NULLABLE = 'X'

TABNAME = TABNAME

  • IMPORTING

  • SUBRC =

TABLES

DDFIELDS = DDFIELD

.

      • LOGIC FOR DYNAMIC ASSIGNMENT OF THE CHARATERISTICS VALUES TO THE

      • SMARTFORM INTERFACE STRUCTURE

LOOP AT DDFIELD ASSIGNING <FS_FIELDNAME>.

SYTABIX = SY-TABIX.

      • READ THE CHARACTERISTICS VALUES MAINTAINED IN 'CHAR' TYPE IN

      • STRUCTURE BAPI1003_ALLOC_VALUES_CHAR

READ TABLE T_CHAR_CHR WITH KEY CHARACT = <FS_FIELDNAME>(35).

IF SY-SUBRC = 0.

ASSIGN COMPONENT SYTABIX OF STRUCTURE T_ZPLMECFORMS TO <ZPLMECFORMS>.

<ZPLMECFORMS> = T_CHAR_CHR-VALUE_CHAR.

ENDIF.

.

.

.

.

.

Tushar

4 REPLIES 4

alejandro_lpez
Contributor
0 Kudos
42

Hi Tushar ,

Field Symbol are like pointer to memory in ABAP. When you use the instruction :

LOOP AT DDFIELD ASSIGNING <FS_FIELDNAME>.

<SOME CODE>

ENDLOOP.

you can access the content of the internal table DDFIELD and modify it, because <FS_FIELDNAME> aims to DDFIELD (actual registry in the loop) .

Alejandro

Former Member
0 Kudos
42

Hi,

Field symbols points to the assigned data object in memory and doesn't take separate memory. If you change the contents of field symbol, it will actually change the content of memory location, it is pointing to. So you are changing the assigned object.

e.g.

Data : a tpe i.

field-symbols : <fs> type any.

a = 12345.

write : /1 a.

assign a to <fs>.

      • Point 1

<fs> = 678.

write : /1 a, <fs>.

      • Point 2

a = 987.

write : /1 a, <fs>.

In above example The output will be

12345

678 678

987 987

After point 1, the field symbol is assigned value 678, which changes value of a as 678.

when you change contents of "a" after point 2, <fs> have same value as it points to same memory.

eg 2.

you have two variable

ABC type i.

ch(10) type c.

At runtime if you want to get the value of variable known at run time only

abc = 10000.

c = 'ABC'

assign (c) to <fs>.

Here <fs> has value 10000, as it is pointing to memory location of var ABC.

Former Member
0 Kudos
42

Hi,

To learn the use of field symbol, you can refer the following links:

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

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm

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

Also a code sample, u can debugg and see it:


DATA :  BEGIN OF t_data OCCURS 0,
          line(5000),
        END OF t_data.
DATA : n TYPE I.

FIELD-SYMBOLS <fs> TYPE ANY TABLE.
ASSIGN t_data[] TO <fs>.
DESCRIBE TABLE <FS> lines n.

Regards,

Anjali

Former Member
0 Kudos
42

Hi Tushar,

If u ahve experience with 'C', then understand this to be similar to a pointer.

It is used to reference another variable dynamically. So this field symbol will simply point to some other variable. and this pointer can be changed at runtime.

In ur case.. LOOP AT DDFIELD ASSIGNING <FS_FIELDNAME>

if ddfield has 5 records, each time one record is looped at and assigned to fs_fieldname.

Same is the case here..

ASSIGN COMPONENT SYTABIX OF STRUCTURE T_ZPLMECFORMS TO <ZPLMECFORMS>.

The field sytabix of t_zplmecforms is assigned dynamically to <Zplmecforms>.

Actually, it doesnt copy the value of it to the field-symbol. But simply points to sytabix field of T_ZPLMECFORMS. if the value of sytabix changes in T_ZPLMECFORMS, the same is reflected in the field symbol also.

Kindly reward suitable points to messages that helped answer ur question.

Reg,

PP.