Skip to Content

Comparing workareas excluding some specific fields

Hi all gurus,

a silly question, I know, anyway: in my requirement I have to compare different workareas in a loop cycle with a model workarea. The aim is to identify if a workarea in a loop differs from the model workarea except for some specific fields.

In example; the workarea A has 100 fields, and I assume that this workarea is equal to the model one (B) if all the fields in A contain the same value that corrisponding field have in B except for fields 'guid' and 'p_guid', which can contain different values.

So, A is EQ to B if the other 98 fields are filled with the same values.

Actually I can build a sequence of comparing condition:

IF A-field1 EQ B-field1 AND A-field2 EQ B-field2 ...

that's quite time-wasting and I wonder if there's a better solution to compare in the above described way.... a sort of exclusion for the compare operation maybe?

Sorry, I get that this is probably a very basic question, anyway I searched a bit without results.

Thanks in advance.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 06, 2011 at 09:40 AM

    If you could change the definition of data type then this comparision can be done in single statement.

    See example below.

    TYPES : BEGIN OF ty_d ,
              col01 TYPE char01 ,
              col02 TYPE char01 ,
              col98 TYPE char01 ,
            END OF ty_d .
    
    TYPES : BEGIN OF ty_dd .
    INCLUDE TYPE ty_d AS d .    "this will enable to refer all COL01.. COL98 by name 'd'
    TYPES : guiid TYPE char05 ,
    END OF ty_dd .
    
    
    DATA : ls_dd1 TYPE ty_dd ,
           ls_dd2 TYPE ty_dd .
    
    ls_dd1-col01 = 'A' .
    ls_dd1-col02 = 'B' .
    ls_dd1-col98 = 'C' .
    
    ls_dd2-col01 = 'A' .
    ls_dd2-col02 = 'B' .
    ls_dd2-col98 = 'C' .
    
    IF ls_dd1-d = ls_dd2-d .
      WRITE 'EQUAL' .
    ELSE.
      WRITE 'NOT EQUAL'.
    ENDIF.
    
    ls_dd2-col01 = 'D' .
    
    IF ls_dd1-d = ls_dd2-d .
      WRITE / 'EQUAL' .
    ELSE.
      WRITE / 'NOT EQUAL'.
    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

    • Thanks Pawan,

      Actually I "workarounded" in this way: since I'm dealing with workareas variables that can be modified, I simply clear the two fields I don't want to be relevant in comparison. This is a simple operation and meets my desiderata; I was anyway looking for an alternative abap construct to build a sort of "exclusion list" of field involved in a compare operation.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.