Show TOC

Example of Migration of an Inversion RoutineLocate this document in the navigation structure

Use

This example is a nearly universally applicable model that shows how to migrate an inversion routine from a transfer rule.

In the routine, the German keys 'HERR' and 'FRAU' in the target characteristic are mapped to the English keys 'MR' and 'MRS' of the PASSFORM field (form of address) in the source. All other values from the source field are mapped to the initial value.

A further example does the same, but is optimized for the new method interface. Compare this with Example of Inversion Routine.

Sample Code
*$*$ begin of inverse routine - insert your code only below this line*-*
*   Simulate 3.X interface by defining variables of the same name
*   and the same type as the FORM routine parameters of the 3.X routine

    DATA:
      i_rt_chavl_cs      TYPE rsarc_rt_chavl,
      i_thx_selection_cs TYPE rsarc_thx_selcs,
      c_t_selection      TYPE sbiwa_t_select,
      e_exact            TYPE rs_bool.

    DATA:
      l_tr_dimensions    TYPE rsmds_tr_dimensions,              "table of dimension references
      l_r_dimension      LIKE LINE OF l_tr_dimensions,          "dimension reference
      l_dimname          TYPE rsmds_dimname,                    "dimension name
      l_sx_selection_cs  LIKE LINE OF i_thx_selection_cs,       "work area for single characteristc RANGE table
      l_r_universe       TYPE REF TO cl_rs_infoobject_universe. "reference for InfoObject universe

    TRY.

*       Transform selection set for outbound (=target)
*       characteristic 0PASSFORM to RANGE table
        CALL METHOD i_r_selset_outbound->to_ranges
          CHANGING
            c_t_ranges = i_rt_chavl_cs.

*       Transform complete outbound selection set to extended RANGES table
*       (The following step can be skipped if I_THX_SELECTION_CS is not used
*        by the 3.X implemention as it is the case here)

*       Get reference to InfoObject universe (singleton)
        l_r_universe = cl_rs_infoobject_universe=>get_instance( ).
*       Get all dimensions (i.e. fields) from outbound selection which are
*       restricted
        l_tr_dimensions = i_r_selset_outbound_complete->get_dimensions( ).
        LOOP AT l_tr_dimensions INTO l_r_dimension.
          CLEAR l_sx_selection_cs.
*         Get dimension name (= field name)
          l_dimname = l_r_dimension->get_name( ).
*         Transform dimension name to InfoObject name
          l_sx_selection_cs-chanm = l_r_universe->dimname_to_iobjnm(
          l_dimname ).
*         Project complete outbound selection set to current dimension and
*         and convert to RANGE table representation
          CALL METHOD i_r_selset_outbound_complete->to_ranges
            EXPORTING
              i_r_dimension = l_r_dimension
            CHANGING
              c_t_ranges    = l_sx_selection_cs-rt_chavl.
          APPEND l_sx_selection_cs TO i_thx_selection_cs.
        ENDLOOP.

*$*$ Insert your 3.X implementation between here ... *-----------------*

        DATA:
          l_s_selection      LIKE LINE OF c_t_selection.

        l_s_selection-fieldnm = 'PASSFORM'.
        CLEAR l_s_selection-high.
        IF space IN i_rt_chavl_cs.
*         Select all values from source except ...
          l_s_selection-sign   = 'E'.
          l_s_selection-option = 'EQ'.
          IF NOT 'MR'  IN i_rt_chavl_cs.
*           ... 'HERR' and ...
            l_s_selection-low    = 'HERR'.
            APPEND l_s_selection TO c_t_selection.
          ENDIF.
          IF NOT 'MRS' IN i_rt_chavl_cs.
*           ... 'FRAU'
            l_s_selection-low    = 'FRAU'.
            APPEND l_s_selection TO c_t_selection.
          ENDIF.
        ELSE.
          IF 'MR'  IN i_rt_chavl_cs.
            l_s_selection-sign   = 'I'.
            l_s_selection-option = 'EQ'.
            l_s_selection-low    = 'HERR'.
            APPEND l_s_selection TO c_t_selection.
          ENDIF.
          IF 'MRS' IN i_rt_chavl_cs.
            l_s_selection-sign   = 'I'.
            l_s_selection-option = 'EQ'.
            l_s_selection-low    = 'FRAU'.
            APPEND l_s_selection TO c_t_selection.
          ENDIF.
          IF c_t_selection IS INITIAL.
*           Other values cannot occur as transformation result
*           ==> source will not contribute to query result
*                 with any record 
*           ==> return empty selection (e.g. include and exclude initial value)
            l_s_selection-sign   = 'I'.
            l_s_selection-option = 'EQ'.
            CLEAR: l_s_selection-low, l_s_selection-high.
            APPEND l_s_selection TO c_t_selection.
            l_s_selection-sign   = 'E'.
            APPEND l_s_selection TO c_t_selection.
          ENDIF.
        ENDIF.
        e_exact = rs_c_false.  "This inversion is exact

*$*$ ... and here *----------------------------------------------------*
*       Convert 3.X inversion result to new method interface
        c_r_selset_inbound = i_r_universe_inbound->create_set_from_ranges(
                               i_fieldname_dimension = 'FIELDNM'
                               i_t_ranges            = c_t_selection ).
        c_exact = e_exact.

      CATCH cx_rsmds_input_invalid
            cx_rsmds_input_invalid_type.

*       Should not occur 
*       If the exception occurs request all values from source
*       for this routine to be on the save side
        c_r_selset_inbound = cl_rsmds_set=>get_universal_set( ).
        c_exact = rs_c_false. "Inversion is no longer exact

    ENDTRY.

*   Finally, add (optionally) further code to transform outbound projection
*   to inbound projection
*
*   Please note:
*
*   In 3.X you did this mapping before entering the source code editor.
*   For the transformation in SAP NetWeaver BI 7.0 the passed inbound projection
*   C_TH_FIELDS_INBOUND already contains all fields from the source structure
*   which are required by this routine according to the rule definition.
*   Remove lines from this internal table if the corresponding field 
*   is not requested for the query.

*   Check if outbound characteristic 0PASSFORM (field name PASSFORM)
*   is requested for the drilldown state of the query
    READ TABLE i_th_fields_outbound
         WITH TABLE KEY segid     = 1           "Primary segment
                        fieldname = 'PASSFORM'
         TRANSPORTING NO FIELDS.
    IF sy-subrc EQ 0.
*     Characteristic 0PASSFORM is needed
*     ==> request (only) field PASSFORM from the source for this routine
      DELETE c_th_fields_inbound
        WHERE NOT ( segid     EQ 1          OR
                    fieldname EQ 'PASSFORM'    ).
    ELSE.
*     Characteristic 0PASSFORM is not needed
*     ==> don't request any field from source for this routine
      CLEAR c_th_fields_inbound.
    ENDIF.

*$*$ end of inverse routine - insert your code only before this line *-*
  ENDMETHOD.                    "invert_0PASSFORM
ENDCLASS.                    "routine IMPLEMENTATION