2008 Aug 13 10:51 AM
Hi,
How can I compare the lines one by one in internal table.
suppose I have 10 lines in my itab.I want to compare 1 lin wih the other line.
2008 Aug 13 10:55 AM
Hi,
Move the contents of that Internal table into another Internal table and then compare that two Internal tables.
Raghav
2008 Aug 13 10:57 AM
HI
data :
i type i value 1.
READ itab into wa1.....INDEX i.
READ itab..into wa2....INDEX i+1.
compare wa1 and wa2
Regards
Pavan
2008 Aug 13 10:58 AM
Hello,
Can you elaborate ur requirement in detail:
Try this:
LOOP AT ITAB INTO WA_CURRENT.
IF SY-INDEX = 1. "First Loop Pass
WA_PREV = WA_CURRENT.
ELSE.
<Compare WA_PREV & WA_CURRENT>
CLEAR WA_PREV.
ENDIF.
WA_PREV = WA_CURRENT.
ENDLOOP.
Hope this is useful.
BR,
Suhas
2008 Aug 13 11:04 AM
hi,
I want to compare line by line with some particular field and want to condense all the details of it in the output with some calculation........
2008 Aug 13 11:09 AM
hi,
use this.
LOOP AT itab1 INTO wa_itab1.
MOVE-CORRESPONDING wa_itab1 TO wa_itab2.
IF <condition here>
COLLECT wa_itab2 INTO itab2.
ELSE.
APPEND wa_itab2 INTO itab2.
ENDIF.
CLEAR wa_itab2.
ENDLOOP.
regards,
Peter
2008 Aug 13 11:11 AM
Hello,
I am sorry plz tell what comparision you want to make.
LOOP AT ITAB INTO WA_CURRENT.
IF SY-INDEX = 1. "First Loop Pass
WA_PREV = WA_CURRENT.
ELSE.
WA_PREV-FIELD <Comparision Condition, this is specific to your requirement> WA_CURRENT-FIELD
IF SUCCESS.
CONDENSE WA_CURRENT.
* Do Calculation
APPEND WA_CURRENT TO IT_OUTPUT.
ENDIF.
CLEAR WA_PREV.
ENDIF.
WA_PREV = WA_CURRENT.
ENDLOOP.
You can try LOOP control stmts. But before suggesting that i will like to know exactly what comparision u want 2 make.
BR,
Suhas
Edited by: Suhas Saha on Aug 13, 2008 12:13 PM
2008 Aug 13 11:12 AM
>
> hi,
> I want to compare line by line with some particular field and want to condense all the details of it in the output with some calculation........
Use COntrol Break statements like ON CHANGE OF or AT NEW.
and in that you can do the calculations.
pk
2008 Aug 13 11:17 AM
HI,
TRY TO CODE LIKE THIS
loop at itab into wa1.
read table jtab into wa2 .....INDEX sy-index.
IF itab GT jtab.
WRITE / 'ITAB GT JTAB'.
ELSEIF itab EQ jtab.
WRITE / 'ITAB EQ JTAB'.
ELSE.
WRITE / 'ITAB LT JTAB'.
ENDIF.
endloop.
2008 Aug 13 11:25 AM
Hi,
try this way-
describe table t_flight lines w_line.
w_index = w_line - 1.
do w_index times.
while w_line gt 0.
w_index1 = w_line - 1.
read table t_flight into fs_flight index w_line.
fs_flight1 = fs_flight.
read table t_flight into fs_flight index w_index1.
if fs_fligh1 = fs_flight.
write:"Records are same'.
endif.
Clear:
fs_flight1,
fs_flight.
subtract 1 from w_line.
endwhile. " WHILE w_line GT 0.
w_line = w_index + 1.
enddo. " DO w_index TIMES.
Regards,
Sujit
2008 Aug 13 11:54 AM
Hi,
Check the following syntax:
READ TABLE <itab> <key> INTO <wa> [COMPARING <f1> <f2> ...
|ALL FIELDS]
[TRANSPORTING <f1> <f2> ...
|ALL FIELDS
|NO FIELDS].
If you do not use the additions COMPARING or TRANSPORTING, the contents of the table line must be convertible into the data type of the work area <wa>. If you specify COMPARING or TRANSPORTING, the line type and work area must be compatible. You should always use a
work area that is compatible with the line type of the relevant internal table.
If you use the COMPARING addition, the specified table fields <fi> of the structured line type are compared with the corresponding fields of the work area before being transported. If you use the ALL FIELDS option, the system compares all components. If the system finds an entry with the specified key <key> and if the contents of the compared fields are the same, SY-SUBRC is set to 0. If the contents of the compared fields are not the same, it returns the value 2. If the system cannot find an entry, SY-SUBRC is set to 4. If the system finds an entry, it copies it into the target work area regardless of the result of the comparison.
If you use the TRANSPORTING addition, you can specify the table fields of the structured line type that you want to transport into the work area. If you specify ALL FIELDS without TRANSPORTING, the contents of all of the fields are transported. If you specify NO FIELDS, no fields are transported. In the latter case, the READ statement only fills the system fields SYSUBRC and SY-TABIX. Specifying the work area <wa> with TRANSPORTING NO FIELDS is unnecessary, and should be omitted.
In both additions, you can specify a field <fi> dynamically as the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is executed, it is ignored.
Regards,
Bhaskar