/
(DV-2002) ERP Report - BADI comparator

(DV-2002) ERP Report - BADI comparator

When you execute the "Set comparison settings" step in the ERP Report Test Case, you are able to select "BADI Report Comparator" for the report comparator type setting. Test Case with this setting will not use standard Validate functionality to compare before and after image data but will call appropriate implementation of BAdI "/DVD/EQS_BADI_REP_COMP". This enables you to implement your own custom compare logic. This section describes basic information about implementing custom BAdI comparator class.

Implementation

To implement the custom comparator class, a new implementation for BAdI definition '/DVD/EQS_BADI_REP_COMP' must be created. Implementing class must implement "/DVD/EQS_IF_REP_BAPI" interface. Create implementation must be set to "Active" to take effect. Otherwise Validate default BAdI comparator implementation will be used. 


/DVD/EQS_IF_REP_BAPI Interface Description

  • Methods:
    • COMPARE_LINES - Receives a full line from before image and appropriate full line from after image to be compared. Exporting parameter EV_DIFFERENT must be set by implementation to decide if rows do match.
    • FULL_CONTROL_REQUESTED - must return value "X" or " ". If "X" is returned "COMPARE_DATA_PACKAGE" method will be used during comparison of data images. If " " is returned "COMPARE_LINES" method will be invoked during comparison of data images.
    • COMPARE_DATA_PACKAGE - Receives a table with data of before image and table with data of after image. Maximum size of the tables is defined by PACKAGE_SIZE* parameter. Implementation must take care of colorization of the result and must return EB_DIFFERENT with value "X" if any difference is found in the whole package . 

From the interface two main approaches of data comparison can be taken. 

Line by line custom comparison

If your implementation returns " " from the "FULL_CONTROL_REQUESTED" method, you only need to implement the "COMPARE_LINES" method. In this case your implementation will be called multiple times for each pair of before/after image rows. For this type of implementation other comparison settings: "Ignore TimeStamps", "Compare only table data" are not ignored and are handled by Validate outside of "COMPARE_LINES" method.

Table custom comparison.

If your implementation returns "X" from the "FULL_CONTROL_REQUESTED" method, you only need to implement the "COMPARE_DATA_PACKAGE" method. For this type of implementation other comparison settings: "Ignore TimeStamps", "Compare only table data" are ignored. Following example is the implementation for this comparison approach. 

Example implementation
 FIELD-SYMBOLS:
                 <ls_data>    TYPE /DVD/EQS_S_VALUE.

* Custom logic should be implemented here.
* CT_B_DATA - table contains rows from before image execution split to
*             74 character long parts
* CT_A_DATA - table contains rows from after image execution split to
*             74 character long parts

* This method might be called more then once. Number of invokes
* depends on Validate "REPORT_COMP_PCG" setting. This setting
* determinate maximum number of rows for one invocation of this method
* Default value is set to 10 000. If there will be 500 rows in image output
* this method will be called once. If there will be 12 000 rows this method
* will be called twice receiving 10 000 rows in first package and 2000
* rows in second invocation.

* Be aware that full spool line is split into rows of length 74
* you can use attribute of <ls_data> structure Y to determinate row
* and X to position. Data coming into method are always sorted by Y
* and X

* Own comparison logic should evaluate correctness of each row in both
* before and after images. If any of the row data is incorrect
* method should return EB_DIFFERENT = ABAP_TRUE. To colorize output in
* validate. I.e. set red color to incorrect rows "color" attribute of
* <ls_data> structure should be set to cl_gui_resources=>LIST_COL_NEGATIVE

* In this example implementation we will just colorize every second row
* of after image
  DATA:
        lb_colorize     TYPE ABAP_BOOL,
        lv_row          TYPE /DVD/EQS_INT,
        lv_row_color    TYPE LVC_COL.

  LOOP AT ct_a_data ASSIGNING <ls_data>.
    IF lv_row <> <ls_data>-y.
*     We moved to another row determine color
      IF lb_colorize = ABAP_TRUE.
        lb_colorize = ABAP_FALSE.
        lv_row_color = cl_gui_resources=>list_col_negative.
      ELSE.
        lb_colorize = ABAP_TRUE.
        CLEAR lv_row_color.
      ENDIF.

      lv_row = <ls_data>-y.
    ENDIF.

    <ls_data>-color = lv_row_color.
  ENDLOOP.

* Pretend errors were found during comparison
  eb_different = ABAP_TRUE.


*PACKAGE_SIZE parameter can be set in Validate settings.


Custom BAdI implementation instance

Another example of custom compare BAdI implementation is provided for the usage as separate transport. Compare is based on full control requested. Report lines are not compared one by one in the same positions, but each line from After Image is searched for in the entire package of lines from Before Image. If not exactly the same line is found in Before Image, a line from After Image is marked red. After the first loop of search, unmatched lines from Before Image are also marked red. This can indicate missing line in after image or a pair line with the difference and is already marked red in After Image.

Comparison settings Ignore timestamps and Compare only table data are taken into account. Remapping of user defined text (in cases of different abbreviations, naming conventions and other small non-relevant differences between system versions) or ignoring entire lines based on a pattern is also supported. Mapping and ignore patterns should be defined by table maintenance of table '/DVD/EQS_REPMAP'.

After the transport is imported, enhancement implementation '/DVD/EQS_EH_IM_REP_COMP' (in package '/DVD/EQS_REP_BADI') must be set to "Active" to take effect. Otherwise Validate default BAdI comparator implementation will be used.