(DV-1805) ERP Report - BADI comparator
When you are executing "Set comparison settings" step in ERP Report Test Case you are able to select "BADI Report Comparator" for 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 custom comparator class 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 - Recieves 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 iamges.
- COMPARE_DATA_PACKAGE - Recieves 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 result and must return EB_DIFFERENT with value "X" if any difference is found in whole package .
From the interface two main approaches of data comparison can be taken.
Line by line custom comparison
If your implementation returns " " from "FULL_CONTROL_REQUESTED" method you only need to implement "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 "FULL_CONTROL_REQUESTED" method you only need to implement "COMPARE_DATA_PACKAGE" method. For this type of implementation other comparison settings: "Ignore TimeStamps", "Compare only table data" are ignored. Following is example implementation for this comparison approach.
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 Valdiate "REPORT_COMP_PCG" setting. This setting * determinates maximum number of rows for one invocation of this method * Defaul 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 recieving 10 000 rows in first package and 2000 * rows in second invocation. * Be awere 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 comming 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.