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

Comparing two structures

Former Member
0 Likes
910

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
Read only

Former Member
0 Likes
823

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

Read only

awin_prabhu
Active Contributor
0 Likes
823

Just do,

IF S1 = S2.

....

ENDIF.

Read only

Former Member
0 Likes
823

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

Read only

Former Member
0 Likes
823

This message was moderated.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
823

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

Read only

Former Member
0 Likes
823

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

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