12-30-2013 6:27 AM
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
12-30-2013 7: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.
12-30-2013 6:46 AM
Hi Mario
Can you please rephrase your requirement...? how is <cellvalue> getting assigned
Please add the sample code.
Nabheet
12-30-2013 6: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
12-30-2013 7: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.
12-30-2013 7:24 AM
Hi Srikanth,
yes, I have to rethink! But I do not have a solution. That's why I posted this thread 🙂
Regards Mario
12-30-2013 7: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.
12-30-2013 7:27 AM
Mario what do you want to do with ABC..Lets your internal table has ABC XYZ DEF etc etc what are your trying to achieve.?
Nabheet
12-30-2013 7:51 AM
Hi -
Can you try with
loop at <fs_table_xls> assigning <fs_wa_xls>.
Instead of loop at <fs_table_xls> into <fs_wa_xls>.
Regards,
Atul Mohanty
12-30-2013 7:55 AM
Instead of using <abc> or <xyz>, use an internal table ITAB with two fields - ABC and XYZ. Instead of assigning the value in every iteration to this field symbol ( <abc> and <xyz> ) you can keep appending the values in the corresponding fields of this new internal table ITAB.
This can be changed as per your requirement.
Regards,
Fasi
12-30-2013 7:59 AM
Hi Atul,
thanks for your suggest; but it comes to an error:
During the processing of a "LOOP ... ASSIGNING" loop for the table
"{A:22*\TYPE=%_T00004S00000149O0000009392}", the field symbol used in the LOOP
was to be converted. This is
not allowed, because the connection of the field symbol to the original
table would be cut and the loop processing would no longer be well
defined.
12-30-2013 8:05 AM
12-30-2013 8:44 AM
Hi Mario -
Please check this below code ( if possible create a temporary program and check in debug mode), may be helpful.
TYPES : BEGIN OF t_itab,
value TYPE char20,
END OF t_itab.
DATA : itab TYPE STANDARD TABLE OF t_itab,
w_itab TYPE t_itab.
w_itab-value = 'KKKK ABC 12'.
APPEND w_itab TO itab.
w_itab-value = 'KKKZ MNP 657'.
APPEND w_itab TO itab.
w_itab-value = 'KKKZ XYZ 456'.
APPEND w_itab TO itab.
DATA : lv_itab(6) TYPE c VALUE 'ITAB[]'.
FIELD-SYMBOLS : <fs_table_xls> TYPE table,
<abc> TYPE any,
<xyz> TYPE any,
<fs_wa_xls> TYPE any.
ASSIGN (lv_itab) TO <fs_table_xls>.
IF <fs_table_xls> IS ASSIGNED.
LOOP AT <fs_table_xls> ASSIGNING <fs_wa_xls>.
IF <fs_wa_xls> CS 'ABC'.
ASSIGN <fs_wa_xls> TO <abc>.
ENDIF.
IF <fs_wa_xls> CS 'XYZ'.
ASSIGN <fs_wa_xls> TO <xyz>.
ENDIF.
ENDLOOP.
ENDIF.
Regards,
Atul Mohanty
12-30-2013 9:51 AM
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.
12-30-2013 7: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
12-30-2013 7: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.
12-30-2013 8: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
12-30-2013 8:09 AM
You need to create a variable rather than a field symbol.
loop at <fs_table_xls> into <fs_wa_xls>.
IF sy-tabix = 1. " or IF <cellvalue> CS 'ABC'.
abc = <fs_wa_xls>.
endif.
IF sy-tabix = 2. " or IF <cellvalue> CS 'XYZ'.
xyz = <fs_wa_xls>.
endif.
endloop.
12-30-2013 8:14 AM
Hi susmitha,
but how do I have to declare abc?
data: abc type ???
Thanks
Regards Mario
12-30-2013 8:16 AM
Same as <fs_wa_xls>.
Or you could just use the assigning option instead of into in the loop statement. It will work fine.
loop at <fs_table_xls> assigning <fs_wa_xls>.
IF sy-tabix = 1. "or IF <cellvalue> CS 'ABC'.
assign <fs_wa_xls> to <ABC>.
endif.
IF sy-tabix = 2. "or IF <cellvalue> CS 'XYZ'.
assign <fs_wa_xls> to <XYZ>.
endif.
endloop.
When you do this, <XYZ> and <ABC> will point to that record in the table it is assigned to rather than to the contents of <fs_wa_xls>. So even if <fs_wa_xls> changes, <XYZ> and <ABC> will continue to point to the initial record.
12-30-2013 8:19 AM
12-30-2013 9:20 AM
Hi Nabheet,
i have to upload several EXCEL with different design.
I wanted to keep it dynamic.
Regards Mario
12-30-2013 8: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
12-30-2013 8:41 AM
Hi Mario,
Please post the correct answer so that someone else could benefit from it.
Hi Fasi,
could you give pls. more details?
Thx, Mario
is definitely not the right answer.
Regards,
Philip.
12-30-2013 9:17 AM
Hi Philip,
FIELD-SYMBOLS:
<ABC> TYPE ANY,
<XYZ> TYPE ANY.
loop at <fs_table> ASSIGNING <fs_wa>.
if sy-tabix = 1.
assign <fs_wa> to <ABC>.
endif.
if sy-tabix = 2.
assign <fs_wa> to <XYZ>.
endif.
endloop.
write:/ 'abc ',<abc>.
write:/ 'xyz ',<xyz>.
Regards
Mario
12-30-2013 9:19 AM
12-30-2013 9:25 AM
That means you did have to change your program... You did change into to assigning in the loop statement. So it was not 'a time lack in compilation' after all.