Skip to Content

Background

We have optional variables at the query level. User entry is expected for at least one optional variable. Based upon entry of that variable, query calculation and execution is possible. When we click on either “Execute” or “Check” button it shall check entry of variable i.e. variable checking at query level instead of object level.

Similarly, based on input value of one mandatory variable second variable entry is optional/mandatory. Such validation is also possible at query level .

I am trying to put together such 2 scenarios. I am sure there can be other  scenarios where we need validation of variable at query level.

Scenario 1:

We have 2 optional selection variables in a query. Among these optional selection variables entry of  at least one is mandatory to execute query.

Example:

We have profit center as well as cost center as optional selection variable and at least one have to be entered to execute query. In such case variable entry need to be check once user has finished entry of each variable. If user has neither selected profit center nor cost center, an error message shall be flashed with message “Enter either profit center or cost center to proceed with query execution”.

Solution:

Prerequisite: Optional selection variables are defined for each object in query designer. In our case for profit center and cost center.</p><p>Customer exit code is required in BW to validate variable entry at query level.

Pseudo code provided as below

Declare check variable and proceed with query level variable checking.

DATA:   var1 TYPE wdy_boolean.

WHEN ‘<Query Technical Name>’.

      CLEAR var1.

*   Check for Profit Center
      READ TABLE i_t_var_range TRANSPORTING NO FIELDS
        WITH KEY vnam = ‘<Profit Center Selection variable Technical Name>’.
      IF sysubrc = 0.
        var1= abap_true.
      ENDIF.

*   Check for Cost Center
      READ TABLE i_t_var_range TRANSPORTING NO FIELDS
        WITH KEY vnam = ‘<Cost Center Selection variable Technical Name>.
      IF sysubrc = 0.
        var1 = abap_true.
      ENDIF.

*   error handling
      IF var1 = abap_false.

*     message output
        CALL FUNCTION ‘RRMS_MESSAGE_HANDLING’
          EXPORTING

            i_class  = ‘<Message Class name>’
            i_type   = ‘E’
            i_number = ‘<Message Number>’
            i_msgv1  = ‘Profit Center’
            i_msgv2  = ‘Cost Center’.
        RAISE no_replacement.
      ENDIF.

Scenario 2 :

Based on input Value of one mandatory variable second variable entry is optional/mandatory.

Example: If currency type is not having default value in that case entry of currency is mandatory. For currency type, mandatory selection variable is used where default value is ‘10’. In such case currency entry is not mandatory but if user changes ‘10’ to some other value in that case currency entry is mandatory.  It will help to do calculation based on currency selected in combination with currency type.

Solution :

Prerequisite:  An individual selection variable has been defined for each object in query designer. In our case, currency type selection variable having default value as ‘10’, single value and entry is mandatory.

Currency selection variable having  single value, optional, ready for input.

Customer exit code is required in BW to validate variable entry at query level.

Pseudo code provided as below </p><p>Declare check variable and proceed with query level variable checking.

DATA:   var2 TYPE wdy_boolean,
        var3 TYPE wdy_boolean.

WHEN ‘<Query Technical Name>’.
      CLEAR: var2, var3.

*Check for currency Type
      READ TABLE i_t_var_range INTO loc_var_range
        WITH KEY vnam = ‘<Currency Type Selection variable Technical Name>’.
      IF loc_var_rangelow = 010.
        var2 = abap_true.
      ENDIF.

*   Check for Currency
       READ TABLE i_t_var_range TRANSPORTING NO FIELDS
        WITH KEY vnam = ‘<Currency Selection variable Technical Name>’.
      IF sysubrc EQ 0.
        var3 = abap_true.
      ENDIF.

*   error handling
      IF var2 EQ abap_false
        AND var3 EQ abap_false.

*     message output
        CALL FUNCTION ‘RRMS_MESSAGE_HANDLING’
          EXPORTING
            i_class  = ‘<Message Class name>’
            i_type   = ‘E’
            i_number = ‘<Message Number>’
            i_msgv1  = ‘Please’
            i_msgv2  = ‘Enter Currency’.

       RAISE no_replacement.

      ENDIF.

Based on needs both scenarios can be utilized in same query as well.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply