2007 Jul 24 11:08 AM
Dear all,
I have two internal table with same structure but different records.
i want to set a flag if records are different of internal table.
data : itab1 like mara occurs 0 with header line.
data : itab2 like itab occurs 0 with header line.
itab2[] = itab1[].
now suppose i make changes in itab1 .
same structure but different records... what will be answer.
********Point is assured.
2007 Jul 24 12:00 PM
Hi,
i think that you will have to do that in a loop like this :
data:BEGIN OF itab1 OCCURS 10,
bukrs LIKE bkpf-bukrs,
belnr like bkpf-belnr,
gjahr like bkpf-gjahr,
end of itab1.
data:BEGIN OF itab2 OCCURS 10,
bukrs LIKE bkpf-bukrs,
belnr like bkpf-belnr,
gjahr like bkpf-gjahr,
end of itab2.
data:wa_2 like itab2,
v_count2 TYPE i,
v_index TYPE i,
wa_1 like itab1,
v_count1 TYPE i.
move 'BE01' to wa_1-bukrs.
move '01' to wa_1-belnr.
move '2006' to wa_1-gjahr.
append wa_1 to itab1.
move 'BE01' to wa_1-bukrs.
move '02' to wa_1-belnr.
move '2006' to wa_1-gjahr.
append wa_1 to itab1.
move 'BE01' to wa_1-bukrs.
move '03' to wa_1-belnr.
move '2006' to wa_1-gjahr.
append wa_1 to itab1.
move 'BE02' to wa_2-bukrs.
move '01' to wa_2-belnr.
move '2006' to wa_2-gjahr.
append wa_2 to itab2.
move 'BE01' to wa_2-bukrs.
move '02' to wa_2-belnr.
move '2006' to wa_2-gjahr.
append wa_2 to itab2.
move 'BE01' to wa_2-bukrs.
move '03' to wa_2-belnr.
move '2006' to wa_2-gjahr.
append wa_2 to itab2.
sort itab1 by bukrs belnr gjahr.
sort itab2 by bukrs belnr gjahr.
DESCRIBE TABLE itab1 LINES v_count1.
DESCRIBE TABLE itab2 LINES v_count2.
if v_count1 = v_count2.
loop at itab1 into wa_1.
v_index = sy-tabix.
read TABLE itab2 INTO wa_2 INDEX v_index.
if wa_1 <> wa_2.
write:'tables not similar!!'.
exit.
ENDIF.
if v_index = v_count1.
write:'tables similar!!'.
ENDIF.
ENDLOOP.
else.
write:'tables not similar!!'.
ENDIF.
Regards,
Sooness
Dear all,
I have two internal table with same structure but different records.
i want to set a flag if records are different of internal table.
data : itab1 like mara occurs 0 with header line.
data : itab2 like itab occurs 0 with header line.
itab2[] = itab1[].
now suppose i make changes in itab1 .
same structure but different records... what will be answer.
********Point is assured.
2007 Jul 24 11:10 AM
hi,
If the data is same u can use
itab1[] = itab2[].
If it is different then u can use MOVE.
2007 Jul 24 11:10 AM
Hi,
if not itab1[] = itab2[].
do something
endif.
Reward points if helpful.
Regards.
Srikanta Gope
2007 Jul 24 11:10 AM
IF itab2[] NE itab1[].
"Records are different
ENDIF.
Or am I looking at it too simply?
2007 Jul 24 11:11 AM
U can compare 2 internal tabs
usining
If itab1[] = itab2[].
message...
endif.
Reward if useful
2007 Jul 24 11:12 AM
hi,
firstyl if u use itab2[] = itab1[] then u are assigning all the values of one internal tabe to another.
both will contain the same records
u can loop one internal table and corresponding read the other internal table using read statement with key.
loop at itab.
read table itab2 with <key> = itab-<key>.
if sy-subrc = 0.
ur code
endif.
endloop.
reward points plz
2007 Jul 24 11:13 AM
Hi,
If u want to compare all fields,
for matching purpose,
then we can do like this.
report abc.
data : a like t001 occurs 0 with header line.
data : b like t001 occurs 0 with header line.
loop at a.
LOOP AT B.
IF A = B.
WRITE 😕 'SAME'.
ENDIF.
endloop.
ENDLOOP.
Regards
2007 Jul 24 11:14 AM
Wow - You've gotta love SDN! 4 answers within 3 minutes of the question being asked!
2007 Jul 24 11:14 AM
Hope this will help u..
Comparing Internal Tables
Like other data objects, you can use internal tables as operands in logical expressions.
.... <itab1> <operator> <itab2> ...
For <operator>, all operators listed in the table in Comparisons Between Data Types can be used (EQ, =, NE, <>, ><, GE, >=, LE, <=, GT, >, LT, <).
If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets ([ ]) after the table name.
The first criterion for comparing internal tables is the number of lines they contain. The more lines an internal table contains, the larger it is. If two internal tables contain the same number of lines, they are compared line by line, component by component. If components of the table lines are themselves internal tables, they are compared recursively. If you are testing internal tables for anything other than equality, the comparison stops when it reaches the first pair of components that are unequal, and returns the corresponding result.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA: ITAB LIKE TABLE OF LINE,
JTAB LIKE TABLE OF LINE.
DO 3 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
MOVE ITAB TO JTAB.
LINE-COL1 = 10. LINE-COL2 = 20.
APPEND LINE TO ITAB.
IF ITAB GT JTAB.
WRITE / 'ITAB GT JTAB'.
ENDIF.
APPEND LINE TO JTAB.
IF ITAB EQ JTAB.
WRITE / 'ITAB EQ JTAB'.
ENDIF.
LINE-COL1 = 30. LINE-COL2 = 80.
APPEND LINE TO ITAB.
IF JTAB LE ITAB.
WRITE / 'JTAB LE ITAB'.
ENDIF.
LINE-COL1 = 50. LINE-COL2 = 60.
APPEND LINE TO JTAB.
IF ITAB NE JTAB.
WRITE / 'ITAB NE JTAB'.
ENDIF.
IF ITAB LT JTAB.
WRITE / 'ITAB LT JTAB'.
ENDIF.
The output is:
ITAB GT JTAB
ITAB EQ JTAB
JTAB LE ITAB
ITAB NE JTAB
ITAB LT JTAB
This example creates two standard tables, ITAB and JTAB. ITAB is filled with 3 lines and copied to JTAB. Then, another line is appended to ITAB and the first logical expression tests whether ITAB is greater than JTAB. After appending the same line to JTAB, the second logical expression tests whether both tables are equal. Then, another line is appended to ITAB and the third logical expressions tests whether JTAB is less than or equal to ITAB. Next, another line is appended to JTAB. Its contents are unequal to the contents of the last line of ITAB. The next logical expressions test whether ITAB is not equal to JTAB. The first table field whose contents are different in ITAB and JTAB is COL1 in the last line of the table: 30 in ITAB and 50 in JTAB. Therefore, in the last logical expression, ITAB is less than JTAB.
Reward if useful..
Regards
Prax
2007 Jul 24 11:18 AM
Hi,
i didn't understand your question well but you can do the following:
1) modify itab1 and make a read statement with all key fields i itab2.
if present then set flag .
2) modify itab1 .
then use modify itab2 where <b>key_field(s) = value(s) from itab1</b>
Regards,
Sooness
2007 Jul 24 11:21 AM
Hi,
this may help u:
*handling duplicates in Internal table:
******************************************
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.
This is my itab1 records:
f1 f2
101 1001
102 1001
103 1003
104 1004
105 1004
106 1004
107 1005
108 1005
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
Jogdand M B
2007 Jul 24 11:26 AM
Dear All ,
Thanks for your valuable support.
Just i want to compair records of two internal table which having same structure .
like
itab1 itab2 both having 3 records but different data.
itab1-name = 'AAA'. itab2-name = 'BBB'
itab1-age= 34. itab2-age = 35
itab1-salary = $1200. itab2-salary = $1400
how to compair ?
2007 Jul 24 12:06 PM
Hi,
U can use,
IF itab1[] EQ itab2[].
WRITE 😕 ''Two Tables are Similar'.
ENDIF.
Regards,
Padmam.
2007 Jul 24 12:00 PM
Hi,
i think that you will have to do that in a loop like this :
data:BEGIN OF itab1 OCCURS 10,
bukrs LIKE bkpf-bukrs,
belnr like bkpf-belnr,
gjahr like bkpf-gjahr,
end of itab1.
data:BEGIN OF itab2 OCCURS 10,
bukrs LIKE bkpf-bukrs,
belnr like bkpf-belnr,
gjahr like bkpf-gjahr,
end of itab2.
data:wa_2 like itab2,
v_count2 TYPE i,
v_index TYPE i,
wa_1 like itab1,
v_count1 TYPE i.
move 'BE01' to wa_1-bukrs.
move '01' to wa_1-belnr.
move '2006' to wa_1-gjahr.
append wa_1 to itab1.
move 'BE01' to wa_1-bukrs.
move '02' to wa_1-belnr.
move '2006' to wa_1-gjahr.
append wa_1 to itab1.
move 'BE01' to wa_1-bukrs.
move '03' to wa_1-belnr.
move '2006' to wa_1-gjahr.
append wa_1 to itab1.
move 'BE02' to wa_2-bukrs.
move '01' to wa_2-belnr.
move '2006' to wa_2-gjahr.
append wa_2 to itab2.
move 'BE01' to wa_2-bukrs.
move '02' to wa_2-belnr.
move '2006' to wa_2-gjahr.
append wa_2 to itab2.
move 'BE01' to wa_2-bukrs.
move '03' to wa_2-belnr.
move '2006' to wa_2-gjahr.
append wa_2 to itab2.
sort itab1 by bukrs belnr gjahr.
sort itab2 by bukrs belnr gjahr.
DESCRIBE TABLE itab1 LINES v_count1.
DESCRIBE TABLE itab2 LINES v_count2.
if v_count1 = v_count2.
loop at itab1 into wa_1.
v_index = sy-tabix.
read TABLE itab2 INTO wa_2 INDEX v_index.
if wa_1 <> wa_2.
write:'tables not similar!!'.
exit.
ENDIF.
if v_index = v_count1.
write:'tables similar!!'.
ENDIF.
ENDLOOP.
else.
write:'tables not similar!!'.
ENDIF.
Regards,
Sooness
2007 Jul 24 1:39 PM
Thanks to all,
my problem has been solved.
Point has been given.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |