Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Expressions and Functions for Conditions →  log_exp - Logical Expressions →  rel_exp - Comparison Expressions →  rel_exp - Comparison Rules 

rel_exp - Comparison of Structures

It is possible to compare structures with structures and to compare structures with elementary fields:

  • Compatible structures are compared on a component-by-component basis and any nested structures are resolved recursively. Two structures are equal if the content of their components matches. If two structures are not equal, the first unequal component pair determines the result of the comparison.
  • It is possible to compare incompatible structures and structures with elementary fields provided that the structures concerned are flat.
  • Comparisons between two flat structures require that their fragment views match for the length of the shorter structure. Before the comparison, the shorter structure is padded to the length of the longer structure. Here, all character-like components are padded with blanks and all other components with their type-dependent initial value. The comparison is then performed on a section-by-section basis according to the fragment view.
  • Comparisons between a flat structure and an elementary field are subject to the following rules:

    If the flat structure is character-like, it is handled in the comparison like an elementary field with the type c.

    If the flat structure is not just character-like, the elementary field must have the type c and the first fragment of the structure fragment view must be character-like and at least as long as the elementary field. If the elementary field is shorter than the structure, it is expanded to the length of the structure before the comparison is started and then handled implicitly like a structure. The character-like parts of the extension are padded with blanks and all other components are padded with their type-dependent initial value.

Other versions: 7.31 | 7.40 | 7.54


Example

The following comparison is true because the structure is handled like a field of type c with length 8.

TYPES: 
  BEGIN OF struc, 
    year  TYPE c LENGTH 4, 
    month TYPE c LENGTH 2, 
    day   TYPE c LENGTH 2, 
  END OF struc. 

DATA(date) = sy-datlo. 
DATA(struc) = VALUE struc( year  = date(4) 
                           month = date+4(2) 
                           day   = date+6(2) ). 

ASSERT date = struc.