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

How to compare two similar complex structures generically?

Former Member
0 Likes
773

Hi all,

I have a problem. I want to write a function module (or method) which imports two similar complex structures. Inside the module, I want to compare every field of every sub-structure and fill some table. How can I do this generically(meaning I do not know the type of the complex structure imported into the module)?

e.g. the module imports bus_ei_extern1 and bus_ei_extern2 structures. These structures have sub-structures like central_data, address etc. These sub-structures have fields inside that i want to compare.

Thanks in advance for your help

3 REPLIES 3
Read only

former_member186741
Active Contributor
0 Likes
570

have a look at abap RADVVTB2 which is used by the dictionary 'compare versions' utility.

Read only

0 Likes
570

Hi Neil,

I do not want to compare the structures themselves (because they will be same for sure), but the values of the fields in the sub-structures.

eg. consider two complex structures st1 and st2

they both have sub-structure 'central' which has fields name1, name2 and name3.

st1

central

name1 = 'abc'

name2 = 'xyz'

name3 = 'pqr'

st2

central

name1 = 'abc'

name2 = 'mno'

name3 = 'pqr'

in the above two structure, name2 field is unequal. I somehow first want to find out the sub-structures of st1 and st2 (which is central) and fields in the substructure and finally compare them.

Message was edited by: Vikram Nagendra

Read only

0 Likes
570

you can discover the fields belonging to a structure by using a variant of describe:

eg,

data td TYPE sydes_desc.

*.. get attributes of component field

DESCRIBE FIELD <field> INTO td.

The structure is quite complex but have a play around in debug and it may become clear.

Then you'd need to loop at the components of the structures and make comparisons.

something like:

DO.

*... work through all structure's components...

ASSIGN COMPONENT sy-index OF STRUCTURE <in_content> TO <field>.

IF sy-subrc <> 0.

*... exit when reaching the end of components

EXIT.

ENDIF.

enddo.