Application Development 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: 

Comparing two structures

Former Member
0 Kudos

Hi all,

Can anyone let me know how to compare two structures ie., wheather all fields(sequence/datatypes) of <Structure1> are same as <Structure2>..

Cheers,

Rahul.

6 REPLIES 6

Former Member
0 Kudos

Hi there,

if you are comparing in some report program in debugging mode, then in the new sap debugger, we have a functionality to compare structures.... you can use that. ....

otherwise, compare the data types of the fields of the structures. If the data types are same , then the structures are identical . Also the number of fields shopuld also be the same.

Do get back if you need further help...

best regards,

Prem Sharma

awin_prabhu
Active Contributor
0 Kudos

Just do,

IF S1 = S2.

....

ENDIF.

Former Member
0 Kudos

Hi Rahul,

do below

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = wa_structure1
    CHANGING
      ct_fieldcat            = it_fieldcat1
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.


  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = wa_structure1
    CHANGING
      ct_fieldcat            = it_fieldcat2
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.


if it_fieldcat1[] = it_fieldcat2[].
,...success message
endif.

it works

Former Member
0 Kudos

This message was moderated.

0 Kudos

Hi,

Try the below code.

DATA: lo_obj TYPE REF TO CL_ABAP_STRUCTDESCR.
DATA: lt_comp1       TYPE cl_abap_structdescr=>component_table.
DATA: lt_comp2       TYPE cl_abap_structdescr=>component_table.

lo_obj  ?= cl_abap_structdescr=>describe_by_name( 'STRUC1_NAME' ).
lt_comp1 = lo_obj->get_components( ).

lo_obj  ?= cl_abap_structdescr=>describe_by_name( 'STRUC2_NAME' ).
lt_comp2 = lo_obj->get_components( ).

if lt_comp1 = lt_comp2.
endif.

Regards,

Sesh

Former Member
0 Kudos

Thanks for your answers, but I wanted to compare two structures of workareas(not values in it).

for ex: <WA1> = <WA2>...?