10-23-2006 7:21 PM
Hi all,
I do have data in internal table like this...
PODTD Instl Instl.type Premise ContractAccount
100 I1 ELED P1 C1
100 I2 ELES P1 C1
101 I3 ELED P2 C2
102 I4 ELES P2 C2.
I want to delete the records if PODTD are same for the same contract account.
only want to display different PODTD exist for the same contract in the report.
How can i do this check in internal tables? Please give me yours valuable guidance>......
Thanks.<b></b>
10-23-2006 7:26 PM
10-23-2006 7:27 PM
Hi
You can move the same data into another internal table with field structure having Contract Account, PODTD followed by other fields.
Now you can sort the new internal table by Contract Account and PODTD.
And, use Delete adjacent duplicates from itab2 comparing Contract Account PODTD.
Regards,
Raj
10-23-2006 8:00 PM
10-23-2006 8:28 PM
Hi Rose
Try this code:
Define 2 internal tables same as ur existing internal table (itab)
data: itab1 like itab occurs 0 with header line,
itab2 like itab occurs 0 with header line.
data: v_lines(05).
sort itab by ContractAccount PODTD
itab2[] = itab[].
loop at itab.
clear v_lines.
itab1[] = itab[].
read table itab2 with key PODTD = itab-PODTD
ContractAccount = itab-ContractAccount
binary search.
if sy-subrc eq 0.
delete itab1 where PODTD <> itab-PODTD OR
ContractAccount <> itab-ContractAccount.
describe table itab1 lines v_lines.
if v_lines gt '1'.
delete itab2 where PODTD = itab-PODTD AND
ContractAccount = itab-ContractAccount.
endif.
endif.
refresh itab1.
endloop.
You will get ur required data in itab2.
10-23-2006 8:30 PM
Sorry you will have to read itab2 with ContractAccount and then PODTD as we sorted itab (and itab2 is same as itab).
read table itab2 with key
ContractAccount = itab-ContractAccount
PODTD = itab-PODTD
binary search.
10-23-2006 8:54 PM
Hi,
Thankyou everybody, I need to find pair of records like
PODID INST INSTLTYPE PREMISE CONTRACTACCOUNT
100 I1 ELED P1 CA1
101 I2 ELED P2 CA2
100 I3 ELES P1 CA1
102 I4 ELES P2 CA2
Records maybe like ,from this I need to first collet the pair like
100 I1 ELED P1 CA1
100 I3 ELES P1 CA1 becasue each contact account have two installation type, One is Electric distribution(ELED), one for electric supply(ELES). I need to delete the above record from internal table.
I need to display this record into display.
101 I2 ELED p2 CA2
102 I4 ELES p2 CA2
How can i check this? If i do compare PODTD & contract account fields not showing correct data?
Help me please....
10-23-2006 7:30 PM
Hi,
If I understand your problem correctly, The following code you can use.
DELETE ADJACENT DUPLICATES FROM itab COMPARING PODTD CONTRACTACCOUNT.
The above statement will delete all records except the first record from the internal table ITAB if PODTD CONTRACTACCOUNT are same in other records.
Please let us know if my above code is not useful.
10-23-2006 7:45 PM
I want to display this pair of records in my report display, Just want to delete the pair of records if PODTD are same
101 I3 ELED P2 C2
102 I4 ELES P2 C2.
Can i use delete duplicates for this????
10-23-2006 8:03 PM
Hi
Yes you can use <b>delete adjacent duplicates comparing <keyfield1> <keyfield2></b>
If it is per Contract Account (i.e distinct PODTD)
then, Keyfield1 = Contract Account and Keyfield2 = PODTD.
Regards,
Raj
10-23-2006 8:05 PM
Hi,
For doing DELETE ADJACENT DUPLICATES you have to sort the internal table first.
SORT ITAB BY PODTD CONTRACT_ACCOUNT.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING PODTD CONTRACT_ACCOUNT.
Thanks,
Naren
10-23-2006 9:13 PM
Hi,
This is the output you want right??
100 I1 ELED P1 CA1
101 I2 ELED P2 CA2
102 I4 ELES P2 CA2
Then use SORT and DELETE ADJACENT DUPLICATES..As I mentioned above..
SORT ITAB BY PODTD CONTRACT_ACCOUNT.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING PODTD CONTRACT_ACCOUNT.
Thanks,
Naren
10-23-2006 9:21 PM
I want to delete both record which having same PODTD. I want the output as
101 I2 ELED P2 CA2
102 I4 ELES P2 CA2.
Thanks,
10-23-2006 10:59 PM
10-23-2006 9:32 PM
Hi,
Okay..Got it..Check this ..
Declare a temporary internal table with the same structure as your internal table that has the data..
DATA: ITAB_TEMP LIKE ITAB OCCURS 0 WITH HEADER LINE.
ITAB_TEMP[] = ITAB[].
DATA: V_TABIX TYPE SYTABIX.
LOOP AT ITAB_TEMP.
CLEAR: V_TABIX.
LOOP AT ITAB WHERE PODTD = ITAB_TEMP-PODTD
AND CONTRACT_ACCOUNT =
ITAB_TEMP-CONTRACT_ACCOUNT.
V_TABIX = V_TABIX + 1.
ENDLOOP.
IF V_TABIX > 1.
DELETE ITAB WHERE PODTD = ITAB_TEMP-PODTD
AND CONTRACT_ACCOUNT =
ITAB_TEMP-CONTRACT_ACCOUNT.
ENDIF.
ENDLOOP.
ITAB internal table will have the final values..
Hope this works..
Thanks,
Naren