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: 

How to compare ABAP Structures and display differences

majcon
Active Participant
0 Kudos
9,175

Hi Experts,

I´m searching for the possibility to compare two deep ABAP Structures (same structure) and to display the differences within the structures.

Is there any hint for this Problem?

I found in the Debugger the possibility to compare two structures, but I couldn´t figure out which Functions or classes are used in the Debugger

Maybe you could make an suggestion where to look or maybe it exists an Service-Class which analyzed the Differences?

Thanks for your Help!

Cheers,

Damir

1 ACCEPTED SOLUTION

majcon
Active Participant
0 Kudos
2,697

Hi,

here are my findings which helped me to go in the right direction:

1) The Debugger uses the class CL_TPDA_TOOL_DIFF for analyzing differences. Look at the Method DIFF_VARS

2) The ABAP Unit Framework has implemented comparions for different Data-Types, also for Deep-Structures.

The class CL_ABAP_UNIT_ASSERT has to local Helper-classes LCL_DIFF and LCL_CHECK which could be adopted for an custom-made compare. The Results are stored in the object master_message which is an Reference of TYPE CL_AUNIT_FAILURE_ASSERT in the Attribute F_ANALYSIS (Table with Results)

Cheers,

Damir

18 REPLIES 18

former_member195270
Active Participant
0 Kudos
2,697

used function module ISM_STRUCTURE_COMPARE .

0 Kudos
2,697

Hi Abdullah,

thanks for the info, but the FM doesn´t exist on my System... (SAP NW7.03 Trial Version)

Best regards,

Damir

Former Member
0 Kudos
2,697

Hi Damir,

Can you refer to the below mentioned discussion.

http://scn.sap.com/thread/136001

Regards,

Santanu.

0 Kudos
2,697

Hi Santanu,

thanks for finding this discussion.

But this Topic is for normal structures, which are not deep. This doesn´t solve my Problem...

Regards,

Damir

Former Member
0 Kudos
2,697

Hi Damir,

                 u can use this FM: COMPARE_STRUCTURE_DATA

0 Kudos
2,697

Hi OmChandra,

sorry but on my System (SAP NW7.03 Trial-Version) the FM doesn´t exist...

Regards,

Damir

arindam_m
Active Contributor
0 Kudos
2,697

Hi, Please find the code for function module ISM_STRUCTURE_COMPARE .

  FUNCTION ISM_STRUCTURE_COMPARE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     REFERENCE(PS_STRUCTURE1) TYPE  ANY
*"     REFERENCE(PS_STRUCTURE2) TYPE  ANY
*"     REFERENCE(PV_STRUCTURE_TYPE) TYPE  DDOBJNAME
*"     REFERENCE(PT_EXCLUDED_DATAELEMENTS) TYPE  MASS_FIELDTAB
*"     REFERENCE(PV_KEY) TYPE  ANY
*"     REFERENCE(PV_ROW) TYPE  BAPIRET2-ROW OPTIONAL
*"  EXPORTING
*"     REFERENCE(PT_RETURN) TYPE  BAPIRET2_T
*"----------------------------------------------------------------------
* Daten deklarieren.
  DATA: LT_DFIES TYPE TABLE OF DFIES.
  DATA: LS_DFIES TYPE DFIES.
  DATA: LV_ACTUAL_FIELD TYPE SY-INDEX.
  DATA: LS_RETURN TYPE BAPIRET2.
  FIELD-SYMBOLS: <LS_STRUCTURE1> TYPE ANY.
  FIELD-SYMBOLS: <LV_FIELD1> TYPE ANY.
  FIELD-SYMBOLS: <LS_STRUCTURE2> TYPE ANY.
  FIELD-SYMBOLS: <LV_FIELD2> TYPE ANY.

* Daten initialisieren.
  REFRESH PT_RETURN.

* Prüfen, ob sich überhaupt ein Feld untrscheidet.
  CHECK PS_STRUCTURE1 <> PS_STRUCTURE2.

* Daten initialisieren.
  ASSIGN PS_STRUCTURE1 TO <LS_STRUCTURE1>
                           CASTING TYPE (PV_STRUCTURE_TYPE).
  ASSIGN PS_STRUCTURE2 TO <LS_STRUCTURE2>
                          CASTING TYPE (PV_STRUCTURE_TYPE).

* Feldkataloge bestimmen.
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
       EXPORTING
            TABNAME   = PV_STRUCTURE_TYPE
       TABLES
            DFIES_TAB = LT_DFIES.

  LOOP AT LT_DFIES INTO LS_DFIES.
    LV_ACTUAL_FIELD = SY-TABIX.
* Sicherstellen, daß das Datenelement nicht von der Prüfung ausgenommen
* ist.
    READ TABLE PT_EXCLUDED_DATAELEMENTS WITH KEY LS_DFIES-ROLLNAME
                                        TRANSPORTING NO FIELDS.
    CHECK SY-SUBRC <> 0.
    ASSIGN COMPONENT LV_ACTUAL_FIELD
                              OF STRUCTURE <LS_STRUCTURE1>
                              TO <LV_FIELD1>.
    ASSIGN COMPONENT LV_ACTUAL_FIELD
                              OF STRUCTURE <LS_STRUCTURE2>
                              TO <LV_FIELD2>.
    IF <LV_FIELD1> <> <LV_FIELD2>.
      IF 1 = 2. MESSAGE E766(JE) WITH 1 2 3 4. ENDIF.
*     Feld &1 Satz &2: &3 <> &4
      CONCATENATE PV_STRUCTURE_TYPE '-' LS_DFIES-FIELDNAME
                  INTO LS_RETURN-MESSAGE_V1.
      LS_RETURN-MESSAGE_V2 = PV_KEY.
      LS_RETURN-MESSAGE_V3 = <LV_FIELD1>.
      CONDENSE LS_RETURN-MESSAGE_V3.
      LS_RETURN-MESSAGE_V4 = <LV_FIELD2>.
      CONDENSE LS_RETURN-MESSAGE_V4.
      LS_RETURN-PARAMETER  = PV_STRUCTURE_TYPE.
      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
           EXPORTING
                TYPE      = CON_INFORMATION
                CL        = 'JE'
                NUMBER    = '766'
                PAR1      = LS_RETURN-MESSAGE_V1
                PAR2      = LS_RETURN-MESSAGE_V2
                PAR3      = LS_RETURN-MESSAGE_V3
                PAR4      = LS_RETURN-MESSAGE_V4
                PARAMETER = LS_RETURN-PARAMETER
                ROW       = PV_ROW
                FIELD     = LS_DFIES-FIELDNAME
           IMPORTING
                RETURN    = LS_RETURN.
      APPEND LS_RETURN TO PT_RETURN.
    ENDIF.
  ENDLOOP.

ENDFUNCTION.

In case you cant create Z-Function module check the FM 'DDIF_NAMETAB_GET' you will get the list of fields for structure.

Cheers,

Arindam

majcon
Active Participant
0 Kudos
2,697

Hi Arindam,

thanks for the Coding.

I´ve tried it out, but the FM only works for Table-Type, it is possible to set the ALL_TYPES = 'X' when calling the FM 'DDIF_NAMETAB_GET', then the Structure could be identified, but the algorithm work not for DEEP-Structures (Structures which inlucde normal Attributes, other Structures and also Tables)...

Regards,

Damir

fred_verheul
Active Contributor
0 Kudos
2,697

Hi Damir,

Just a thought: you could of course use recursion to code it yourself, using the code from COMPARE_STRUCTURE_DATA (or ISM_...) for the 'simple' case.

I'm sure that isn't what you're looking for, but might get you quicker where you want to be than waiting for the ultimate answer here (if it even exists).

Cheers, Fred

majcon
Active Participant
0 Kudos
2,697

Hi Fred,

that seem to be the next step ;-(

I fugured that someone has a similar Problem and used the Debbuger-Diff-Tool or something similar to solve the Problem...

Cheers,

Damir

majcon
Active Participant
0 Kudos
2,698

Hi,

here are my findings which helped me to go in the right direction:

1) The Debugger uses the class CL_TPDA_TOOL_DIFF for analyzing differences. Look at the Method DIFF_VARS

2) The ABAP Unit Framework has implemented comparions for different Data-Types, also for Deep-Structures.

The class CL_ABAP_UNIT_ASSERT has to local Helper-classes LCL_DIFF and LCL_CHECK which could be adopted for an custom-made compare. The Results are stored in the object master_message which is an Reference of TYPE CL_AUNIT_FAILURE_ASSERT in the Attribute F_ANALYSIS (Table with Results)

Cheers,

Damir

fred_verheul
Active Contributor
0 Kudos
2,697

Thanks for sharing the solution!

Former Member
0 Kudos
2,697

Hi!

I have a similar requirement of comparing two structures. Let me be more precise:

Structure 1 : TYPE VBAP

Structure 2: TYPE VBAP + some other fields

Can you please provide more details on how you used this in your code? How I can use it?

A code snippet would be better. I am not sure on how to go about it.

Please do!

Thanks anyway!

majcon
Active Participant
0 Kudos
2,697

Hi Sonia,

sorry but the Solution was made for an Framework for an important customer... so he would not be amused to find some details here ;-(

But If you look at the Function-Module that Arindam suggested, it could work quite well for you.

An idea is FIRST to move the Second Structure (VBAP+some additional Fields) to an VBAP structure and SECOND to compare both VBAP structures...

Best regards,

Damir

0 Kudos
2,697

Hi Damir,

     As you mention : 

here are my findings which helped me to go in the right direction:

1) The Debugger uses the class CL_TPDA_TOOL_DIFF for analyzing differences. Look at the MethodDIFF_VARS

2) The ABAP Unit Framework has implemented comparions for different Data-Types, also for Deep-Structures.

The class CL_ABAP_UNIT_ASSERT has to local Helper-classes LCL_DIFF and LCL_CHECK which could be adopted for an custom-made compare. The Results are stored in the object master_message which is an Reference of TYPE CL_AUNIT_FAILURE_ASSERT in the Attribute F_ANALYSIS (Table with Results)

     Do you find out how to compare the two internal table both their structure and it's data ? I hope you can share your experience. Thanks so much.

majcon
Active Participant
0 Kudos
2,697

Hi Zhang,

I could remember, that all things which you need are in the ABAP Unit Framework... Also the Analysis for different Data Values!

Sorry, but I couldn´t give more explicit tips, because I´m supporting now an another Customer and I have no access on the code-basis ;-(

I hope this help you?

Regards,

Damir

0 Kudos
2,697

Hi Majer,

     Thanks for your sincerely answer!  about this ABAP Unit Framework , how do I find what I need ? 

vonglan
Active Participant
0 Kudos
2,523

For anyone wondering how to access CL_TPDA_TOOL_DIFF in the debugger:

Method 1:

Go to the „Diff“ register card (tab).

Method 2:

Use the „Variable Fast Display“ window/tool.

Add both variables (can be anything, e.g. tables) to the variable list.

Mark them (selection column).

Press the comparison icon („Start comparison“).