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: 

Internal Table

Former Member
0 Kudos

Hi Experts,

I have three data's in my Internal Table.

Name age Sex

A 22 MALE

B 20 MALE

C 28 MALE

and My WA have one data like,

B 20 MALE

Now I want to delete the Internal table Record whare stored in WA.

Means based on WA value I want to delete tha REcord from Internal Table. From the above example I want to delete the Record "B" from internal table using WA.

Any body help me the with solution.

Thanks in advance.

Points Assured.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Loop at itab into wa_itab.

delete itab from wa_itab.

endloop.

whatever data comes in the workarea, that data in internal table is deleted.

Regards,

Vani.

17 REPLIES 17

Former Member
0 Kudos

delete itab from wa.

Former Member
0 Kudos

Hi Jasmine,

Use DELETE statement to delete a record in an internal table.

DELETE ITAB WHERE NAME = WA-NAME AND AGE = WA-AGE AND SEX = WA-SEX.

Thanks,

Vinay

former_member386202
Active Contributor
0 Kudos

Hi,

Do like this.

Loop at itab into wa.

if wa-name = 'B' and " U can check only one condtion also, it depends on u

wa_age = ' 20' and

wa_sex = 'MALE'.

delete itab.

endif.

endloop.

Regards,

Prashant

matt
Active Contributor
0 Kudos

DELETE TABLE itab FROM wa.

( Vasu G : without the TABLE, you'll get errors if you do this outside of a LOOP AT ).

( Vinaykumar G : not efficient for HASHED tables )

( Prashant Patil : very inefficient ).

matt

Former Member
0 Kudos

Hi Jasmine,

Try this,

Delete table it_int from wa.

Regards,

Kaveri

Former Member
0 Kudos

Hi,

Loop at itab into wa_itab.

delete itab from wa_itab.

endloop.

whatever data comes in the workarea, that data in internal table is deleted.

Regards,

Vani.

0 Kudos

Hi!

As your example doesn't mention how many entries your real internal table will have and how many of these you expect to delete, here is something else to consider:

I would be careful with deleting individual lines of an internal table if you have a <b>large</b> internal table and if you expect to delete <b>many lines</b> from it. If you do that one entry at a time, than this can cause performance issues, because for each line deleted, the subsequent entries of the internal table are basically moved up one line as far as their index is concerned. I've had cases where this made a program run very slowly!

Another approach could be to add a field "delete" to your itab-definition and modify just this field if the record needs to be deleted. Once you are done with determining all of the to-be-deleted entries you can do that with just one delete-statement: delete <i>itab</i> where delete = 'X'.

Works like a charm (but may not be applicable in all cases as stated above)

Cheers

Baerbel

0 Kudos

Thanks.

But My Internal table always has three data's only.

Former Member
0 Kudos

Hi

This will do the required...

DELETE TABLE itab FROM wa

This will search for the same entry like the record in the wrok area WA and it will delete it from the internal table

Thanks

Ravi

Message was edited by:

Ravikanth Alapati

Former Member
0 Kudos

Thanks for your efforts.

I deleted WA from Itab.

Now My requirement is I have second Internal Table with the Same structure.

my Second Internal table don't have any data. But data should be like this,

Name age Sex

B 20 MALE

A 22 MALE

C 28 MALE

In My First Internal table consist of following data's.

Name age Sex

A 22 MALE

C 28 MALE

My wa consist of following data's.

Name age Sex

B 20 MALE

How can I get the required outout in Second Internal Table using this first Internal Table and Wa.

Thanks in Advance.

0 Kudos

use following code.

itab2[] = itab1[] .

append wa to itab2.

0 Kudos

Hi Jasmine,

1) Copy 1st internal table into second intenal table and delete the record from 2nd internal table.

ITAB2[] = ITAB1[].

DELETE TABLE ITAB2 FROM WA.

2) Delete the record in work area first and then copy the remaining contents to 2nd internal table

DELETE TABLE ITAB1 FROM WA.

ITAB2[] = ITAB1[].

Thanks,

Vinay

0 Kudos

ur wa has

Name age Sex

B 20 MALE

itab1 has

Name age Sex

A 22 MALE

C 28 MALE

itab2[] = itab1[].

if u want in same order then use...

insert wa into table itab2 index 1.

now u will get

Name age Sex

B 20 MALE

A 22 MALE

C 28 MALE

into itab2.

Regards

Vasu

0 Kudos

Thanks Vasu,

But I got syntax error.

"ME->Itab1" and the line of "ME->WA" are incompatible.

Thanks.

0 Kudos

Thanks Vinay.

But from your code In Itab2 I have only two values(Data's A & C) only.

Thanks.

0 Kudos

use following code to get all the data from itab and wa

itab2[] = itab1[] .

append wa to itab2.

0 Kudos

Hi Jasmine,

You have two options to do this

1) Use MOVE-CORRESPONDING option with LOOP...ENDLOOP

LOOP AT ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2.

APPEND ITAB2.

CLEAR ITAB2.

ENDLOOP.

2) Declare 1st internal table with A,C,B and declare the 2nd internal table with A,C

and then use ITAB2[] = ITAB1[], Otherwise ITAB2[] = ITAB1[] doesnt work

Thanks,

Vinay