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

how to access dynamic fields in a field symbol


how do i access the dynamic fields created in side a field-symbol....

wht i mean is i have a table, whose workarea i assign to field symbol. but this table is runtime, altough i have debugged and found the values in this table, I want to accees the field symbol in a generic way.

say the table has 3 fields now fld1 fld2 and fld3 so i want to access the field symbol <fs> as <fs>-(name) where name can be anything fld1 or fld2 whichever i assign....

thanks. Let me know if you have any further questions.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Nov 02, 2007 at 07:11 PM

    Access the field symbol like this

    FIELD-SYMBOLS: <wa>   TYPE ANY,   "<< Table work area
                   <comp> TYPE ANY.     "<< variable to hold the values
    WHILE sy-subrc = 0. 
      ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>. 
      WRITE / <comp>. 


    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member


      i want to assign value to the field symbol itself and that to, to a particular field of u get it now?

      field is wht i fix runtime......maybe fld1 or fld2.

      and i want to do <fs>-(field) = 20.

  • author's profile photo Former Member
    Former Member
    Posted on Nov 02, 2007 at 07:14 PM

    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 de-referenced pointers in the C programming language (that is, pointers to which the content operator * is applied). In ABAP, data references represent a real equivalent to pointers in the sense of variables that contain a memory address and can be used without the contents operator.

    All operations programmed with field symbols are applied to the field assigned to it. A MOVE statement between two field symbols, for example, assigns the contents of the field assigned to another source field symbol to the field assigned to the target field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before the MOVEstatement.

    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 during the field assignment whether the assigned field matches the type of field symbol.

    Field symbols provide greater flexibility when you address data objects:

    · You can assign one field symbol to another, which allows you to address subfields.

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

    · You can also force a field symbol to take different technical properties than those of the field assigned to it (casting).

    The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.

    While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.

    For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. The MOVE statement (with your own auxiliary variables, if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.

    To declare a field symbol, use the statement


    For field symbols, the angle brackets are part of the syntax. They identify field symbols in the program code.

    If you do not specify any additions, the field symbol.

    in a static ASSIGN and:

    ASSIGN (dobj) TO from the second loop pass onwards.

    Add a comment
    10|10000 characters needed characters exceeded

    • Naimesh's solution will work for standard tables, but for other types, you need to be careful about what you're changing. Remember that with field-symbols, you are directly working with the data in memory. 0FISCPER is part of the key of your hashed table - <data> points to it, so you can't change it. You need another work area to make the change. This should work.

      DATA: lp_data TYPE REF TO DATA.
      CREATE DATA lp_data LIKE <wa_data>.
      ASSIGN lp_data->* TO <wa_temp>.
      <wa_temp> = <wa_data>.
      IF <data> IS ASSIGNED.
        IF <data> IS INITIAL.
          <data> = v_per   
        COLLECT <wa_data> INTO c_th_data.


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.