2006 Nov 21 7:57 AM
hi everyone
i have 2 internal tables: itab and itrans
itrans has the fields tabname, fieldname and it always contains the data
tabname fieldname value
FEBKO ABSND
FEBKO AZDAT
FEBEP KFMOD
FEBEP KWBTR
FEBEP PAKTO
and the table itab has the fields
kfmod
kwbtr
pakto
absnd
azdat
now i have to compare the lines in the table itab with those in the table itrans
with the corresponding values i.e
the table itrans should be read in order as above and checked in table itab if the corresponding entry is not null, if the entry is null, the next record in the table itrans should be compared
we compare when itrans-fieldname= ABSND, with itab-absnd,
if itab-absnd is null, move that line to another table
if its not null, continue comparing
else
compare when itrans-fieldname = AZDAT, with itab-azdat
if itab-azdat is null, move to anothe rtable
else compare with the next record in table itrans
i really dont have an idea how to make this comparion in ABAP, can sombody help me out plz?
2006 Nov 21 8:08 AM
Hi,
The best way is using the ASSIGN COMPONENT OF... statement.
For example,
field-symbols:
<itrans> like line of itrans,
<field> type any.
loop at itrans assigning <itrans>.
assign component <itrans>-fieldname of structure <itrans> to <field>.
if sy-subrc = 0.
if <field> is initial.
Do something here...
endif.
endif.
endloop.
I didn't syntax check the code above, etc but that's pretty much what you'll need to do.
MJ
hi everyone
i have 2 internal tables: itab and itrans
itrans has the fields tabname, fieldname and it always contains the data
tabname fieldname value
FEBKO ABSND
FEBKO AZDAT
FEBEP KFMOD
FEBEP KWBTR
FEBEP PAKTO
and the table itab has the fields
kfmod
kwbtr
pakto
absnd
azdat
now i have to compare the lines in the table itab with those in the table itrans
with the corresponding values i.e
the table itrans should be read in order as above and checked in table itab if the corresponding entry is not null, if the entry is null, the next record in the table itrans should be compared
we compare when itrans-fieldname= ABSND, with itab-absnd,
if itab-absnd is null, move that line to another table
if its not null, continue comparing
else
compare when itrans-fieldname = AZDAT, with itab-azdat
if itab-azdat is null, move to anothe rtable
else compare with the next record in table itrans
i really dont have an idea how to make this comparion in ABAP, can sombody help me out plz?
2006 Nov 21 8:02 AM
TRY THIS.
LOOP AT ITRANS.
READ TABLE ITAB WITH KEY FIELDNAME = ITRANS-FIELDNAME.
IF SY-SUBRC NE 0.
< YOUR CONDITION OR MOVE TO ANOTHER TABLE>
ENDIF.
ENDLOOP.
SHIBA PRASAD DUTTA
2006 Nov 21 8:02 AM
Hi,
check this sample prog
data:begin of itab1 occurs 0,
f1(10) type c,
end of itab1.
data:begin of itab2 occurs 0,
f1(10) type c,
end of itab2.
data:begin of itab3 occurs 0,
f1(10) type c,
end of itab3.
itab1-f1 = 'abc'.
append itab1.
itab2-f1 = 'abc'.
append itab2.
if itab1[] = itab2[].
itab3[] = itab1[].
else.
write:/ 'tables are not same'. (or)
message e000(zz) with 'tables are not same'.
endif.
loop at itab3.
write:/ itab3-f1.
endloop.OR
LOOP AT t_1.
READ TABLE t_2 WITH KEY f1 = t_1-f1
f2 = t_1-f2.
IF sy-subrc = 0.
MOVE-CORRESPONDING t_1 TO t_3.
APPEND t_3.
CLEAR t_3.
ELSE.
* raise error
ENDIF.Cheers
VJ
2006 Nov 21 8:10 AM
no its not that
if a corresponding entry is not found, i have to compare the next record in itrans
for eg.
loop at itab
read table itrans with key fieldname = itab-absnd
if sy-subrc eq 0.
if itab-absnd is null
move to another table
else
***i need to compare the next record in table itrans****and this is where i dnt know how to proceed
i need to compare itrans-fieldname with the remaining records in table itab
endif.
endloop.
2006 Nov 21 8:08 AM
Hi,
The best way is using the ASSIGN COMPONENT OF... statement.
For example,
field-symbols:
<itrans> like line of itrans,
<field> type any.
loop at itrans assigning <itrans>.
assign component <itrans>-fieldname of structure <itrans> to <field>.
if sy-subrc = 0.
if <field> is initial.
Do something here...
endif.
endif.
endloop.
I didn't syntax check the code above, etc but that's pretty much what you'll need to do.
MJ
2006 Nov 21 8:12 AM
Hi,
create a table itab1 which is of same structure as itab.
loop at itab.
loop at itrans.
case itrans-fieldname.
when 'ABSND'.
if itab-absnd eqspace.
move-corresponding itab to itab1.
append itab1.
exit.
endif.
when 'AZDAT'.
if itab-azdat eq space.
move-corresponding itab to itab1.
append itab1.
exit.
endif.
..
endcase.
endloop.
endloop.
Now your itab1 contains the required entries.
2006 Nov 21 9:24 AM
hi anjali,
check out this code,
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.
IF ITAB GT JTAB.
<< ANY OPERATION>>
ENDIF.
now in ur case if all the records are not null then do nothing else shift to another table
simple steps:-
1. transfer ur itab table into a new internal table which has the same structure as itrans.
2. now sort the both tables (itans and new internal table) with unique key fields(i.e. no
repeated values in the table).
3. now compare both the tables with 'eq' operator
if equals then do nothing ( or whatelse u want to do)
else move the records into another table.
Reward me with the points if u find answer helpful to u.
Regards,
Vikram dev
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |