Application Development and Automation 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: 
Read only

How to select data from an internal table

Former Member
0 Likes
8,363

material norm date last modified

B2-SP HEAT 50.000 20090420

BF COKE 575.000 20090419

GROSS COKE 200.000 20090419

B2-SP HEAT 100.000 20090419

TWT 33.000 20090330

B7-SP HEAT 2.000 20090310

B1-SP HEAT 1.000 20090309

B7-SP HEAT 615.000 20090308

B2-SP HEAT 585.000 20090308

B1-SP HEAT 100.000 20090308

B3-SP HEAT 610.000 20090308

BF COKE 68.500 20090308

GROSS COKE 72.600 20090308

B8-SP HEAT 600.000 20090308

B9-SP HEAT 625.000 20090308

BX-SP HEAT 615.000 20090308

B9-SP HEAT 58.000 20090307

B1-SP HEAT 100.000 20090307

B6-SP HEAT 350.000 20090306

B2-SP HEAT 888.000 20090306

Like above there r numerous data in a table :

how will i select data into another internal table where material above is not repeated with latest modified date.please help.

material norm date last modified

B2-SP HEAT 50.000 20090420

BF COKE 575.000 20090419

GROSS COKE 200.000 20090419

B2-SP HEAT 100.000 20090419

TWT 33.000 20090330

B7-SP HEAT 2.000 20090310

B1-SP HEAT 1.000 20090309

B7-SP HEAT 615.000 20090308

B2-SP HEAT 585.000 20090308

B1-SP HEAT 100.000 20090308

B3-SP HEAT 610.000 20090308

BF COKE 68.500 20090308

GROSS COKE 72.600 20090308

B8-SP HEAT 600.000 20090308

B9-SP HEAT 625.000 20090308

BX-SP HEAT 615.000 20090308

B9-SP HEAT 58.000 20090307

B1-SP HEAT 100.000 20090307

B6-SP HEAT 350.000 20090306

B2-SP HEAT 888.000 20090306

Like above there r numerous data in a table :

how will i select data into another internal table where material above is not repeated with latest modified date.please help.

14 REPLIES 14
Read only

Former Member
0 Likes
1,902

Hi,

1) Sort the internal table with respect to material and latest date

2) delete the records which you want by using delete internal table

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,902

Sort ur internal table by material last date .

itab2[] = itab[].

Loop at itab.

read table itab2 with key matnr = itab-date date = itab-date.

if sy-subrc eq 0.

delete itab2 from wa.

else.

continue.

endif,

endloop,

Read only

Former Member
0 Likes
1,902

Hi Sonu,


Loop at itab1.
loop at itab2 where matnr = itab1-matnr.
delete itab2 index sy-tabix.
endloop.
endloop.
now itab1 has same records,
and itab2 has records who are not available in itab1 materials.

now move two tables data inot final internal table.

Regards,

Prabhudas

Read only

Former Member
0 Likes
1,902

Hi,

First sort the table by material and last modified.

SORT itab BY material last_modified.

And then as you don't want same material that has been modified twice on the same day.. just delete those.

DELETE ADJACENT DUPLICATES COMPARING material last_modified.

Now you no need to pass the entries into some other internal table but can use the same itab as the duplicate entries are deleted already..

Hope this helps you...

Read only

Former Member
0 Likes
1,902

you just have to sort and delete adjacent duplicate.

sort it_itab material last_modified.

delete adjacent duplicates comparing material last_modified.

Regards,

Lalit Mohan Gupta

Read only

0 Likes
1,902

hi,

First sort the internal table it_tab in ascending order of material and descending order for last_material.

Delete adjacent duplicates. This will keep the records with lates modified date for the material.

SORT it_tab BY matrial ASCENDING

date DESCENDING.

delete adjacent duplicates comparing material.

hope it helps.

Read only

Former Member
0 Likes
1,902

Hi,

First sort the Internal Table with MATNR in assending order and DATE in descending order.

Then, use DELETE ADJACENT DUPLICATES FROM ITAB comparing MATNR DATE.

In this case, all the duplicates records of MATNR(sorted ascending order) and DATE (sorted in descending order, so the old records wil be in the bottom,) will be deleted. Only the latest updated records will be available in ITAB.

Then Move ITAB[] to ITAB2[].

Best Wishes,

Sai Prasad

Read only

Former Member
0 Likes
1,902

Dear somu .

First sort the Internal Table with matnr.

Next, use DELETE ADJACENT DUPLICATES FROM ITAB comparing matnr lastmodified date.

I hope this is useful .

Regards ,

GJ

Read only

Former Member
0 Likes
1,902

HI Sonu,

As u want the matnr not repeated with latest modified into another table,

First move itab1 to itab2.

sort itab2 by matnr ascending last modified descending.

delete adjacent duplicates from itab2 comapring matnr.

Read only

0 Likes
1,902

Hi Sonu,

You can use the following algorithm:


DATA: count type i.

SORT itab by date_last_modified material.

LOOP AT itab into wa.
	CLEAR count.
	LOOP AT itab INTO wa1 WHERE material = wa-material AND 
                    date_last_modified = wa-date_last_modified.
		count = count + 1.		
	ENDLOOP.
	IF count = 1.
		APPEND wa TO result_itab.
	ENDIF.
ENDLOOP.

This logic works for sure.

Thanks and best regards

Anand.

Edited by: Anand Shankar on Apr 24, 2009 12:24 PM

Edited by: Anand Shankar on Apr 24, 2009 12:25 PM

Read only

Former Member
0 Likes
1,902

Hi,

Create an internal table same as your current like Itab1 . Now process the loop for your current internal table [itab]. Take your value in another variable . and on change of matnr move the value in your itab1. eg

Loop at itab.

lmatnr = itab-matnr .

On change of itab-matnr.

itab1-matnr = lmatnr .

modify itab1.

clear lmatnr.

endon.

endloop.

Regards,

Himanshu

Read only

Former Member
0 Likes
1,902

Hi,

You have to first SORT your internal table

according to the material field then use statement,

DELETE ADJACENT DUPLICATES FROM INTERNAL TABLE

By this all the unique entries will be left in the internal table.

Hope it helps

Regards

Mansi

Read only

Former Member
0 Likes
1,902
sort it_tab by material ascending date_modified descending.
delete adjacent duplicates from it_tab."Now the it_tab has the unique and latest modified materials
Read only

Former Member
0 Likes
1,902

Hi Sonu,

The main task is to move the contents of the one internal table to another with some condition.

First sort and delete the duplicate entries from the First Internal table like below :

sort it_tab by material ascending date_modified descending.

delete adjacent duplicates from it_tab.

Then move that Internal table contents to another internal table.

Define another internal table with the same structure as you have first internal table and then

Second Step :

it_itab1 = it_itab.
If you are using seperate Header line and Body then you can do like below : 
       
       it_itab1[] = it_itab[].

This will fix the issue.

Please let me know if you need any further explonation.

Regards,

Kittu

Edited by: Kittu on Apr 24, 2009 12:21 PM