call variant function into object depnedinces

Upload: mohameds1988

Post on 24-Feb-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    1/12

    Generated by Jive on 2016-01-03+01:00

    1

    Variant Functions with an example

    Hi Friends,

    While doing the Variant configuration, we may came across scenarios where std. syntax of VC will not be

    sufficient. For this type of scenarios, we can use Variant functions to achieve the desired functionality. Variant

    functions will use Function Modules, here we have to write the code using ABAP.

    OverviewVariant functions allow us to integrate the function modules with all types of object dependencies. In the

    object dependencies we need to use the syntax for calling the function module as well as input and output

    parameters.

    Variant conditions used where standard syntax is not sufficient to map desired functionality. This may be

    possible in following cases.

    Complex processing of Char. values Evaluation of database tables that cannot be addressed via reference characteristics. Complex validity checks of allowed char. values. Generation of custom information messages.

    Example:Using variant function to concatenate values of three characteristics into another characteristic.

    Chars Values

    Processor Core i7 Core i5 Core i3

    Hard Disk 500 GB 750 GB 1 TB

    RAM 2 GB 4 GB 6 GB

    Label Above 3 char selected values should be

    concatenated and displayed as label.

    Creation of Variant Function:

    T.Code: CU65

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    2/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    2

    For creating variant function we have to provide required input and output parameters for the function module.

    Give Function Name and Description Click on Characteristics

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    3/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    3

    Assign required input and output characteristics and save the variant function. In the above example

    PROCESSOR, HARD_DISK, RAM are input parameters.

    Creating Function Module:

    Note: For creating Function Modules requires developer access.

    Open the variant function in change mode in CU66T.code and click on Function Module button.

    Function builder initial screen will appear system will propose the function module name click on Create button.

    Enter the required details and press save button.

    Interface of the Function Module

    Import Parameters

    Parameter Name Typing Reference Field Content

    GLOBALS LIKE CUOV_00 Global parameters

    for calling a function.

    However, the list of fields

    currently only contains

    the date.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-64352-3-714525/3.png
  • 7/25/2019 Call Variant Function Into Object Depnedinces

    4/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    4

    Tables

    Parameter Name Typing Reference Type Content

    QUERY LIKE CUOV_01 Table of input parameters

    and the expected output

    parameters

    MATCH LIKE CUOV_01 Table of output

    parameters

    All partial fields except

    ATCIO must be filled in a

    MATCH entry (especially

    format ATFOR)

    Structure CUOV_01comprises the following fields:

    VARNAM (characteristic name) ATFOR (format of the value) ATWRT (alphanumeric characteristic value in internal format) ATFLV (numeric characteristic value) ATCIO (Indicator: input (I) or output (O) parameter)

    The fields ATFOR, ATWRT, and ATFLV only have values assigned for input parameters.

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    5/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    5

    Exceptions:

    FAIL This exception shows that the condition represented

    by the function is not fulfilled.

    INTERNAL_ERROR This exception shows that a runtime error has

    occurred processing the function.

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    6/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    6

    Source Code :Used for writing your own logic for the function module using ABAP.

    The following help functions are supported for accessing import parameters:

    CUOV_GET_FUNCTION_ARGUMENT: Read characteristics from the input parameters.

    CUOV_GET_FUNCTION_ARGUMENT: Transfer value of characteristics to Variant configuration.

    Write the ABAP code and Save and activate the function module.

    Press back button, system will display the Change Function transaction. Change the status to1 Released

    and Save Function.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-64352-3-714529/7.png
  • 7/25/2019 Call Variant Function Into Object Depnedinces

    7/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    7

    Call Variant Function

    Write the Procedure and assign it to configuration profile of the material. Below is the procedure for this

    example.

    FUNCTION ZCOMP_LABEL

    (PROCESSOR = $ROOT.PROCESSOR,

    HARD_DISK = $ROOT.HARD_DISK,

    RAM = $ROOT.RAM,

    LABEL = $SELF.LABEL)

    The characteristics on the left-hand side are characteristics of the function. The characteristics on the right-

    hand side are characteristics of the PC.

    Characteristic LABEL must be referred to with the variable $SELF, because LABEL is a characteristic of the

    object currently being processed. Otherwise, values cannot be inferred. The default object $ROOT is assumed

    for the other characteristics.

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    8/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    8

    Testing

    As soon as all values assigned to the characteristics of variant function, function module will sets the value for

    LABEL.

    Note:

    When you call a user-defined function module, SAP Variant Configuration no longer has control of possible

    error situations: the person who writes the function module can use all ABAP language elements, but has sole

    responsibility for the code.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-64352-3-714535/9.png
  • 7/25/2019 Call Variant Function Into Object Depnedinces

    9/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    9

    Example code for Function Module

    FUNCTION ZCOMP_LABEL.

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

    *"*"Local Interface:

    *" IMPORTING

    *" REFERENCE(GLOBALS) LIKE CUOV_00 STRUCTURE CUOV_00

    *" TABLES

    *" QUERY STRUCTURE CUOV_01

    *" MATCH STRUCTURE CUOV_01

    *" EXCEPTIONS

    *" FAIL

    *" INTERNAL_ERROR

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

    DATA : LV_PROCESSOR TYPE CUOV_01-ATWRT,

    LV_HARDDISK TYPE CUOV_01-ATWRT,

    LV_RAM TYPE CUOV_01-ATWRT,

    LV_LABEL TYPE CUOV_01-ATWRT.

    REFRESH MATCH.

    CALL FUNCTION 'CUOV_GET_FUNCTION_ARGUMENT'

    EXPORTING

    ARGUMENT = 'PROCESSOR'

    IMPORTING

    * VTYPE =

    SYM_VAL = LV_PROCESSOR

    * NUM_VAL =

    * IO_FLAG =

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    10/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    10

    TABLES

    QUERY = QUERY

    EXCEPTIONS

    ARG_NOT_FOUND = 1

    OTHERS = 2

    .

    IF SY-SUBRC 0.

    * Implement suitable error handling here

    ENDIF.

    CALL FUNCTION 'CUOV_GET_FUNCTION_ARGUMENT'

    EXPORTING

    ARGUMENT = 'HARD_DISK'

    IMPORTING

    * VTYPE =

    SYM_VAL = LV_HARDDISK

    * NUM_VAL =

    * IO_FLAG =

    TABLES

    QUERY = QUERY

    EXCEPTIONS

    ARG_NOT_FOUND = 1

    OTHERS = 2

    .

    IF SY-SUBRC 0.

    * Implement suitable error handling here

    ENDIF.

    CALL FUNCTION 'CUOV_GET_FUNCTION_ARGUMENT'

    EXPORTING

    ARGUMENT = 'RAM'

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    11/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    11

    IMPORTING

    * VTYPE =

    SYM_VAL = LV_RAM

    * NUM_VAL =

    * IO_FLAG =

    TABLES

    QUERY = QUERY

    EXCEPTIONS

    ARG_NOT_FOUND = 1

    OTHERS = 2

    .

    IF SY-SUBRC 0.

    * Implement suitable error handling here

    ENDIF.

    CONCATENATE LV_PROCESSOR LV_HARDDISK LV_RAM INTO LV_LABEL SEPARATED BY '|'.

    CALL FUNCTION 'CUOV_SET_FUNCTION_ARGUMENT'

    EXPORTING

    ARGUMENT = 'LABEL'

    VTYPE = 'CHAR'

    SYM_VAL = LV_LABEL

    * NUM_VAL =

    TABLES

    MATCH = MATCH

    EXCEPTIONS

    EXISTING_VALUE_REPLACED = 1

    OTHERS = 2

    .

    IF SY-SUBRC 0.

    * Implement suitable error handling here

    ENDIF.

  • 7/25/2019 Call Variant Function Into Object Depnedinces

    12/12

    Variant Functions with an example

    Generated by Jive on 2016-01-03+01:00

    12

    ENDFUNCTION.