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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

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' .
    ls_dd2-col01 = 'D' .
    IF ls_dd1-d = ls_dd2-d .
      WRITE / 'EQUAL' .
      WRITE / 'NOT EQUAL'.

    Add 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.