Quantcast
Channel: SCN : Document List - SAP ERP PLM - Classification and Variant Configuration
Viewing all articles
Browse latest Browse all 27

LO-VC: counting the number of selected values in multiple-value characteristic

$
0
0

For specific reasons, it may be necessary to count the number of values that the user has selected, in a multiple-value characteristic.

 

The task could easily be performed if the characteristic values are well defined, that is, they are available in the characteristic 'Values' tab: this can be accomplished, for instance, by means of an object dependency that will go through the values, counting the selected ones.

But what about if the values are dynamically set?

 

In such a case, we will anyway use an object dependency that will call a variant function (user-defined function), that in turn will count the selected values.


The multiple values characteristic will not be part of the function interface, as it is not possible to use this kind of characteristic in variant function. But this is not blocking us to read anyway the characteristic selected values, and return their count to another characteristic.

 

Let's try to implement a simple trial about it.

 

So, we will have a multiple values characteristic, here I called it TEST_FLAVIO

img20001.png

 

and a single value characteristic, TEST_FLAVIO_COUNT, that will contain the number of  values that have been selected in the previous characteristic. This will be the output of the user defined function.

img20002.png


We have to also define an input characteristic for the same function:  we could use a dummy one, with a default value 'X', for example.

img20003.png

 

All these characteristics will be part of our class.

 

As anticipated, we need an user defined function, here called ZTEST_FLAVIO. It's 'Characteristics' section will look like the following:

img20004.png

 

The function module code itself, will be the following:

 

FUNCTION ZTEST_FLAVIO.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(GLOBALS) TYPE  CUOV_00

*"  TABLES

*"      MATCH STRUCTURE  CUOV_01

*"      QUERY STRUCTURE  CUOV_01

*"  EXCEPTIONS

*"      FAIL

*"      INTERNAL_ERROR

*"----------------------------------------------------------------------

  DATA: i_used_values   TYPE cudbt_vallist,

        w_char          TYPE cudbt_key,

        w_instance      TYPE cudbt_instance,

        w_counter       TYPE i,

        w_value         TYPE cuov_01-atflv.

 

* Initializing the instance number

  IF globals-self ISINITIAL.

    w_instance = 1.

  ELSE.

    w_instance = globals-self.

  ENDIF.

 

* Reading the chosen values in the multiple value characteristic

  w_char = 'TEST_FLAVIO'.

 

  CALLFUNCTION'CUPR_GET_VALLIST'

    EXPORTING

      instance              = w_instance

      characteristic        = w_char

    IMPORTING

      values                = i_used_values

    EXCEPTIONS

      unknown_instance      = 1

      unknown_characteristic = 2

      not_multivalued       = 3

      not_found             = 4

      internal_error        = 5

      OTHERS                = 6.

  IF sy-subrc = 4.

    CLEAR i_used_values.

    REFRESH i_used_values.

  ENDIF.

 

* Counting the values, and send back the number

  IF i_used_values[] ISNOTINITIAL.

    DESCRIBETABLE i_used_values LINES w_counter.

    IF w_counter >0.

      MOVE w_counter TO w_value.

      CALLFUNCTION'CUOV_SET_FUNCTION_ARGUMENT'

        EXPORTING

          argument               = 'TEST_FLAVIO_COUNT'

          vtype                  = 'NUM'

          num_val                = w_value

        TABLES

          match                  = match

        EXCEPTIONS

          existing_value_replaced = 1

          OTHERS                 = 2.

      IF sy-subrc <>0.

      ENDIF.

    ENDIF.

  ENDIF.

 

ENDFUNCTION.

 

What the code is doing is quickly explained: first, thanks to the FM 'CUPR_GET_VALLIST', we read the multiple values characteristic and save them in a local variable. Then, we just count them and return this value to the output characteristic by means of the FM 'CUOV_SET_FUNCTION_ARGUMENT'.

 

Now, we need an object dependency (Procedure) that will call the user defined function. Here it is:

img20005.png

 

We will add it to our configuration profile.

 

That's all. Let's go and give this a quick test inside CU50:

img20006.png

Here above, 4 values have been selected in the multiple values characteristic. Change them, and the counting characteristic will change accordingly:

img20007.png

Thanks.

 

Flavio


Viewing all articles
Browse latest Browse all 27

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>