How-to Enforce DTP Semantic Group

Have you ever had a support ticket raised against a solution you delivered, only to find that it’s not broken but someone has changed it without realising the consequences?

The worst thing to happen is when that change doesn’t stop the nightly load window but turns up as poor quality data that has been made available for reporting.

When the DTP configuration uses Semantic Groups to drive business rules within a Transformation, it is usually done by the BW Developer intentionally and for a very good reason. In the end, it always comes back to a need to process simular records together as a group while processing a DataPacket.

For Example: A time-dependant DataSet is converted to time-independant.

For Example: Reducing a DataSet to a smaller group of nominated representative records.

For Example: Optimised business rule processing because all related records are processed together, resulting in fewer lookups into external resources.

In these circumstances, the Semantic Group configuration in the DTP is considered mandatory and should always be used as originally configured, no changes allowed.

Use this solution in a Transformation Start Routine to enforce a DTP Semantic group configuration. The DTP will always fail to load (Abort) until the DTP Semantic Group configuration is restored.

Method ZCL_TRFN_SEMANTIC_GROUP->CHECK

METHOD check.<br>
*--------------------------------------------------------------------*<br>
* Code Name:   zcl-trfn-semantic-group-check.                        *<br>
* Code URI:    http://lnxbw.co/edsg-cod-1                            *<br>
* Description: Check DTP Semantic Group configuration against        *<br>
*              expectations in a SAP BW Transformation.              *<br>
* Version:     1.0.0                                                 *<br>
* Author:      Bob Sarmany and John Lang                             *<br>
* Author URI:  http://www.learnbw.com/                              *<br>
* License:     BSD-New                                               *<br>
* License URI: http://opensource.org/licenses/BSD-3-Clause           *<br>
*--------------------------------------------------------------------*<br>
* Copyright (c) 2015, www.LearnBW.com. All rights reserved.          *<br>
*                                                                    *<br>
* Redistribution and use in source and binary forms, with or without *<br>
* modification, are permitted provided that the following conditions *<br>
* are met:                                                           *<br>
*                                                                    *<br>
* 1. Redistributions of source code must retain the above copyright  *<br>
* notice, this list of conditions and the following disclaimer.      *<br>
*                                                                    *<br>
* 2. Redistributions in binary form must reproduce the above         *<br>
* copyright notice, this list of conditions and the following        *<br>
* disclaimer in the documentation and/or other materials provided    *<br>
* with the distribution.                                             *<br>
*                                                                    *<br>
* 3. Neither the name of the copyright holder nor the names of its   *<br>
* contributors may be used to endorse or promote products derived    *<br>
* from this software without specific prior written permission.      *<br>
*                                                                    *<br>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *<br>
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *<br>
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *<br>
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *<br>
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS *<br>
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,           *<br>
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED    *<br>
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,      *<br>
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON  *<br>
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,    *<br>
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *<br>
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *<br>
* SUCH DAMAGE.                                                       *<br>
*--------------------------------------------------------------------*<br>
********************************************************************************<br>
* Class : ZCL_TRFN_SEMANTIC_GROUP                                              *<br>
* Method: CHECK                                                                *<br>
* Date  : 2015                                                                 *<br>
* Author: Bob Sarmany                                                          *<br>
********************************************************************************<br>
* Description:<br>
* ------------<br>
* Check the validity of the DTP Semantic Group definition being executed.<br>
*<br>
* Example Usage:<br>
* ==============<br>
*<br>
*  DATA:<br>
*    lt_fldlist TYPE zcl_trfn_semantic_group=>tty_field_list<br>
*  , ls_fldname TYPE zcl_trfn_semantic_group=>ty_field_list<br>
*  .<br>
*<br>
*  * Populate field names that are expected in the semantic group.<br>
*    refresh lt_fldlist.<br>
*    ls_fldlist-fieldname = 'MATERIAL'. insert ls_fldlist into table lt_fldlist.<br>
*    ls_fldlist-fieldname = 'CALDAY'.   insert ls_fldlist into table lt_fldlist.<br>
*<br>
*  * Ensure only the expected field names are in the semantic group.<br>
*    CALL METHOD zlbw_trfn_semantic_group=>check<br>
*      EXPORTING<br>
*        i_p_r_request                = p_r_request<br>
*        it_fieldlist                 = lt_fldlist<br>
*      EXCEPTIONS<br>
*        no_grouping_defined          = 1<br>
*        grouping_incorrectly_defined = 2<br>
*        field_not_found_in_group     = 3<br>
*        others                       = 4.<br>
*<br>
*  * Abort the Transformation.<br>
*    IF sy-subrc <> 0.<br>
*      clear monitor_rec.<br>
*      monitor_rec-msgid = 'RSTRAN'.<br>
*      monitor_rec-msgty = 'E'.<br>
*      monitor_rec-msgno = '826'.<br>
*      monitor_rec-msgv1 = 'Semantic grouping error. The following'.<br>
*      monitor_rec-msgv2 = 'fields must be in the semantic group:'.<br>
*      monitor_rec-msgv3 = 'MATERIAL,CALDAY.'.<br>
*      monitor_rec-msgv4 = ''.   "<- More field names if needed.<br>
*      APPEND monitor_rec TO monitor.<br>
*      RAISE EXCEPTION TYPE cx_rsrout_abort.<br>
*    ENDIF.<br>
********************************************************************************</p>
<p>  DATA:<br>
    lr_dtp         TYPE REF TO cl_rsbk_dtp<br>
  , lv_dtp_name    TYPE rsbkdtpnm<br>
  , lt_groupfields TYPE rsbk_tx_fields_keyfl<br>
  , lv_fieldcount  TYPE i<br>
  .</p>
<p>  FIELD-SYMBOLS:<br>
    <lfs_groupfields> TYPE rsbk_sx_fields_keyfl<br>
  , <lfs_fieldlist>   TYPE rsbk_t_fields_keyfl<br>
  , <lfs_fieldname>   TYPE rsbk_s_fields_keyfl<br>
  .</p>
<p>* Use the in-built class to get the current DTP name.<br>
  lv_dtp_name = i_p_r_request->get_dtp( ).</p>
<p>  lr_dtp = cl_rsbk_dtp=>factory( lv_dtp_name ).<br>
  lr_dtp->get_obj_ref_display( ).</p>
<p>* Validate that semantic grouping is correct.<br>
* Get grouping field list.<br>
  CALL METHOD lr_dtp->get_groupfields<br>
    IMPORTING<br>
      e_t_groupfields = lt_groupfields.</p>
<p>* Get number of expected fields in semantic group.<br>
  lv_fieldcount = lines( it_fieldlist ).</p>
<p>* First check if any semantic grouping has been defined.<br>
  READ TABLE lt_groupfields ASSIGNING <lfs_groupfields><br>
                                INDEX 1.<br>
  IF sy-subrc <> 0.<br>
    RAISE no_grouping_defined.</p>
<p>  ELSE.</p>
<p>    ASSIGN <lfs_groupfields>-t_fields TO <lfs_fieldlist>.</p>
<p>*   Check that we have the correct number of fields defined.<br>
    IF lines( <lfs_fieldlist> ) <> lv_fieldcount.<br>
      RAISE grouping_incorrectly_defined.</p>
<p>    ELSE.</p>
<p>*     Now ensure that every field matches with what is expected.<br>
      LOOP AT <lfs_fieldlist> ASSIGNING <lfs_fieldname>.<br>
        READ TABLE it_fieldlist<br>
             WITH TABLE KEY fieldname = <lfs_fieldname>-fieldname<br>
             TRANSPORTING NO FIELDS.<br>
        IF sy-subrc <> 0.<br>
          RAISE field_not_found_in_group.<br>
        ENDIF.<br>
      ENDLOOP.</p>
<p>    ENDIF.<br>
  ENDIF.</p>
<p>ENDMETHOD.

Implemented in 3 easy steps:

  1. Save the CHECK method code snippet;
  2. Create the ZCL_TRFN_SEMANTIC_GROUP ABAP Class;
  3. Enhance Transformation with call to DTP Semantic Group check.

How did it go? Leave a comment below.