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

Logic required

Former Member
0 Likes
1,132

i have 2 internal table. itab and itab1

itab1

material1 material2 qty

aaa 123 1

aaa 456 3

itab2

material1 material2 material3 values

aaa 123 xyz 1a

aaa 123 x1y1 2b

aaa 123 x2z2 1a

bbb 456 abc 4g

ddd 789 pqr 2g

ddd 789 lmn 5g

ddd 789 1bc 7h

i need to compare both the internal tables with material1 and material2, In the 2nd internal table the field material2's records comes three or more times i need to remove those records from the internal tabel and append the correct records into another table.

How to add with out this values into another internal table.

From the above example i need to remove aaa and ddd from the internal and append only bbb from here to itab3.

any one help this?

Mohana

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,108

Hi Mohana,

do sumthing like this:

Sort itab_1 with by field1, field2.

Loop at itab_1 into wa_1.

  count = count + 1.
" if you want to check some condition with itab_2 use a READ statement & check the same
  At end of field1.
" if you want combination of field1 & field2 than use 'AT END OF FIELD2'
    If count lt 3.
      Append wa1 to itab3.
      Clear count.
    Endif.    
  Endat.  
Endloop.

With luck,

Pritam.

Edited by: Pritam Ghosh on Mar 23, 2009 8:57 AM

11 REPLIES 11
Read only

Former Member
0 Likes
1,108

hi,

use

DELETE ADJACENT DUPLICATE

on both the internal table..

this remove al the duplicate records from both the internal table after that you append left value

in the third internal table...

hope this help you

Regards

Ritesh J

Read only

Former Member
0 Likes
1,108

Hi Mohana,

Loop through ITAB2 with WHERE Condition and move the value to other internal table.. or

u can check and delete from ITAB2 without deleting.

to move to other.

loop at itab2 where fld1 = 'value ' and fld2 = 'value '.

itab3 = itab2.

append itab3.

clear itab3.

endloop.

to delete it from itab2.

loop at itab2.

if fld1 ne 'value' and fld2 ne 'value'.

delete itabe2.

endif.

endloop.

Hope this helps u.

Guru

Read only

awin_prabhu
Active Contributor
0 Likes
1,108

Hi friend,

Use like below in itab2.

DELETE ADJACENT DUPLICATES FROM itab2 comparing material1 material2.

Thanks..

Read only

Former Member
0 Likes
1,108

loop at itab1 into wa_itab1.

read table itab2 into wa_itab2

where wa_itab2-mat1 = wa_itab1-mat1 and wa_itab2-mat2 = wa_itab1-mat2.

IF SY-SUBRC NE 0.

MOVE-CORRESPONDING wa_itab2 to wa_itab3.

APPEND WA_ITAB3 TO ITAB3.

ENDIF.

endloop .

HOPETHIS WILL HELP U.

Read only

Former Member
0 Likes
1,108

i have one internal table itab with below records.

fld1 fld2 fld3

zzz 784 231

zzz 784 597

AAA 111 BBB

AAA 111 CCC

AAA 111 DDD

BBB 222 xyz

BBB 222 pqr

BBB 222 123

BBB 222 478

BBB 222 zqr

ggg 123 879

CCC 777 kkk

CCC 777 qwi

CCC 777 dsf

CCC 777 qwe

my requirement is i need to check the field fld1 and fld2, if the values comes more than 3times i need to remove the records, i want to append the correct records into another internal table.

the above case i need to append 'ggg' and 'zzz' rows only.

Anyone pls suggest the logic.

Read only

0 Likes
1,108

Just in your words tell what is the final o/p you are expecting from your internal table ..

give the output for the below..

fld1 fld2 fld3

zzz 784 231

zzz 784 597

AAA 111 BBB

AAA 111 CCC

AAA 111 DDD

BBB 222 xyz

BBB 222 pqr

BBB 222 123

BBB 222 478

BBB 222 zqr

ggg 123 879

CCC 777 kkk

CCC 777 qwi

CCC 777 dsf

CCC 777 qwe

is it the occurance of fld1 & fld2 thrice or fld1 3 times sinlge is enough to discard the entry ?

AAA 111 BBB

AAA 121 CCC " check hte change

AAA 111 DDD

AAA 111 BBB

ABA 111 CCC

AAA 111 DDD

in both the cases can we discard the entry ..

Br,

Vijay..

Read only

0 Likes
1,108

Hi,

My final output table will be like below

zzz 784 231

zzz 784 597

ggg 123 879

pls help this out.

Mohana

Read only

0 Likes
1,108

Apply this logic.

sort itab by 3 fields.

Loop at internal table.

var1 = field1.

count = count +1.

At new field 1

if count >3.

clear var1.

else.

move var1 to second internal table.

endif.

endloop.

Thanks & Regards.

Ruchi Tiwari

Read only

0 Likes
1,108

execute the code ..

REPORT ZEX14.

data : begin of itab occurs 0 ,

f1(4) type c,

f2(4) type c,

f3(4) type c,

end of itab.

DATA : GV_FLAG, GV_CNT TYPE I, GV_VAL(4) TYPE C.

ITAB-F1 = 'ZZZ'. ITAB-F2 = '784'. ITAB-F3 = '231'. APPEND ITAB.CLEAR ITAB.

ITAB-F1 = 'ZZZ'. ITAB-F2 = '784'. ITAB-F3 = '597'. APPEND ITAB.CLEAR ITAB.

ITAB-F1 = 'AAA'. ITAB-F2 = '111'. ITAB-F3 = 'BBB'. APPEND ITAB.CLEAR ITAB.

ITAB-F1 = 'AAA'. ITAB-F2 = '111'. ITAB-F3 = 'BBB'. APPEND ITAB.CLEAR ITAB.

ITAB-F1 = 'AAA'. ITAB-F2 = '111'. ITAB-F3 = 'BBB'. APPEND ITAB.CLEAR ITAB.

SORT ITAB BY F1 F2.

LOOP AT ITAB.

AT NEW F1.

GV_FLAG = 'X'.

ENDAT.

IF GV_FLAG = 'X'.

GV_CNT = GV_CNT + 1.

ENDIF.

AT END OF F1.

IF GV_CNT GE 3.

DELETE ITAB WHERE F1 = ITAB-F1.

ENDIF.

CLEAR : GV_FLAG, GV_CNT.

ENDAT.

ENDLOOP.

LOOP AT ITAB.

WRITE:/ ITAB-F1, ITAB-F2, ITAB-F3.

ENDLOOP.

you can enhace the logic on fld2 just like f1 in the above.

br,

vijay.

Read only

0 Likes
1,108

Hi,

Use like this.

loop at it.

if prev_fld1 = it-fld1 and prev_fld2 = it-fld2.

count = count + 1.

if count GE 3.

delete it where fld1 = prev_fld1 and fld2 = prev_fld2 .

endif.

endif.

prev_fld1 = it-fld1.

prev_fld2 = it-fld2.

endloop.

Read only

Former Member
0 Likes
1,109

Hi Mohana,

do sumthing like this:

Sort itab_1 with by field1, field2.

Loop at itab_1 into wa_1.

  count = count + 1.
" if you want to check some condition with itab_2 use a READ statement & check the same
  At end of field1.
" if you want combination of field1 & field2 than use 'AT END OF FIELD2'
    If count lt 3.
      Append wa1 to itab3.
      Clear count.
    Endif.    
  Endat.  
Endloop.

With luck,

Pritam.

Edited by: Pritam Ghosh on Mar 23, 2009 8:57 AM