Skip to Content
author's profile photo Former Member
Former Member

field symbols

could you pls tell me whats the difference between

field symbols and ordinary variable.

why we go for field symbols.could you pls explain.

ambichan.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 17, 2005 at 04:34 AM

    hi ambi,

    a simple way to think of the two (in my opinion) is that a variable is a container, while a field symbol is a reference to the container.

    a very concrete way of showing the difference is via internal table manipulation. if you have an internal table and you wanted to modify its contents, usually you have to create a work area for the internal table, loop into it, and modify for each change...

    data: itab type table of zmara.
    data: wa_itab type mara.
    
    loop at itab assigning wa_itab.
      if ... "conditions
        wa_itab-lvorm = 'X'.
        modify itab from wa_itab.
      endif.
    endloop.
    

    ... whereas in the case of a field symbol, when you make modifications to it, it won't just change the values it's holding, but rather, change the values where the field symbol was referenced from...

    data: itab type table of zmara.
    field-symbols: <fs> type mara.
    
    loop at itab assigning <fs>.
      if ... "conditions
        <fs>-lvorm = 'X'.
      endif.
    endloop.
    

    also, check the ABAP documentation, if you're still confused - and ask us too.

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

    hope that helped.

    ryan.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 17, 2005 at 06:24 AM

    Hello Ambichan,

    1. <u>Difference between a fieldsymbol and an ordinary variable.</u>

    Ordinary variable takes up space in memory, depending on its data type. In other word, a variable can be looked at as the instantiation of a particular data-type. That is why we call them data-objects (of course, constants are also considered data-objects).

    A Field-symbol, being just a reference to a variable (or a data-object), will always occupy a constant memory no matter what data object it points to.

    2. <u>Why do we need field-symbols.</u>

    Field-symbols are a very important means of achieving dynamism in the programs that we write. Though they are often considered tricky to use, the kind of generic programming that can be done using them is almost unparallelled (with the exception of OO ABAP).

    3. <u>Where do we need to use Field-Symbols.</u>

    The answer would have to be almost anywhere that you want. But one of the most important and common of their uses that I have found is in the processing of internal tables, especially using the control-levels.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 17, 2005 at 07:05 AM

    hey anand mandalika & subramian,

    thanks for your clear explanation.

    however still i have doubt in one point.

    we have code here inside the loop using Field symbol.

    (just wondering why they use FSymbol here,by all means this

    program is not OO ABAP program)

    Loop at GLTZ.

    cn = '0'.

    do '16' times.

    cnt =cnt+1.

    if cnt > 9.

    fz+8 = cnt.

    else.

    fz+9 =cnt.

    endif.

    assign (fz) to <FIZ>

    sum = sum + <FIZ>

    enddo.

    endloop.

    From your point, i understood Ord.variable occurs space

    and F.symbol wont occupy it,

    However u said its very important means of acchieveing dynamism.

    what does it mean. does this dynamism relates with my code?

    from my point of view..i feel Field symbols and variable works same

    in this case. only difference is with memory and declaration.

    is it?

    i am sorry if i my understanding is wrong.

    ambichan.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I am not sure of the need of field-symbol in your program, but you have shown only part of the program. As Anand, has pointed out, you have not given the declaration of the Field-symbols and other variables used.

      For usage of Field-Symbols, you may want to look at the link , I have provided earlier as well as this weblog.

      <a href="/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table Internal table</a>

      Regards,

      Subramanian V.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.