Cross Database Comparison: Enhancement Guide
Cross Database Comparison: Enhancement Guide
Enhancement Guide
TABLE OF CONTENT
MOTIVATION .................................................................................................................................................... 3
Characteristics of generated CDC Data Extractors ..................................................................................... 3
Limitation of generated CDC Data Extractors .............................................................................................. 3
DATA EXTRACTORS FOR SOURCE TYPE ABAP ........................................................................................ 4
General Procedure to enhance the generated ABAP data extractor ......................................................... 4
Example case ................................................................................................................................................... 4
DATA EXTRACTORS FOR SOURCE TYPE ADBC ........................................................................................ 5
General Procedure to enhance the generated ADBC SQL statement ........................................................ 5
ENHANCEMENT SPOTS WITHIN CDC ........................................................................................................... 6
Enhancement Spot DSWP_CDC_CONVERSION .......................................................................................... 6
Procedure .......................................................................................................................................................... 6
Enhancement Spot DSWP_CDC_SOURCE ................................................................................................... 7
Filter possibilities for implementation ................................................................................................................. 8
Interface to be implemented .............................................................................................................................. 8
CREATING YOUR OWN SOURCE TYPES ..................................................................................................... 8
Procedure ......................................................................................................................................................... 8
Definition of the source type .............................................................................................................................. 8
Creation of the class ........................................................................................................................................ 11
Which methods have to be implemented? ...................................................................................................... 14
Embedding a specific UI for your source type ................................................................................................. 14
APPENDIX ...................................................................................................................................................... 16
Enhancing SQL extractions with DISTINCT ................................................................................................ 16
Business Example ........................................................................................................................................... 16
Enhancing SQL extractions with relative date selections ......................................................................... 16
Business Example ........................................................................................................................................... 16
MS-SQL server ................................................................................................................................................ 16
MaxDB ............................................................................................................................................................. 17
Enhanced ABAP data extractor with relative date selection on yesterday (simple date field) ............. 17
Enhanced ABAP data extractor with relative date selection on yesterday (timestamp field),
independent SELECT... FOR ALL ENTRIES, additional application logic, key mapping ....................... 21
BAdI implementation for enhancement spot DSWP_CDC_SOURCE ....................................................... 28
Business Use Case ......................................................................................................................................... 28
Procedure ........................................................................................................................................................ 28
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
MOTIVATION
Characteristics of generated CDC Data Extractors
With the Cross Database Comparison (CDC) tool, you define a graphical data model of both source systems
and the mapping of the comparison fields between them. This data model offers a lot of flexibility, like joins
on several tables and filters on fixed and dynamic criteria. Based on the data model, certain source types like
ABAP and ADBC perform a generation, which is an automatic creation of the corresponding extractor ABAP
function module or the native SQL statement. This generation happens based on fixed templates, to create
the code to extract the data based on the object model, using best practices and common procedures to
facilitate an “as-close-as-possible” match to the expected extraction scenario.
3
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Example case
The actual goal of the comparison is quite simple: Compare the delivery numbers of all deliveries created
yesterday between SAP EWM and SAP ERP, which have a successful goods movement for all items, to
prove whether it was correctly replicated from EWM to ERP.
On the ERP side, the only enhancement is a relative date selection on all documents created yesterday,
filtering on LIKP~ERDAT (simple date field).
On the EWM side, there were multiple extensions necessary, caused by the completely different data model:
- Relative date selection based on a timestamp field /SCDL/DB_PROCH_O~CRETST.
- Requirement to read all item’s status from /SCDL/DB_STATUS, because there is no appropriate status field
on header level, together with an aggregation of header status telling all items have goods issue finished.
- Mapping of the EWM document ID to the corresponding ERP delivery number.
Note: As of ST 7.1 SP5, the relative date filtering is available in standard.
4
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
5
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Procedure
1. Create a new conversion ID
Start transaction SM30 and enter view CDC_V_CONV_TYPE. Click on “Maintain” (Figure 1)
Figure 1
A maintenance dialog will be displayed. Click on “New entries” and enter the following data:
a. Conversion ID
The conversion ID is the technical name which will identify the conversion. It is character
field with length 10. The name has to start with “Y” or “Z” for customer specific conversions.
b. Field Label
This is the text that will appear in the drop-down list when selecting a conversion ID in the
mapping detail screen:
6
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 2
c. Description
A more detailed description what this conversion will do. The description is just for internal
reference but will currently not be displayed on any screen.
2. Implement the coding
Start the class builder for class CL_DSWP_CDC_CONVERSION and navigate into method
CONVERT_DATA. Click on button Enhance . Position the cursor on the line “ENHANCEMENT-
POINT DSWP_CDC_CONV_ID SPOTS DSWP_CDC_CONVERSION . “ and perform a right click to
display the context menu. Choose option Enhancement Operations → Create implementation. Enter
a name for your enhancement in the displayed popup. Best practice would be to use the conversion
ID is the conversion ID you have entered as technical name to have a simple reference between
coding and definition.
Add the following coding to the new enhancement implementation
IF <fs_conversion>-conv_id EQ ‘<conversion_id>.
<YOUR CONVERSION CODE>
ENDIF.
Here <conversion_id> should be the technical name of the conversion ID you have created, while
<YOUR CONVERSION CODE> contains your actual code. You can use the standard conversion
routines as guidance how your conversion coding could look like.
Please implement SAP note 1942636 - CDC: Not possible to implement enhancements for data conversion if
you have problems with the enhancement implementation.
7
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
should rather create a custom conversion ID than implement the BAdI, in particular if the same conversion
ID should be reused in the data models of multiple comparison objects. If you need more complex
conversion like converting extracted data in one column based on the data in another column or if the
conversion should only be used for the data model in a specific comparison object or even only for a
specific comparison instance, you should rather implement the BAdI.
Interface to be implemented
The class used to implement the BAdI has to implement interface IF_DSWP_CDC_SOURCE_DATA. This
interface provides the following methods:
MODIFY_DATA_TABLE
This method may be used to modify the data table derived from the extracted data after
transformation of the XML. The data is contained in changing parameter CT_SOURCE_TAB.
MODIFY_DATA_XML
This method may be used to modify the extracted XML data directly. The data is contained either in
changing parameter CV_DATA_STRING or CV_DATA_XSTRING depending on whether the source
type provides the XML in character string format or in binary string format. Importing parameter
IV_XML_TYPE may be used to decide which import parameter should be used.
Procedure
Definition of the source type
Start transaction DSWP_CDC_SOURCES. You get a screen for view cluster maintenance. Click on button
“New Entries”.
Figure 3
8
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Description: A meaningful description for this source type like “Demonstration for enhancement”
Implementing class: The class that implements this source type. This class has to implement interface
IF_DSWP_CDC_SOURCE. For details see section “Creation of the class”. It is recommended that
the name should contain the technical name, e.g. ZCL_ZTHS_SOURCE_TYPE.
Save your new definition. The next step is to define the needed connection parameters. To do this select
your new Source Type and navigate in the tree on the left side to CDC Source Parameter
Figure 4
9
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
As we create a new type, no parameters exist yet, but we have to create new ones. Click on “New Entries” to
start this process. First enter the Source Type (in our case ZTHS) and a technical name for the parameter:
Figure 5
In addition, the following parameters define the behavior of the Source Type’s parameter:
Description
A description what this parameter will achieve and what it means. The description will appear as
tooltip on the parameter in the UI.
Field Label
The label that will be used on the UI for the input field.
Parameter Sort Order
An integer number defining the order of display on the UI.
Parameter usage in Comparison Object
o 0 Invisible
Set this value if the parameter should be invisible in the Comparison Object UI.
o 1 Display Only
Set this value if the parameter should not be changeable, e.g. because it is calculated
depending on other parameters or values during generation.
o 2 Maintenance
Set this value if the parameter should be maintained manually in the Comparison Object.
Parameter usage in Comparison Instance
o 0 Invisible
Set this value if the parameter should be invisible in the Comparison Object UI.
o 1 Display only
Set this value if the parameter should not be changeable, e.g. because it is calculated
depending on other parameters
o 2 Maintenance
Set this value if the parameter should be maintained manually in the Comparison Instance.
o 3 Copy Once from Object – Maintenance in Instance
The value of the parameter will be copied from the Comparison Object during initial creation
of the instance, but can be overwritten manually in the Comparison Instance if this value is
set.
10
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Once all parameters are maintained save the Source Type parameter definition and continue creating further
parameters if needed.
11
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
CHECK_EXTRACTOR
This method can be used to implement an existence check, e.g. if the generated extractors have to
be transported between different systems to ensure they are available.
CHECK_VERSION
Here you can implement the versioning check if you have set the flag “Versioning Support” in the
definition of the Source Type. It will be called at run time to check whether the extractor still fits to the
version of the Comparison Object. If the version does not fit a corresponding exception has to be
raised.
CONVERT_RELATIVE_DATE
Here you can implement the conversion of relative dates into specific date formats as needed by
your system. If the needed format corresponds to the internal format as used in ABAP system you
may use cl_dswp_cdc_utils=>conv_dynamic_date_syntax to perform this date
transformation.
FETCH_BLOCK
This method will be called at run time to receive a new block of specified block size from the source
system. Depending on whether you support iteration or not it also has to be able to use the
comparison keys provided at run time.
The extracted data has to be returned in the XML-structure needed for the comparison as character
string or binary string where the tag-names correspond to the mapping names as defined in the
corresponding comparison object.
The XML has to be in asXML format, that means that in addition each row of data has to be
encapsulated in <item> … </item> and the complete table in <table>..</table> tags to allow the
identification of the individual rows. An example where the mapping names “PARTNER”, “TYPE”,
and “BPKIND” are used would look is displayed in Listing 1:
This transformation has either to be done locally in the managed system or centrally in the method
itself based on a data table returned from the managed system. If the data table (for example
lt_source_data) already contains the relevant mapping names as column names the conversion can
be done easily in method FETCH_BLOCK in Solution Manager based on the following coding
template (Listing 2)
12
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
CALL TRANSFORMATION id
SOURCE table = lt_source_data
RESULT XML ev_data_string.
FETCH_BLOCK
This method will be called during the actual comparison run to receive a block of data. The data will
be provided as XML-document in string or xstring-format depending on the settings of the source
types used in the comparison.
FETCH_COUNT
This method will be called initially at run time to determine how many records will roughly be
compared. The returned value is also the basis for the progress indicator.
FETCH_COUNT_BOTH
This method will be called initially at run time to determine how many records will roughly be
compared. The method “FETCH_COUNT_BOTH” will be called for single source types only (see
section Definition of the source type for further details).
FETCH_RESULT
Method FETCH_RESULT will receive not a block of data to be compared but a complete comparison
result from a managed system. It will be called for single source types only (see section Definition of
the source type for further details).
GENERATE_EXTRACTOR
This method will be invoked when pressing the button “generate” in the Comparison Object’s UI. You
can implement generations based on the entered parameters and data model like generation of
function modules, SQL-statements etc.
GET_COLUMNS
The helper method GET_COLUMNS is used during design time as value help for field names (or
equivalent) during data modeling. It will be called from method
CL_DSWP_CDC_SOURCE=>VALUEHELP_COLUMNS.
GET_TABLES
This helper method is used during design time as value help for tables (or equivalent) during data
modeling. It will be called from method CL_DSWP_CDC_SOURCE=>VALUEHELP_TABLES.
GET_VALUES
This helper method is used during design time as value help for field contents (or equivalent) during
data modeling. It will be called from method CL_DSWP_CDC_SOURCE=>VALUEHELP_VALUES.
PARAMETER_SET
This method is used to set the parameter values as filled in the UI and should transfer them to the
member table MT_PARAMETER
PARAMETER_VALIDATE
This method is invoked at design time during validation. You should check whether the entered
parameter values are meaningful.
PARAMETER_VALUEHELP
This method can be used to implement a value help for the source type parameters. It receives the
13
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
technical name of the parameter and any filter data entered and has to return a table containing the
actual allowed values and a description for each value.
PERFORM_PING
This method will be called for a connection test to the Source System and should assess whether
the data source is reachable.
Besides this general decision, you have to decide which additional features your implementation should
support. In case an extraction in multiple blocks should be supported for the usual use case, you have to
return the concatenated key of the last entry in a block in field EV_ACT_KEY in addition to the block. This
key will be provided during the next call of method FETCH_BLOCK to provide the offset in field
IV_PREV_KEY. The delimiter to be used is contained in constant
cl_dswp_cdc_compare=>gc_combined_key_separator_db. Your implementation of this method has to
ensure that the returned entries are sorted according to the key across all blocks returned.
If iteration shall be supported, CDC will send a list of all keys for inconsistencies identified in a previous
iteration to this method using parameter IT_FILTER_KEY. Each line of this table contains the key for an
inconsistency where the individual keys are separated by constant
cl_dswp_cdc_compare=>gc_combined_key_separator_db. You need then to perform an extraction for each
of these keys and transfer the result back to CDC for comparison.
If your source type should support F4-helps for parameters, method PARAMETER_VALUEHELP has to be
implemented. In addition, you can implement method PARAMETER_VALIDATE
In case your source type implementation should support proposal of fields and table names you have to
implement the following methods:
GET_COLUMNS
GET_TABLES
In case your custom programmed source type should support a generation of extractors, method
GENERATE_EXTRACTOR has to be implemented. In addition, a validation should usually be performed
before you start generation. To perform this validation method PARAMETER_VALIDATE has to be
implemented as well.
The following interface methods are used for interaction between your UI and the embedding main UI:
14
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
GET_DATA:
The method GET_DATA provides parameters and their values to the main CDC UI via exporting
parameter ET_PARAMETER. The importing parameter USE_CASE determines which interface view
should provide the needed data respective from where the method is called:
o O – The method is called for a Comparison Object.
o I – The method is called for a Comparison Instance.
SET_DATA
This method is used to provide data from the central UI to the embedded screens, e.g. after loading
an Comparison Object. The following parameters contain the data to be displayed:
o Importing parameter IT_SOURCE_PARAMETER contains a list of parameters and their
values that should be displayed.
o The source system is determined by importing parameter IV_SOURCE_NO. A value of 1
means source 1, a value of 2 means source 2.
o IV_SOURCE_TYPE contains the technical name of the source type which parameters
should be displayed like ABDY or ABAP.
o The USE_CASE again determines whether data us provided for a Comparison Object or a
Comparison Instance.
SET_DISPLAY_MODE
This interface method will be called from the UI whenever a change of the display mode is triggered
by the central CDC UI. It only contains Boolean importing parameter IV_DISPLAY_MODE. A value
of true means that the embedded UI should be in read-only mode.
After the ABAP Web Dynpro UI to be embedded has been created it has to be embedded in the central
screens. To do this easily a new source type parameter “Web Dynpro Component” has been introduced with
SAP Solution Manager 7.1 SP12. Simply enter the name of your component into this field for those source
types that should utilize the UI. If the field is empty, the standard UIs for parameter maintenance will be
called.
15
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
APPENDIX
Enhancing SQL extractions with DISTINCT
Sometimes you are not interested to compare all data between two systems but are only interested whether
a data with a specific non-unique key exists at all. As the key for the Comparison Run has to be unique you
can add the SQL-command DISTINCT to extract key values only once.
Business Example
You replicate orders from one system to the other system where status handling is done. You are not
interested in the status information of orders, but would just like to know that at least one status record of a
relevant subset Status1 to Status5 exists. This would lead to a statement of the following form (manually
added parts in bold italic):
TABLE1 would be the table with the order information, while TABLE2 would contain the status information.
Business Example
You replicate orders from one system to the other system. You are not interested in outdated orders, but
would just like to know whether orders created in the last 7 days are consistent.
As the data functions are database dependent you have to enhance the SQL-statement with functions native
to the respective database.
MS-SQL server
The template for the restriction to 7 days would then be (added parts in bold italic):
SELECT TABLE1.ORDER_NUM
FROM /*SCHEMA*/table1
WHERE (
table1.entry_time >= DATEADD(day,-7,DATEDIFF(Day, 0, GETDATE()))
)
)
ORDER BY TABLE1.ORDER_NUM
16
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Again table1 would be the table containing the order information, order_num would be the primary key (order
number) and entry_time would be the time the order was entered.
MaxDB
The template for the restriction to 7 days would then be (added parts in bold italic
SELECT TABLE1.ORDER_NUM
FROM /*SCHEMA*/table1
WHERE (
table1.entry_time >= SUBDATE( DATE, 7 )
)
ORDER BY TABLE1.ORDER_NUM
Enhanced ABAP data extractor with relative date selection on yesterday (simple date field)
Here a local data calculation and usage as filter criteria during data selection was added. Added coding is
written in bold italic.
FUNCTION ZCDC_BUSTRANS_DELIVERY_V2.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IV_PREV_KEY) TYPE STRING OPTIONAL
*" VALUE(IV_BLOCK_SIZE) TYPE I DEFAULT 1000
*" VALUE(IT_FILTER) TYPE DDSHSELOPS OPTIONAL
*" EXPORTING
*" VALUE(EV_ACT_KEY) TYPE STRING
*" VALUE(EV_BLOCK) TYPE BOOLEAN
*" VALUE(EV_TOTAL) TYPE I
*" VALUE(EV_LINES) TYPE I
*" VALUE(EV_DATA_STRING) TYPE STRING
*" VALUE(EV_DATA_XSTRING) TYPE XSTRING
*" EXCEPTIONS
*" AUTHORIZATION_ERROR
*" DATABASE_ERROR
*" FILTER_ERROR
*" TRANSFORMATION_ERROR
*" CONVERSION_ERROR
*"--------------------------------------------------------------------
* ---------------------------------------------------------------------
* ---- CDC Extract Function ----
* This function module has been generated.
* Generated on 2012/03/22 15:15:26
* Enhanced on 2012/03/27 for custom-specific extractor logic
* => Please do not overwrite by new generation
* ---------------------------------------------------------------------
TYPES:
BEGIN OF TS_SOURCE_KEY,
KEY1 TYPE VBELN,
END OF TS_SOURCE_KEY,
BEGIN OF TS_SOURCE_DATA,
KEY1 TYPE VBELN,
END OF TS_SOURCE_DATA.
CONSTANTS:
LC_DELIMITER TYPE STRING VALUE '|||'.
DATA:
17
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
DATA:
LV_TABLE_GROUP TYPE BRGRU,
LV_TABLE_GROUP_NO_AUTH TYPE SYMSGV,
LV_ERROR_MESSAGE TYPE STRING,
LV_FILTER_FIELD TYPE STRING,
LX_ROOT TYPE REF TO CX_ROOT.
DATA:
LV_TYPE TYPE STRING,
LV_NO_COMPONENT TYPE I,
LV_KEY_STRING TYPE STRING,
LV_OFFSET TYPE I,
LV_LENGTH TYPE I.
DATA:
LV_YESTERDAY LIKE LIKP-ERDAT.
FIELD-SYMBOLS:
<LS_FILTER_LINE> TYPE DDSHSELOPT,
<FS_FIELD> TYPE ANY.
IF SY-SUBRC NE 0.
CONCATENATE LV_TABLE_GROUP_NO_AUTH LV_TABLE_GROUP
INTO LV_TABLE_GROUP_NO_AUTH SEPARATED BY ','.
ENDIF.
18
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
INTO LV_TABLE_GROUP
WHERE TABNAME = 'LIKP'.
IF SY-SUBRC NE 0.
CONCATENATE LV_TABLE_GROUP_NO_AUTH LV_TABLE_GROUP
INTO LV_TABLE_GROUP_NO_AUTH SEPARATED BY ','.
ENDIF.
IF IV_BLOCK_SIZE < 0.
* Count expected number of rows only
SELECT COUNT(*)
INTO EV_TOTAL
FROM VBUK JOIN LIKP ON LIKP~VBELN = VBUK~VBELN
WHERE VBUK~WBSTK EQ 'C'
AND LIKP~ERDAT = LV_YESTERDAY
AND LIKP~VKORG = '0001'.
RETURN.
ENDIF.
19
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
ENDIF.
FIND LC_DELIMITER
IN LV_KEY_STRING
MATCH OFFSET LV_OFFSET
MATCH LENGTH LV_LENGTH.
IF SY-SUBRC EQ 0.
MOVE LV_KEY_STRING(LV_OFFSET) TO <FS_FIELD>.
ELSE.
MOVE LV_KEY_STRING TO <FS_FIELD>.
EXIT.
ENDIF.
ENDDO.
CATCH CX_SY_CONVERSION_ERROR INTO LX_ROOT.
MESSAGE E001(00) WITH IV_PREV_KEY
RAISING CONVERSION_ERROR. "#EC MG_PAR_CNT
ENDTRY.
ENDIF.
SELECT VBUK~VBELN
INTO TABLE LT_SOURCE_DATA
UP TO IV_BLOCK_SIZE ROWS
FROM VBUK JOIN LIKP ON LIKP~VBELN = VBUK~VBELN
WHERE VBUK~WBSTK EQ 'C'
AND LIKP~ERDAT = LV_YESTERDAY
AND LIKP~VKORG = '0001'
AND VBUK~VBELN > LS_SOURCE_KEY-KEY1
ORDER BY VBUK~VBELN.
EV_LINES = SY-DBCNT.
20
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
ENDFUNCTION.
Enhanced ABAP data extractor with relative date selection on yesterday (timestamp field),
independent SELECT... FOR ALL ENTRIES, additional application logic, key mapping
FUNCTION ZCDC_BUSTRANS_DELIVERY_V2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IV_PREV_KEY) TYPE STRING OPTIONAL
*" VALUE(IV_BLOCK_SIZE) TYPE I DEFAULT 1000
*" VALUE(IT_FILTER) TYPE DDSHSELOPS OPTIONAL
*" EXPORTING
*" VALUE(EV_ACT_KEY) TYPE STRING
*" VALUE(EV_BLOCK) TYPE BOOLEAN
*" VALUE(EV_TOTAL) TYPE I
*" VALUE(EV_LINES) TYPE I
*" VALUE(EV_DATA_STRING) TYPE STRING
*" VALUE(EV_DATA_XSTRING) TYPE XSTRING
*" EXCEPTIONS
*" AUTHORIZATION_ERROR
*" DATABASE_ERROR
*" FILTER_ERROR
*" TRANSFORMATION_ERROR
*" CONVERSION_ERROR
*"----------------------------------------------------------------------
* ---------------------------------------------------------------------
* ---- CDC Extract Function ----
* This function module has been generated.
* Generated on 2012/03/22 15:13:44
* Enhanced on 2012/03/27 for custom-specific extractor logic
* => Please do not overwrite by new generation
* ---------------------------------------------------------------------
TYPES:
BEGIN OF ts_source_key,
KEY1 TYPE /SCDL/DL_REFDOCNO,
END OF ts_source_key,
BEGIN OF ts_source_data,
KEY1 TYPE /SCDL/DL_REFDOCNO,
21
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
BEGIN OF ts_del_item_status,
DOCID TYPE /SCDL/DL_DOCID,
ITEMID TYPE /SCDL/DL_ITEMID,
STATUS_VALUE TYPE /SCDL/DL_STATUS_VALUE,
END OF ts_del_item_status,
tt_del_item_status TYPE SORTED TABLE OF ts_del_item_status
WITH UNIQUE KEY docid itemid.
CONSTANTS:
lc_gi_finished TYPE /SCDL/DL_STATUS_VALUE VALUE '9'.
CONSTANTS:
lc_delimiter TYPE string VALUE '|||'.
DATA:
lt_source_data TYPE STANDARD TABLE OF ts_source_data,
lt_temp_source_data TYPE STANDARD TABLE OF ts_source_data,
lv_remaining_block_size TYPE i,
ls_source_data TYPE ts_source_data,
ls_source_key TYPE ts_source_key.
DATA:
lv_table_group TYPE brgru,
lv_table_group_no_auth TYPE symsgv,
lv_error_message TYPE string,
lv_filter_field TYPE string,
lx_root TYPE REF TO cx_root.
* DATA:
* lt_FILTER1 TYPE RANGE OF /SCDL/DL_CRETST, ls_FILTER1 LIKE LINE OF
*lt_FILTER1.
DATA:
lv_type TYPE string,
lv_no_component TYPE i,
lv_key_string TYPE string,
lv_offset TYPE i,
lv_length TYPE i.
DATA:
lv_tstamp_from LIKE /scdl/db_proch_o-cretst,
lv_tstamp_to LIKE /scdl/db_proch_o-cretst,
lv_timezone LIKE ttzz-tzone VALUE 'UTC',
lv_time TYPE sy-uzeit,
lv_yesterday TYPE sy-datum,
lt_del_doc TYPE STANDARD TABLE OF /scdl/db_proch_o-docid,
lt_del_item_status TYPE tt_del_item_status,
lt_del_gi_finished TYPE STANDARD TABLE OF /scdl/dl_docid,
lv_status_low TYPE /scdl/dl_status_value.
FIELD-SYMBOLS:
<ls_filter_line> TYPE ddshselopt,
<fs_field> TYPE any,
<ls_del_item_status> TYPE ts_del_item_status.
22
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
IF sy-subrc NE 0.
CONCATENATE lv_table_group_no_auth lv_table_group
INTO lv_table_group_no_auth SEPARATED BY ','.
ENDIF.
IF sy-subrc NE 0.
CONCATENATE lv_table_group_no_auth lv_table_group
INTO lv_table_group_no_auth SEPARATED BY ','.
ENDIF.
23
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
IF sy-subrc NE 0.
CONCATENATE lv_table_group_no_auth lv_table_group
INTO lv_table_group_no_auth SEPARATED BY ','.
ENDIF.
IF iv_block_size < 0.
** Count expected number of rows only
* SELECT COUNT(*)
* INTO ev_total
* FROM /SCDL/DB_REFDOC
* JOIN /SCDL/DB_PROCH_O
* ON /SCDL/DB_PROCH_O~DOCID = /SCDL/DB_REFDOC~DOCID
* JOIN /SCDL/DB_STATUS
* ON /SCDL/DB_STATUS~DOCID = /SCDL/DB_PROCH_O~DOCID
* WHERE /SCDL/DB_REFDOC~REFDOCCAT EQ 'ERP'
* AND /SCDL/DB_PROCH_O~DOCCAT EQ 'PDO'
* AND /SCDL/DB_STATUS~ITEMID EQ
* '00000000000000000000000000000000'
* AND /SCDL/DB_STATUS~STATUS_TYPE EQ 'DGI'
* AND /SCDL/DB_PROCH_O~CRETST BETWEEN lv_tstamp_from
* AND lv_tstamp_to.
24
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
* Cannot use multiple block fetches with key offset (different keys)
* => need to fetch all deliveries in one block
** Move imported key string to key structure
* DESCRIBE FIELD ls_source_key
* TYPE lv_type
* COMPONENTS lv_no_component.
* IF iv_prev_key IS NOT INITIAL.
* TRY.
* DO lv_no_component TIMES.
* ASSIGN COMPONENT sy-index
* OF STRUCTURE ls_source_key
* TO <fs_field>.
* IF sy-index EQ 1.
* lv_key_string = iv_prev_key.
* ELSE.
* lv_key_string = lv_key_string+lv_offset.
* lv_key_string = lv_key_string+lv_length.
* ENDIF.
* FIND lc_delimiter
* IN lv_key_string
* MATCH OFFSET lv_offset
* MATCH LENGTH lv_length.
* IF sy-subrc EQ 0.
* MOVE lv_key_string(lv_offset) TO <fs_field>.
* ELSE.
* MOVE lv_key_string TO <fs_field>.
* EXIT.
* ENDIF.
* ENDDO.
* CATCH cx_sy_conversion_error INTO lx_root.
* MESSAGE e001(00) WITH iv_prev_key
* RAISING conversion_error. "#EC MG_PAR_CNT
* ENDTRY.
* ENDIF.
* This was the original generated join, but cannot be used here
* SELECT /SCDL/DB_REFDOC~REFDOCNO
* INTO TABLE lt_source_data
* UP TO iv_block_size ROWS
* FROM /SCDL/DB_REFDOC
* JOIN /SCDL/DB_PROCH_O
* ON /SCDL/DB_PROCH_O~DOCID = /SCDL/DB_REFDOC~DOCID
* JOIN /SCDL/DB_STATUS
* ON /SCDL/DB_STATUS~DOCID = /SCDL/DB_PROCH_O~DOCID
* WHERE /SCDL/DB_REFDOC~REFDOCCAT EQ 'ERP'
* AND /SCDL/DB_PROCH_O~DOCCAT EQ 'PDO'
* AND /SCDL/DB_STATUS~ITEMID EQ '00000000000000000000000000000000'
* AND /SCDL/DB_STATUS~STATUS_TYPE EQ 'DGI'
* AND /SCDL/DB_PROCH_O~CRETST BETWEEN lv_tstamp_from AND lv_tstamp_to
* AND /SCDL/DB_REFDOC~REFDOCNO > ls_source_key-key1
* ORDER BY /SCDL/DB_REFDOC~REFDOCNO.
25
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
* Find all deliveries where all items have goods issue completed
lv_status_low = lc_gi_finished.
LOOP AT lt_del_item_status ASSIGNING <ls_del_item_status>.
* Find any item status smaller than 9 (goods issue finished)
IF <ls_del_item_status>-status_value < lv_status_low.
lv_status_low = <ls_del_item_status>-status_value.
ENDIF.
* Remember all deliveries which have all items GI completed
AT END OF docid.
IF lv_status_low = lc_gi_finished.
APPEND <ls_del_item_status>-docid TO lt_del_gi_finished.
ENDIF.
lv_status_low = lc_gi_finished.
ENDAT.
ENDLOOP.
* Cannot use multiple block fetches with key offset (different keys)
* => need to fetch all deliveries in one block
26
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
CLEAR ev_block.
ENDFUNCTION.
27
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 6
In the next dialog choose Create Enhancement Implementation(F8). Each BAdI implementation has
to be assigned to an enhancement implementation.
Figure 7
Input technical name, short text for enhancement implementation and hit enter
28
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 8
Maintain the Object attributes – Local object if this implementation is not expected to be transported.
Figure 9
Figure 10
Figure 11
29
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 12
Review the properties for the enhancement implementation that was just created. Status is Inactive
Figure 13
30
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 14
Figure 15
method IF_DSWP_CDC_SOURCE_DATA~MODIFY_DATA_TABLE.
* In the following example, the comparison object has in column 3 a data
* type NUMC. So the content value has leading zeros, which need to be
* converted to an integer number for comparison reasons.
DATA:
lv_integer TYPE i,
lv_number TYPE n,
lv_txt TYPE c LENGTH 7.
FIELD-SYMBOLS:
<ls_source_row> TYPE any, " row of source data table
<lv_source_val> TYPE any. " component of table row
31
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
lv_number = <lv_source_val>.
lv_txt = <lv_source_val>.
<lv_source_val> = lv_integer.
* If it cannot be converted into a valid number, clear the value
CATCH cx_sy_conversion_no_number.
CLEAR <lv_source_val>.
ENDTRY.
ENDIF.
ENDLOOP.
endmethod.
Save and Maintain the BAdI Implementation Filter Values specific to the Comparison Object or
Comparison Instance, and relevant Source 1 or Source2
Figure 16
Save, and Activate all the objects part of the Enhancement Implementation
Figure 17
Execute the comparison run for comparison instance. Screenshot below shows the Number format
conversion (debug mode)
32
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 18
33
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Comparison Results before implementation of CDC specific BAdI : Object Key: VBELN_OBJECTID
has leading zeroes
Figure 19
34
CROSS DATABASE COMPARISON – ENHANCEMENT GUIDE
Figure 20
35