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: 

Hi need help in a logic

Former Member
0 Kudos
129

Hi Group,

I have a req:

I have an itab where eg there are 2 fields in it and data is:

f1 f2

101 1001

102 1001

103 1003

104 1004

105 1004

106 1004

107 1005

108 1005

109 1006

Now I have to fetch data based on f2 where if my table have more than 2 entries of same value wrt f2 I have to fetch that value and place those data in other internal table

Hope you have understood my point.

Eagerly waiting for your answers, thanks all..

Varun.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
102

assume that 'itab' is the name of the internal table that holds the sample data that u've posted,

1.copy itab to a temporary table itab_temp

itab_temp[] = itab[].

2. use the following logic.

loop at itab.

clear w_count.

loop at itab_temp where f2 = itab-f2.

w_count = w_count + 1.

delete itab_temp.

endloop.

if w_count > 2.

append itab to itab_final.

endif.

endloop.

3. now the internal table 'itab_final' contains all the required values.

get back for more help in u find any issues.

10 REPLIES 10

Former Member
0 Kudos
102

Hi,

Try this command:

DELETE ADJACENT DUPLICATES FROM connection_tab comparint f1 f2 . 

Former Member
0 Kudos
102

Hi Varun,

U can use selct statement to select values from F2 and after selecting use

Delete adjacent duplicates from f2comparing f1

hope this will solve ur problem

Rewards if helpfull

Regards,

Pavan

Former Member
0 Kudos
102

Thank you for responding.

Could you please send me the code for the query which I have asked(Where I have provided the sample data)?

I didnt get regarding DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.

Please urgent.

Thanks in advance.

Varun.

0 Kudos
102

try this

Declare one more itab with f2 as first field and f1 as second field , say itab2

loop at itab1.
move-corresponding itab1 to itab2.
append itab2.
endloop.

delete adjacent duplicate from itab comparing f2.

loop at itab2.
  read table itab1 with key f2 eq itab2-f2.
   if sy-subrc eq 0.
      move-corresponding itab1 to itab2.
      append itab2.
   endif.
endloop.

now itab2 will contain the duplicate entries

Message was edited by:

Chandrasekhar Jagarlamudi

naveen1241
Participant
0 Kudos
102

with ur testdata.........

wht wud b the second internal table's data?

mention tht also to make ur req clear.

Regards,

Naveen

Former Member
0 Kudos
103

assume that 'itab' is the name of the internal table that holds the sample data that u've posted,

1.copy itab to a temporary table itab_temp

itab_temp[] = itab[].

2. use the following logic.

loop at itab.

clear w_count.

loop at itab_temp where f2 = itab-f2.

w_count = w_count + 1.

delete itab_temp.

endloop.

if w_count > 2.

append itab to itab_final.

endif.

endloop.

3. now the internal table 'itab_final' contains all the required values.

get back for more help in u find any issues.

0 Kudos
102

Hi Group,

I dont want to delete any duplicates, I want to make sure that all the entries which are there in itab1 with respect to f2 ie itab1-f2 which have more than 1 records which the same value that of itab1-f2 only those all should be pushed into a temp internal table.

In my question it should be that is my output should be like this:

This is my itab1 records:

f1 f2

101 1001

102 1001

103 1003

104 1004

105 1004

106 1004

107 1005

108 1005

109 1006

Now in any temp table the output should be:

f1 f2

101 1001

102 1001

104 1004

105 1004

106 1004

107 1005

108 1005

109 1006

Hope you would understand my query thanks.

Regards:

Varun.

0 Kudos
102

Hi,

data:itab1 like <ref_table>. occurs 0 with header line.

data:itab2 like <ref_table>. occurs 0 with header line.

data:wa like <ref_table>,num(2) type n.

loop at itab1 into wa.

clear num.

loop at itab1 where f2 = wa-f2.

num = num + 1.

endloop.

if num > 1.

move-corresponding wa to itab2.

append itab2.

endif.

endloop.

<b>reward if useful.</b>

rgds,

bharat.

Message was edited by:

Bharat Kalagara

Former Member
0 Kudos
102

Hi,

Most of the logics involve two loops. But here is a way to do it with one loop.

SORT itab1 BY f2.

DATA : lv_f2 TYPE xxx,

count TYPE i .

count = 0.

LOOP AT itab1 ASSIGNING <fs>.

IF <fs>-f2 <> lv_f2.

IF count = 1.

DELETE itab_temp WHERE f2 = lv_f2.

ENDIF.

APPEND <fs> to itab_temp.

count = 1.

lv_f2 = <fs>-f2.

ELSE.

count = count + 1.

ENDIF.

ENDLOOP.

Former Member
0 Kudos
102

Thank you all guys thanks for all your answers,

Bharat I truly appreciate your help, you understood my query.

Thank you ssooooo much.

God Bless.