cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate the total sum value of a particular field that repeats

Former Member
0 Kudos

Hi All,

I have the following Req...File----Idoc Scenario

In the Inbound xml file i will get the Sales Order details with suppose 10 line items( 10 Orders)

Each line item represents one one SO. So totally i wil have 10 Sales Orders in this file.

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_Sales_Order xmlns:ns0="http://sap/Sales_Order">

<Header>

<COMP_CODE></COMP_CODE>

<DOC_TYPE></DOC_TYPE>

<SUPPL_VEND></SUPPL_VEND>

</Header>

<Item>

<ITEM></ITEM>

<MATERIAL></MATERIAL>

<PLANT></PLANT>

<QUANTITY></QUANTITY>

<Amount></Amount>

</Item>

In the above structure Item Segment will repeats as many no. of Sales Orders comes in a file.

In a file if there are 10 Orders means the Item segment wil repeats 10 times.

I have the Amount field in the Item Segment, each and every time that needs to be added to next Amount value that presents in the next Line Item.

Finally i will have the Another separate field caled Grand Total, and i have to get the total summation of the 10 values of the Amount field at last.

Can we achieve this using UDF or is there any way to do this

REgards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Check with below mapping


DISCOUNT----->EqualsS--->Constant(ZE)-------->\if
                                               ---------->Sum---->Target
                                AMOUNT ----->/then

Change the context of DISCOUNT and AMOUNT to higher level

Answers (1)

Answers (1)

SudhirT
Active Contributor
0 Kudos

Hi,

Use statistics function SUM, set the proper context or use

Amount ->removeContext->SUM--->GrandTotal

Thanks!

Former Member
0 Kudos

Heyy Sudhir,

Its Perfect, i was worried abt this on how to do it,

U solved it simply

Thank u

Former Member
0 Kudos

Hi,

I have another check in the incoming data to do sum.

In the incoming file if the field Discount Type is equals to ZE means i have to add those values only.

i have placed the condition like this , but it is calculating the sum irrespctive of the condition

http://img266.imageshack.us/my.php?image=15129719ih9.jpg

Regards

Former Member
0 Kudos

write a simple UDF

sumOfDiscountType ( String[] discountType, String[] amount, result )
{
   int sum = 0;
   for ( int i = 0; i < discountType.length; i++ )
  {
    if ( "ZE".equalsIgnoreCase( discountType[ i ] )
   {
      sum += Integer.parseInt( amount[ i ]  );
   }
 }
 result.addValue ( sum );
}

pass two params.. 

discountType (removecontext) ----
                                               | -----UDF ----Total
amount ( removecontext)        ----

Edited by: Anand on Nov 25, 2008 4:02 PM

SudhirT
Active Contributor
0 Kudos

Hi Krishna,

did u use function removeContext after discount type field?

thanks

Former Member
0 Kudos

Hi Vamsi

You are using IFS

Use only If you mapping will work. Use remove context as well after discount and amount

Thanks

Gaurav

SudhirT
Active Contributor
0 Kudos

Hi,

Do like this, actually in your case sum is taking place before the condition check for discount type

do a little change in mapping

DiscntType--removeContext--
                                          EqulsS-------IfWithoutElse----Amount---removecontext--then---SUM-
 Connstatnt(Value)

--->GrandAmount

Krishna, Check the same question asked by Rajesh in thread

Thanks!