11-27-2007 10:47 AM
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.
11-27-2007 10:53 AM
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.
11-27-2007 10:48 AM
11-27-2007 10:50 AM
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
11-27-2007 10:50 AM
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
11-27-2007 10:51 AM
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
11-27-2007 10:53 AM
11-27-2007 10:53 AM
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.
11-27-2007 11:12 AM
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
11-27-2007 11:16 AM
11-27-2007 11:00 AM
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
11-27-2007 11:11 AM
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.
11-27-2007 11:14 AM
11-27-2007 11:21 AM
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
11-27-2007 11:27 AM
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
11-27-2007 11:36 AM
Thanks Vasu,
But I got syntax error.
"ME->Itab1" and the line of "ME->WA" are incompatible.
Thanks.
11-27-2007 11:37 AM
Thanks Vinay.
But from your code In Itab2 I have only two values(Data's A & C) only.
Thanks.
11-27-2007 11:47 AM
use following code to get all the data from itab and wa
itab2[] = itab1[] .
append wa to itab2.
11-27-2007 11:49 AM
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