02-26-2013 3:23 PM
Hi experts,
In an internal table, i have some data. I want to modify all the records contained in the fieldC to a fixed value 'XXXX'
I tought about this treatment:
LOOP AT itab INTO str.
str2t2 = str.
str2-fieldC = 'XXXXX'.
APPEND str2 TO itab.
CLEAR str2.
ENDLOOP.
It's working fine now, but i am afraid about performance in the future. What are you advices?
Any better way to perform it?
Thanks.
Amine
02-26-2013 3:55 PM
Hi Amine,
I'm dont know the structure of your internal Table and also the requirement. If this change is mandatory , then proceed with it. I think, It should not cause any performance issue
In some cases if we want to modify only a some records. U can try this also.
str2-fieldC = 'XXXX'.
modify itab into str transporting fieldC where fieldC = Value1 or fieldA = Value2. " Here the fieldC would be modified where fieldA has Value -> Value 1 or Value2
Thanks
Vivek
02-26-2013 3:41 PM
Hi Amine,
If you want to Modify the data,then why you are appending the data?You have to modify the table line using workarea after assigning proper value to 'str2-fieldC'.If you append to the same internet table when will the loop ends.I am not sure how come it is working perfect in your case.
Use Modify statement instead of Append.
Thanks
Siva
02-26-2013 3:55 PM
Hi Amine,
I'm dont know the structure of your internal Table and also the requirement. If this change is mandatory , then proceed with it. I think, It should not cause any performance issue
In some cases if we want to modify only a some records. U can try this also.
str2-fieldC = 'XXXX'.
modify itab into str transporting fieldC where fieldC = Value1 or fieldA = Value2. " Here the fieldC would be modified where fieldA has Value -> Value 1 or Value2
Thanks
Vivek
02-26-2013 4:01 PM
Hi Amine,
I really don't see any concerns from performance perspective once to perfom LOOP without any specific condition (as your case) normaly is done quite fast. But a question about your code purposes, you're adding new entry at each loop performed, is this what you need? I'm affraid you could have an endless loop.
Maybe you should use MODIFY instead.
Regards,
Edgar
02-26-2013 4:11 PM
Hi Amine,
Rather than using loop you can use modify statement.
MODIFY itab FROM str TRANSPORTING fieldC WHERE <your condition>.
where str is your work area containing your required value.
You may choose not to specify any condition.
Hope this helps
02-26-2013 4:13 PM
Try using Modify Internal Table Statement From Workarea
using Where and Transporting Clauses.
Let me know if it works.
Thanks
Gaurav
02-26-2013 5:29 PM
Dear Amine,
Please go throught this below code where a field symbol is used you need not to modify or append the table.
Ty_itab can be structure, type or table.
FIELD-SYMBOLS : <fs_field> TYPE ty_itab.
itab TYPE STANDARD TABLE OF ty_itab.
unassign : <fs_field>.
loop at itab assigning <fs_field>.
<fs_field>-fieldC = 'XXXXX'.
endloop.
Above code is enough.
Hope this helps you.
Kindly let me know.
Thanks & Regards,
Vignesh Yeram
02-27-2013 8:00 AM
Hi,
All solutions given in post are correct. However solution from Vignesh that uses assigning will be the fastest for many rows in itab and I would recommend it. Assign statement works on reference and there is no need of row copying to work area like in case of loop. Memory operations are anyhow fast, but in case of very large table this will make some difference.
Regards
Adam
02-26-2013 5:54 PM
Hi,
Instead of the append u can use the modify statement which doesnot give any impact on ur performance.
02-26-2013 5:59 PM
Is this your actual code, you are looping at the internal table, together appending new records, so that can generate an endless loop, and trigger memory exhaustion and dump once initial table is not empty ?
From LOOP AT itab
If you insert rows after the current row, these new rows will be processed in the subsequent loop passes. An endless loop can result.
Read first some documentation like processing Statements for Internal Tables in Abap Internal Tables online documentation.
Regards,
Raymond
02-26-2013 7:13 PM
02-26-2013 7:25 PM
Just one detail guys,
str is not a structure in my example, but a workarea.
Everything is working fine
Amine
02-27-2013 3:28 AM
excellent piece of information, I had come to know about your website from my friend kishore, pune,i have read atleast 8 posts of yours by now, and let me tell you, your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a lot once again, Regards, <a href=" http://sapinfos.blogspot.com//">sap</a>
03-18-2014 6:28 AM
Hi,
Friends
Please take 1 example and give beef explanation with code also..
Thanks,
Roopa.k