cancel
Showing results for 
Search instead for 
Did you mean: 

Using the statistical value in the cumulated formula 036

0 Kudos

Dear Experts,

I want to use the statistical value the instead of the Net Value. Also I looked point 9b in the note 844141 from ECC. We understood that we needed to use the statistical value (XWORKM, for example) instead of the Net Value.


We created a copy of value formula 036 in the customer namespace (936). The replace the line ICurrencyValue netValue = pricingItem.getNetValue() with

ICurrencyValue netValue = pricingItem.getSubtotal(PricingCustomizingConstants.ConditionSubtotal.SUBTOTAL_M) in the copied formula 936.


Unfortunately the formula 936 did not work.

Please help me,
Alex.

package masterdata.pricing.userexits;

import java.math.BigDecimal;

import com.sap.spe.conversion.ICurrencyUnit;
import com.sap.spe.conversion.ICurrencyValue;
import com.sap.spe.pricing.customizing.PricingCustomizingConstants;
import com.sap.spe.pricing.transactiondata.PricingTransactiondataConstants;
import com.sap.spe.pricing.transactiondata.userexit.IPricingConditionUserExit;
import com.sap.spe.pricing.transactiondata.userexit.IPricingItemUserExit;
import com.sap.spe.pricing.transactiondata.userexit.ValueFormulaAdapter;

public class ZCummulationCondition2 extends ValueFormulaAdapter {
public BigDecimal overwriteConditionValue(IPricingItemUserExit pricingItem,
         IPricingConditionUserExit pricingCondition) {
         if (pricingCondition.getStructureConditionFlag() != PricingCustomizingConstants.StructureIndicator.CONDITION_FOR_CUMULATION) {
             return null;
         }

//         ICurrencyValue netValue = pricingItem.getNetValue();
         ICurrencyValue netValue = pricingItem.getSubtotal(PricingCustomizingConstants.ConditionSubtotal.SUBTOTAL_M);
         pricingCondition.setConditionBase(netValue.getValue(), netValue.getUnit());

         BigDecimal accumulatedNetValue = PricingTransactiondataConstants.ZERO;

         if (!pricingItem.isStatistical()) {
             accumulatedNetValue = pricingCondition.getConditionBase().getValue();
         }

         IPricingItemUserExit[] prItems = pricingItem.getSubPricingItemsUserExitRecursive();
         for (int i = 0; i < prItems.length; i++) {
             if (!prItems[i].isStatistical()) {
                 IPricingConditionUserExit[] conditionsForCumulation = prItems[i].getConditionsForCumulation();
                 for (int j = 0; j < conditionsForCumulation.length; j++) {
                     if ((pricingCondition.getStepNumber() == conditionsForCumulation[j].getStepNumber())
                             && (pricingCondition.getCounter() == conditionsForCumulation[j].getCounter())) {
                         accumulatedNetValue =
                             accumulatedNetValue.add(conditionsForCumulation[j].getConditionBase().getValue());
                         break;
                     }
                 }
             }
         }

         pricingCondition.setConditionRate(accumulatedNetValue, (ICurrencyUnit) netValue.getUnit());
         pricingCondition.setStatistical(true);

         pricingItem.setSubtotal(PricingCustomizingConstants.ConditionSubtotal.SUBTOTAL_M, PricingTransactiondataConstants.ZERO);

         return accumulatedNetValue;
     }
}

Accepted Solutions (1)

Accepted Solutions (1)

Lakshmipathi
Active Contributor
0 Kudos

Moved from SAP ERP SD Sales to ABAP Development

G. Lakshmipathi

Answers (0)