on 07-27-2007 6:54 PM
Hi All,
When I get a file in XI, I need to count the number of records that file has. Also each record has an amount field, I need to add all the amount fields in the all the records present. How do I go about doing it.
Regards,
XIer
Hi,
You can use Count function for counting the no. of records.
For adding the total you can use the function SUM.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the standard available functions select the "Statistics" group and you will get the Sum, Count, Average and other functions.
for using the count, drop that function and the input will be the node you want to count and the value will be assigned to the node you map it to. same for the average function also.
MAKE sure that you set the context right, if not the values wont be right.
Context will be the scope at which the operation (sum/count) will be performed.
suppose you have the following structure.
<source>
<record>
<amount>20</amount>
<amount>30</amount>
</record>
<record>
<record>
<amount>10</amount>
<amount>10</amount>
</record>
<source>
if you do the mapping the following way,
<record> --> count --> totalrecord
<amount> --> sum --> totalAmount
if the context of <record> is at same level - then you will get the total as 1. If you set the context at <source> then you will get the total as 2.
similarly for <amount>, the values will be 50 (2030) or 70 (20301010), if you set the context at record and source level.
To set the context, right click the <record> or <amount> node in the editor and goto the context menu.
Thanks
Hi thezone,
The structure I have is:
<source>
<record>
<amount>20</amount>
<amount>30</amount>
</record>
<record>
<record>
<amount>10</amount>
<amount>10</amount>
</record>
</totalrecords>
<source>
Now in my file to SAP scenario, I am getting the above structure in. The total records value comes from the sender system. now I need to add the number of records in the file structure and see if it matches with the value in total records.
1) How to add num of records and compare it with total records?
2) Is intermediate structure necessary for the baove?
3) If the totalrecords do not match the counting done in above, an alert email has to be generated? Do i have to generate UDF for that or is there any other method too?
Regards,
XIer
You'll probably need a double mapping for this, if the record count element appears before the actual records.
Make a datatype axactly like the output type, except with recordtotal field at the very end, because each one in the output file is the same right?
Your first mapping will be from the source to this new dt, create a global variable and initialize it to zero, then where you map the record over add one onto the this variable every time in an udf. at teh last part with the record recordcount field at the end, map the global variable to it in an UDF, since that should be the total number of records.
now make a message mapping from this new DT to the destination message, with that record count field mapped to whereever you need it everytime
In the interface mapping, just do both message mappings in the message mapping part, make sure they're in order.
-give me points if this works, and ask questions about this if you need to
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use standard Count function for your first requirement.
Second requirement - write a UDF, using a container variable add the amount value to the variable or use SUM
If the count function isnt sufficient you may want to use the index function available in A-UDF.
sincerely,
--NM
Message was edited by:
Naomi Monnier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.