Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Change the records with abap in internal table

amine_lamkaissi
Active Contributor
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

13 REPLIES 13

siva_subramanian2
Participant
0 Kudos

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

Former Member
0 Kudos

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

edgar_nagasaki
Contributor
0 Kudos

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

former_member491621
Contributor
0 Kudos

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

Former Member
0 Kudos

Try using Modify Internal Table Statement From Workarea

using Where and Transporting Clauses.

Let me know if it works.

Thanks

Gaurav

vigneshyeram
Active Participant
0 Kudos

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

0 Kudos

Hi,

All solutions given in post are correct. However solution from 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

Former Member
0 Kudos

Hi,

Instead of the append u can use the modify statement which doesnot give any impact on ur performance.

  1. LOOP AT itab INTO str. 
  2.      strstr2t2 = str. 
  3.      str2-fieldC = 'XXXXX'
  4.   modify  itab from str2 transporting fieldc.

  5. *     APPEND str2 TO  itab. 
  6.      CLEAR str2. 
  7.    ENDLOOP.

raymond_giuseppi
Active Contributor
0 Kudos

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

amine_lamkaissi
Active Contributor
0 Kudos

Thanks to all guys for your explanations.

Amine

amine_lamkaissi
Active Contributor
0 Kudos

Just one detail guys,

str is not a structure in my example, but a workarea.

Everything is working fine

Amine

Former Member
0 Kudos

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>

Former Member
0 Kudos

Hi,

Friends

Please take 1 example and give beef explanation with code also..

Thanks,

Roopa.k