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: 

ti identify discrepancies in internal table data

Former Member
0 Kudos

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>

14 REPLIES 14

Former Member
0 Kudos

Use DELETE <table> comparing PODTD Contractaccount

Former Member
0 Kudos

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

0 Kudos

Hi all,

Please help me..to resolve the issue...

Thanks...

0 Kudos

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.

0 Kudos

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.

0 Kudos

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....

venkata_ramisetti
Active Contributor
0 Kudos

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.

0 Kudos

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????

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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,

0 Kudos

Rose,

Did u tried my code or the one which Naren sent/

Former Member
0 Kudos

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