Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

 

Applies to:

CRM 6.0/7.0

Summary

This wiki explains how to perform validations on pricing condition types using java routines with a simple example.

Author(s):  

   
Company:     Accenture
Created on:    09/08/2010
Author(s) Bio
Arun Kumar is a senior CRM developer working with Accenture.

Table of Contents

Introduction

There are scenarios where certain validations need to carried out when pricing is triggered. For example, when a reprice/complete re-price is triggered or when adding a manual condition type. In CRM since pricing is executed by the Sales Pricing Engine, the presentation layer is mostly used to implement any such validations. However, this doesn't prevent pricing from being executed in case of any failed validations. So the better approach for condition type validation is to use requirement routines thus preventing access to the condition.

This wiki explains how to perform condition validations in IPC using a requirement routine with a simple example.


Scenario

The scenario is to restrict user from adding more than one manual entry for the same condition type. If user adds an existing condition type more than once, an error message should be displayed and the condition exclusion indicator must be set. 

Create a manual condition type and add it to a pricing procedure.


Create a requirement routine


Requirement userexits are used during condition finding on pricing procedure step/counter level and on condition access step level.Assign a formula number for the userexit ZYIDP_CHECK and assign attribute PRC_INDICATOR from the item communication structure 


Assign the requirement routine 601 to condition type YIDP in the pricing procedure.


Create an userexit using any Java IDE, the userexits class must be inherited from RequirementAdapter. Use library com.sap.spe.base.util.event.WarningStatusEvent to throw warning messages when validation fails.

private WarningStatusEvent event =
new WarningStatusEvent(validateYIDP.class,"ZMSG",108,args,"Msg","Context");

Overwrite the method checkRequirement. If this method returns false, the current access in not made.

public boolean checkRequirement(IConditionFindingManagerUserExit item, IStep step, IAccess access)

Read the pricing indicator attribute passed to the userexit

String pricingIndicator = item.getAttributeValue("PRICING_INDICATOR");

Get item pricing condition types into an array and clear the status message initially.

IPricingItemUserExit pricingItem = (IPricingItemUserExit) item;
IPricingConditionUserExit pricingCondition[] = pricingItem.getUserExitConditions()
pricingItem.clearStatusMessage(event);

In the pricing conditions check the number of occurrences of condition type YIDP. If YIDP is added more than once then set the warning message and return the check result, 'false' to avoid the access.

pricingItem.setStatusMessage(event);
return false;

Coding:

import com.sap.spe.condmgnt.customizing.IAccess;
import com.sap.spe.condmgnt.customizing.IStep;
import com.sap.spe.condmgnt.finding.userexit.IConditionFindingManagerUserExit;
import com.sap.spe.condmgnt.finding.userexit.RequirementAdapter;
import com.sap.spe.pricing.transactiondata.userexit.IPricingItemUserExit;
import com.sap.spe.pricing.transactiondata.userexit.IPricingConditionUserExit;
import com.sap.spe.base.util.event.WarningStatusEvent;

public class validateYIDP extends RequirementAdapter

{
String args[] = { };
boolean popup = false;

private WarningStatusEvent event = new WarningStatusEvent(validateYIDP.class,"ZMSG",108,args,"Msg","Context");
public boolean checkRequirement(IConditionFindingManagerUserExit item, IStep step, IAccess access);

{
int count = 0;
String lv_ctype = null;
//read pricing indicator flag
String pricingIndicator = item.getAttributeValue("PRICING_INDICATOR");
IPricingItemUserExit pricingItem = (IPricingItemUserExit) item;
//get all user exit conditions
IPricingConditionUserExit pricingCondition[] = pricingItem.getUserExitConditions();
pricingItem.clearStatusMessage(event);
 
//loop into the condition types & increment the counter flag if condition type YIDP is found{*}{color}
for(int j=0;j < pricingCondition.length;j++)
{
  if(pricingCondition[j].getConditionTypeName() != null)
  {
    if(pricingCondition[j].getConditionTypeName().trim().equalsIgnoreCase("YIDP"))
    {
      count = count + 1;
    }
  }
}

//display warning message & condition exclusion flag if counter > 1

if (count > 1)
{
  pricingItem.setStatusMessage(event);
  return false;
}
else
{
  pricingItem.clearStatusMessage(event);
  return pricingIndicator.equals("X");
}
}
}



Related Content

OSS Note 809820   Note containing IPC document and the prepared eclipse project.

Regards,
Arun Kumar

Useful Information

Condition type validations using IPC routines 

3 Comments

  1. Former Member

    Hi Arun,

    good wiki!

    Can I ask you a question regarding the userexits?

    Would you think it is possible to set a condition of all subitems to the value of the main item (for the same condition)? The problem I have: main items are getting created and they get assigned a manual discount (in%). This value should then be copied to all subitems of the main item.

    Customzing of the pricing procedure doesn't allow me to do so (as far as I know now). And ABAP  exits cannot deal with it. So I am trying to implement a java exit. But I am not sure if it is possible. I started with a value formula exit. It would be called when the main item condition is manually changed. But how to find the subitems of this main item and then change their conditions?

    Thanks for any comment from your side.

    Regards,

    Thorsten

  2. Hi Thorsten,

    Yes, it is possible to set a condition of allsubitems to the value of the main item. You can loop into the line items then loop into its condition types, read a condition value or update a condition value and do a lot of stuff using ValueFormulaAdapter.

    To loop into all items,

    public BigDecimal overwriteConditionValue(IPricingItemUserExit pricingItem,
       IPricingConditionUserExit pricingCondition) {
     
    <some code like declarations & stuff...>
     
    IPricingItemUserExit[] prItems = pricingItem.getSubPricingItemsUserExitRecursive();    --> this will return all subitems
    for (int i = 0; i < prItems.length; i++)       --> loop into the subitems
      {
    	if (!prItems[i].isStatistical())
    	   {
    		IPricingConditionUserExit[] conditions = prItems[i].getUserExitConditions();
    		IPricingConditionUserExit PriConditions  = null;
    		for (int j = 0; j < conditions.length; j++)    --> loop into the condition types
    		    {
     				PriConditions = (IPricingConditionUserExit) conditions[j];  --> get condition type
    				lv_conditionValue = PriConditions.getConditionValue().getValue();
    		     }
    	   }
    }
    

    Hope this helps.

    Cheers,
    Arun

  3. Hi Arun,

    We have a scenario where there are existing documents in the system and we now implemented a requirement formula for a condition type. The requirement formula returns false based on the new logic, however when I try to reprice the document (using option retain manual conditions) the condition for which the requirement fails is not removed from the document. Manually removing is not an option. Can you please let me know how to overcome this?

    Pradeep