09-27-2010 12:13 PM
Hi Gurus,
Problem 1
I have 2 internal tables ITAB1 and ITAB2 that are copies of one another with 6 columns. (A, B, C, D, E, F)
Data in some columns for ITAB1 gets changed. I dont know which columns or where exactly the data is changed.
Is there a technique or a function module that returns me where the data between ITAB1 and ITAB2 has changed and then i can have the info on the changed data such as column that was changed and the row etc...
Problem 2
Is there a function module or a technique that allows me to read column names from an ITAB (as the itab is generated dynamically) and based on the names i can do further processing.....
Thnx
Salman
Edited by: Salman Akram on Sep 27, 2010 1:19 PM
09-27-2010 1:07 PM
1) I think the only resonable way is to compare each line. If there are not equal then compare the components as well and report those which differ
field-symbols: <line1> type any,
<line2> type any,
<comp1> type any,
<comp2> type any.
loop at itab1 assigning <line1>.
read table itab2 assigning <line2> index sy-tabix.
if sy-subrc = 0.
"compare lines - they are equall if al the fields are equal
if <line1> ne <line2>.
do.
assign component: sy-index of structure <line1> to <comp1>,
sy-index of structure <line2> to <comp2>.
if sy-subrc ne 0.
exit. "go check next line
else.
if <comp1> ne <comp2>.
"not equal
endif.
endif.
enddo.
endif.
endif.
endloop.
2) Yes, there are two techniques. One is by means of [GET_COMPONENT_LIST|;. The other one is using RTTI
data: lr_strdescr type ref to cl_abap_structdescr,
lr_tabdescr type ref to cl_abap_tabledescr,
it_components type cl_abap_structdescr=>COMPONENT_TABLE with header line.
lr_tabdescr ?= cl_abap_typedescr=>describe_by_data( itab1 ).
lr_strucdescr ?= lr_tabdescr->GET_TABLE_LINE_TYPE( ).
it_components = desc_struc->get_components( ).
loop at it_components.
"show all component names
write: it_components-name.
endloop.
Regards
Marcin
09-27-2010 1:07 PM
1) I think the only resonable way is to compare each line. If there are not equal then compare the components as well and report those which differ
field-symbols: <line1> type any,
<line2> type any,
<comp1> type any,
<comp2> type any.
loop at itab1 assigning <line1>.
read table itab2 assigning <line2> index sy-tabix.
if sy-subrc = 0.
"compare lines - they are equall if al the fields are equal
if <line1> ne <line2>.
do.
assign component: sy-index of structure <line1> to <comp1>,
sy-index of structure <line2> to <comp2>.
if sy-subrc ne 0.
exit. "go check next line
else.
if <comp1> ne <comp2>.
"not equal
endif.
endif.
enddo.
endif.
endif.
endloop.
2) Yes, there are two techniques. One is by means of [GET_COMPONENT_LIST|;. The other one is using RTTI
data: lr_strdescr type ref to cl_abap_structdescr,
lr_tabdescr type ref to cl_abap_tabledescr,
it_components type cl_abap_structdescr=>COMPONENT_TABLE with header line.
lr_tabdescr ?= cl_abap_typedescr=>describe_by_data( itab1 ).
lr_strucdescr ?= lr_tabdescr->GET_TABLE_LINE_TYPE( ).
it_components = desc_struc->get_components( ).
loop at it_components.
"show all component names
write: it_components-name.
endloop.
Regards
Marcin
09-27-2010 2:00 PM
awesome is the least way i can describe your response. so clear and exactly what i required. let me try it and wil come back with the news.....
thnxxxxxxx
09-27-2010 6:26 PM