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

Value of field symbol is changing during loop over dynamic internal table

Hallo,

I created a dynamic internal table.

I want to loop over the table.

If a row contains a certain value (In this Sample ABC or XYZ) I want wo keep the value.

In my sample to <ABC> or <XYZ>

But when the loop goes on and the value of <fs_wa_xls> changes also the value of <ABC> is changing.

loop at <fs_table_xls> into <fs_wa_xls>.

IF <cellvalue> CS 'ABC'.

assign <fs_wa_xls> to <ABC>.

endif.

IF <cellvalue> CS 'XYZ'.

assign <fs_wa_xls> to <XYZ>.

endif.

endloop.

How can I prevent the changing of <ABC>?

Thanks and many regards

Mario

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 07:23 AM

    Sorry,

    i made a misstake in the coding. One line was missing:

    loop at <fs_table_xls> into <fs_wa_xls>.

    ASSIGN COMPONENT 1 of STRUCTURE <fs_wa_xls> to <cellvalue>.

    IF <cellvalue> CS 'ABC'.

    assign <fs_wa_xls> to <ABC>.

    endif.

    IF <cellvalue> CS 'XYZ'.

    assign <fs_wa_xls> to <XYZ>.

    endif.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member


      Types: begin of itype,

      abc type char30,

      xyz type char30,

      end of itype.

      data: itab type table of itype with header line.


      loop at <fs_table_xls> into <fs_wa_xls>.

      ASSIGN COMPONENT 1 of STRUCTURE <fs_wa_xls> to <cellvalue>.

      IF <cellvalue> CS 'ABC'.

      assign <fs_wa_xls> to <ABC>.

      move <abc> to itab-abc.

      append itab.

      clear itab.

      endif.

      IF <cellvalue> CS 'XYZ'.

      assign <fs_wa_xls> to <XYZ>.

      move <xyz> to itab-xyz.

      append itab.

      clear itab.

      endif.

      endloop.


      * At the end, you will have all the data available in ITAB. You can use it further as per your requirement.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 08:03 AM

    Hello all,

    sorry for the indistinct formulation.

    The code could also look like

    loop at <fs_table_xls> into <fs_wa_xls>.

    IF sy-tabix = 1.

    assign <fs_wa_xls> to <ABC>.

    endif.

    IF sy-tabix = 2.

    assign <fs_wa_xls> to <XYZ>.

    endif.

    endloop.

    After the second loop ( when sy-tabix = 2 ) the value of <ABC> gets also changed, because <fs_wa_xls> is changing.

    How can I prevent <ABC> from getting changed.


    Thanks

    Regards Mairo

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 08:33 AM

    Hello all,

    sorry for the inconvieniences. But as I debugged now, my programm works correct.

    I guess the compilation had a time lack

    Havy a happy 2014!

    Regards Mario

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 07:01 AM

    Hi Mario,

    Due to the below statement the value of <fs_wa_xls> changes also the value of <ABC> is changing.

    assign <fs_wa_xls> to <ABC>.

    you need to rethink your logic.

    Regards,

    Srikanth.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 30, 2013 at 07:43 AM

    Don't use a work area (even if defined thru field-symbols) in the LOOP statement, but assign to the field-symbol.

    LOOP AT itab ASSIGNING <record>.
    ASSIGN COMPONENT 1 OF STRUCTURE <record> TO <cellvalue>.
    IF <cellvalue> CS 'ABC'.
    ASSIGN <record> TO <abc>.
    ENDIF.
    IF <cellvalue> CS 'XYZ'.
    ASSIGN <record> TO <xyz>.
    ENDIF.
    ENDLOOP.

    In your code the work area is a single area in memory, like a single variable, which changes at each iteration of the LOOP, in my code the area is the actual area in the internal table

    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 30, 2013 at 07:47 AM

    Hi Mario,

    I think that is how it field symbols works.. when you assign a field symbol, it does assign the reference not the value. This is the reason when you change the value at later point it changes the value in the fields.

    I still didn't get the context.

    1. When you are using 'CS', how come both the IF statements can be satisfied?

    2. May be you need to push it to variable(not field symbol) , i guess you have a purpose to write IF conditions and this should be satisfied before you reuse the field symbol again in the same loop or in the next loop.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 30, 2013 at 06:46 AM

    Hi Mario

    Can you please rephrase your requirement...? how is <cellvalue> getting assigned

    Please add the sample code.

    Nabheet

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 06:54 AM

    Hi Mario,

    What are entries in your internal table? May be when you are executing loop, it is taking value as ABC and then changing.

    Thanks

    Siddarth

    Add a comment
    10|10000 characters needed characters exceeded

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.