Skip to Content

In most cases, we use variant functions to retrieve desired output value back into the configuration with the help of FUNCTION call from object dependencies.

It is nicely explained in here already by one of our friend.

In this write up, I would like to explain what is PFUNCTION and how it is different from FUNCTION call. I came across with a situation where we need to read all the configuration data and I can not specify the exact inputs for this function. Because the input parameters get changed for each and every product.

New way of calling the function module in object dependency is that simply change the procedure to PFUNCTION instead of calling it as FUNCTION, then we don’t really need to specify any arguments to it. When a function module is called with PFUNCTION, it populates GLOBALS structure which has an instance of the configuration. Using the Instance number we can use any of the function module in CUPR function group. For example, use CUPR_GET_VAL to read any characteristic value from the configuration and use CUPR_SET_VAL to set a value back into the configuration).

The main advantage using PFUNCTION is that we don’t need to specify any arguments (input & output parameters) and instance number will be sent automatically to read the configuration data.

I found this is so helpful in terms of getting and setting data in variant configuration using variant functions.

Let’s see a simple example with a PFUNCTION call for a function module

1. List of characteristics created. VCH_ARKTX will get populated with concatenated text with Material, Length, Width and Thickness.

2. Create Variant function: Transaction code: CU65. Function module ZVF_GLASS is created

and assigned to this variant function.

It does not has any input or output parameters.

 

Function Module interface

 

3. Call Variant function from the configuration.

Assign a procedure to the configuration profile and call variant function as shown below.

Procedure: VDP_PFUNCTION

PFUNCTION ZVF_GLASS( )

 

Test VC model  

Material number characteristic is a referenced characteristic for VBAP-MATNR. So material will get populated automatically. Material description will get populated from pfunction call upon providing Length, Width and Thickness.

Variant function will be called and it outputs Item text into the configuration.

 

Source code of the function module

 

FUNCTION zvf_glass.
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     REFERENCE(GLOBALS) LIKE  CUOV_00 STRUCTURE  CUOV_00
*”  TABLES
*”      QUERY STRUCTURE  CUOV_01
*”      MATCH STRUCTURE  CUOV_01
*”  EXCEPTIONS
*”      FAIL
*”      INTERNAL_ERROR
*”———————————————————————-
TYPE-POOLScudbt.
DATAval          TYPE cudbt_val,
lv_length    TYPE char10,
lv_width     TYPE char10,
lv_thickness TYPE char10,
lv_desc      TYPE char30,
lv_matnr     TYPE matnr.

* Get Material
CALL FUNCTION ‘CUPR_GET_VAL’
EXPORTING
instance       globalsroot
characteristic ‘VCH_MATNR’
IMPORTING
val            val
EXCEPTIONS
not_found      01
OTHERS         02.
IF sysubrc 0.
lv_matnr valatwrt.
ENDIF.
* Get length
CALL FUNCTION ‘CUPR_GET_VAL’
EXPORTING
instance       globalsroot
characteristic ‘VCH_LENGTH’
IMPORTING
val            val
EXCEPTIONS
not_found      01
OTHERS         02.
IF sysubrc 0.
CALL FUNCTION ‘MC_FLTP_CHAR’
EXPORTING
fc_a_fld valatflv
fc_iva   ‘X’
fc_nk    ‘0’
IMPORTING
fc_r_fld lv_length.
ENDIF.

* Get Width
CALL FUNCTION ‘CUPR_GET_VAL’
EXPORTING
instance       globalsroot
characteristic ‘VCH_WIDTH’
IMPORTING
val            val
EXCEPTIONS
not_found      01
OTHERS         02.
IF sysubrc 0.
CALL FUNCTION ‘MC_FLTP_CHAR’
EXPORTING
fc_a_fld valatflv
fc_iva   ‘X’
fc_nk    ‘0’
IMPORTING
fc_r_fld lv_width.
ENDIF.

* Get Thickness
CALL FUNCTION ‘CUPR_GET_VAL’
EXPORTING
instance       globalsroot
characteristic ‘VCH_THICKNESS’
IMPORTING
val            val
EXCEPTIONS
not_found      01
OTHERS         02.
IF sysubrc 0.
CALL FUNCTION ‘MC_FLTP_CHAR’
EXPORTING
fc_a_fld valatflv
fc_iva   ‘X’
fc_nk    ‘0’
IMPORTING
fc_r_fld lv_thickness.
ENDIF.

***** Populate Product description to Configuration
CONDENSE lv_width.
CONDENSE lv_length.
CONDENSE lv_thickness.
CONCATENATE lv_length lv_width lv_thickness INTO lv_desc SEPARATED BY ‘X’.
CONCATENATE lv_matnr lv_desc INTO lv_desc SEPARATED BY ‘,’.

valatfor ‘CHAR’.
valatwrt lv_desc.
CALL FUNCTION ‘CUPR_SET_VAL’
EXPORTING
instance               globalsroot
characteristic         ‘VCH_ARKTX’
val                    val
EXCEPTIONS
unknown_instance       1
unknown_characteristic 2
internal_error         3
OTHERS                 4.
IF sysubrc <> 0.
* Implement suitable error handling here
ENDIF.

ENDFUNCTION.

 

Following function modules from function group CUPR can be used in this variant function.

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