(DV-2402) Conversion Rules
The conversion rules functionality provided by Validate offers another option for how data can be adjusted to allow seamless usage in complex transformation scenarios. It enables you to define a conversion rule applied on key and value fields, to be used during the comparison of data images.
Before the rule is set, the relevant variant must be created. By using the Set Conversion rules button in advanced settings, rules can be assigned and defined.
The functionality provides you with two types of rules:
ABAP rule
Value mapping
It is possible to use both options within the same variant, but only one rule can be defined for each field in the data image.
The ABAP rule allows the runtime execution of a piece of ABAP code which enables users to create their own conversion of a field value. To be able to use conversion ABAP rules, the impacted field must be filled in the key or value fields of the variant. This is an advanced feature; it is expected that the user has at least basic knowledge of the ABAP syntax and coding.
In the case of rules where data is selected from the database, caution is advised. The code is executed for every line of the data image. Therefore, all accesses to the DB should be optimized. It is recommended to use STATIC local variables to store this kind of content. Using this approach, the data only needs to be selected once and will be reused in every following line evaluation.
To create an ABAP rule, click on the insert row button.
First, fill in the Field name (specifies to which column, the rule should be applied), then fill in the Rule Type A (ABAP rule) and the rule name. The ABAP rule name is restricted to a Z prefix for those created by the customer.
The ABAP code of an ABAP rule can be opened by double-clicking on its name. If the ABAP rule doesn't exist, a pop-up will ask for confirmation to create it. Each field of a table can have a maximum of one ABAP Conversion Rule defined in a Variant.
The ABAP editor is opened, which allows the edition of the code.
The code's syntax can be checked with the Check syntax button.
The code can be pretty-printed by clicking on the Pretty print button.
By clicking on the Confirm button, the code will be saved regardless of the validity of its syntax to allow for continuous writing of the ABAP.
By clicking on the Cancel button, all the changes made to the code from the last confirmation will be discarded. A Variant can be saved with a syntactically incorrect ABAP rule, at saving a warning pop-up will inform the user of the code's incorrectness.
The code of the ABAP rule is locked. Only a part of the form is editable, where the ABAP conversion rule code should be written. The user is able to access the context class within the form. Furthermore, the original table line, converted table line, field name, and changed value is available as well.
Available information from the context class
lo_run_ctx->A_VARIANT_ID: After image ID
lo_run_ctx->INITIALIZED: Is the context class initialized
lo_run_ctx->LAST_START_TIMESTAMP: Timestamp of the last run
lo_run_ctx->PL_TECHNAME: Testplan technical name
lo_run_ctx->RFC_DEST: RFC destination of the Variant
lo_run_ctx->RUNID: Run ID of the Variant execution
lo_run_ctx->START_TIMESTAMP: Timestamp of the start of the run
lo_run_ctx->TC_TECHNAME: Test case technical name
lo_run_ctx->TC_TYPE: Test case type
lo_run_ctx->VARIANT_ID: VariantID
lo_run_ctx->TABLE_NAME: Table name for the Variant (30c)
lo_run_ctx->ROWCOUNT: Is rowcount selected
lo_run_ctx->STORAGE_ID: StorageID for SM Table Variant
lo_run_ctx->T_FIELD_MAPPING: Table of Field Mapping definition
lo_run_ctx->T_CHAR_FIELD: Table of selected key fields of the Variant
lo_run_ctx->T_KYF_FIELD: Table of selected value fields of the Variant
lo_run_ctx->T_TAGS: Table with Variant TAGs
lo_run_ctx->EXT_TABNAME_LONG: External table name for SM Table Variants
lo_run_ctx->T_DYN_FLT: Table with Dynamic Filters of the Variant
lo_run_ctx->T_CONTENT: Table of DF ABAP codes
Value Mapping gives the ability to apply simple mapping within the comparison task.
No logic is required, only a list of old and new values corresponding to one another needs to be provided.
To create a value mapping rule, click on the insert row button.
First, fill in the field name (specifies to which column value mapping should be applied), then fill in the rule type V (value mapping rule) and then the rule name. The rule name is restricted to a Z prefix for those created by the customer.
The mapping can be opened by double-clicking on the rule name. If the rule doesn't exist, a pop-up will ask for confirmation to create it. Column Old value specifies the value to be replaced. Column New value represents the value to which the corresponding old value change.