cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a function module in VC

Former Member
0 Kudos

Hi,

I want to call a function module for an addition formula which shall calculate and infer the value.

eg. quantities of 5 different characteristics (of numeric data) is to be summed up and inferred against the 6th characteristic.

I want to know the detailed process to create a Variant Function and use it in a dependency.

Request to please advise the steps, type of dependency and its code.

Regards,

Rajesh Mohapatra

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Dear Rajesh,

I also wanted to learn how to do that, your post motivated me to use a bit of freetime and investigate on the subject. I finally made my function work, so here are the tips.

The example is very simple, just a variant function with two inputs and which multiplies inside the input values and transfer that result to the output ( 3 x 4 => 12 ).

Deducting how to add five values or any other logic would be easier starting from there.

STEP 1: Create Variant Class for the product. I imagine you already have that. In my case its name is ZVC_CLASS, you have already a material assigned to the class, a configuration profile, etc....

STEP 2: Create Three Characteristics Z_NUM_CH_1,Z_NUM_CH_2,Z_NUM_CH_3 the three of numeric type

STEP 3: Assign characteristics from step 2 into class ZVC_CLASS

STEP 4: Create the function module with the code given below. I put the name ZVC_FUN_TEST

FUNCTION ZVC_FUN_TEST.

*"----


""Interfase local

*" IMPORTING

*" REFERENCE(GLOBALS) TYPE CUOV_00

*" TABLES

*" QUERY STRUCTURE CUOV_01

*" MATCH STRUCTURE CUOV_01

*" EXCEPTIONS

*" FAIL

*" INTERNAL_ERROR

*"----


*- Inicializar los valores.

DATA:

GV_VALOR_FINAL TYPE CUOV_01-ATFLV,

GV_VALOR_NUM1 TYPE CUOV_01-ATFLV,

GV_VALOR_NUM2 TYPE CUOV_01-ATFLV.

CLEAR:

gv_valor_final,

gv_valor_num1,

gv_valor_num2.

CALL FUNCTION 'CUOV_GET_FUNCTION_ARGUMENT'

EXPORTING

ARGUMENT = 'Z_NUM_CH_1'

IMPORTING

  • VTYPE = P_VTYPE1

  • SYM_VAL = P_VALOR_SYM1

NUM_VAL = gv_valor_num1

  • IO_FLAG =

TABLES

QUERY = QUERY

EXCEPTIONS

ARG_NOT_FOUND = 01.

IF SY-SUBRC <> 0.

RAISE INTERNAL_ERROR.

ENDIF.

CALL FUNCTION 'CUOV_GET_FUNCTION_ARGUMENT'

EXPORTING

ARGUMENT = 'Z_NUM_CH_2'

IMPORTING

  • VTYPE = P_VTYPE1

  • SYM_VAL = P_VALOR_SYM1

NUM_VAL = gv_valor_num2

  • IO_FLAG =

TABLES

QUERY = QUERY

EXCEPTIONS

ARG_NOT_FOUND = 01.

IF SY-SUBRC <> 0.

RAISE INTERNAL_ERROR.

ENDIF.

*- Calculate final value

gv_valor_final = gv_valor_num1 * gv_valor_num2. "Especifico de c/u.

DATA: VTYPE TYPE CUOV_01-ATFOR.

VTYPE = 'NUM'.

CALL FUNCTION 'CUOV_SET_FUNCTION_ARGUMENT'

EXPORTING

ARGUMENT = 'Z_NUM_CH_3'

VTYPE = VTYPE

NUM_VAL = gv_valor_final

TABLES

MATCH = MATCH

EXCEPTIONS

EXISTING_VALUE_REPLACED = 01.

IF SY-SUBRC <> 0.

RAISE INTERNAL_ERROR.

ENDIF.

ENDFUNCTION.

STEP 5: Activate the function module for Variant Configuration in transaction CU65, put there your function module, release int and in button characteristics write Z_NUM_CH_1,Z_NUM_CH_2,Z_NUM_CH_3. Flag the first two lines as they are inputs.

STEP 6: Create a Dependency ZVC_PROC_TEST of type Procedure to call the function with this code:

000010 Function ZVC_FUN_TEST

000020 (Z_NUM_CH_1 = $root.Z_NUM_CH_1,

000030 Z_NUM_CH_2 = $root.Z_NUM_CH_2,

000040 Z_NUM_CH_3 = $self.Z_NUM_CH_3)

STEP 7: Lets say I want to calculate the multiplication only upon the selection of another characteristic "Calculate" YES/NO. For this I create a characteristic in CT04 Z_CALCULATE type CHAR 1 with possible values Y or N. For the value Y y add the procedure ZVC_PROC_TEST so that formula only activates on Y.

STEP 8: Add characteristic Z_CALCULATE to class ZVC_CLASS

STEP 9: VA01, it should work

Former Member
0 Kudos

Hi Sebastian,

Thanks for the input.

I resolved my problem which was basically because of FM interface error.

Regards,

Rajesh Mohapatra

Jelena
Active Contributor
0 Kudos

Unable to understand the question. What is "variant function"? What do you mean by VC?

In any case, I'd suggest to involve a qualified ABAP developer in any development effort.