cancel
Showing results for 
Search instead for 
Did you mean: 

How to count records in a File

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use Count function for counting the no. of records.

For adding the total you can use the function SUM.

Regards,

---Satish

Former Member
0 Kudos

Satish Could u pls elaborate...

XIer

Former Member
0 Kudos

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.

justin_santhanam
Active Contributor
0 Kudos

XIer,

If you could give us the structure it could be easy for us to suggest.

Best regards,

raj.

Former Member
0 Kudos

What do u mean by Context?

Regards,

XIer

Former Member
0 Kudos

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

Former Member
0 Kudos

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

justin_santhanam
Active Contributor
0 Kudos

Hi,

Is it ok for you to use BPM in this scenario? Also wht you have to do if the record counts are equal?

Best regards,

raj.

Former Member
0 Kudos

Raj, no we strictly don't want to use BPM. Also if the counts are equal the data is paased on to SAP system using a proxy.

File ---> XI ---> Proxy (ECC).

Regards,

XIer

justin_santhanam
Active Contributor
0 Kudos

Hi,

Then we can do onething, u can't send e-mail. But u can throw an exception in runtime and you can configure the alerts for this intrface and send an e-mail to concerned persons is it ok?

Best regards,

raj.

Former Member
0 Kudos

Raj,

I beleive that we can send alerts from UDF...

XIer

justin_santhanam
Active Contributor
0 Kudos

Hi,

Sending Alerts from UDF is nothing but throwing an exception and trigerring alert through ALRTCATDEF. I think this is the way to trigger an alert, please correct me if i'm wrong.

Best regards,

raj.

Former Member
0 Kudos

So u mean we can't send emails through udf?

XIer

Former Member
0 Kudos

thezone,

I can't find context in message mapping.

XIer

Former Member
0 Kudos

Hey

>>I can't find context in message mapping.

right click in the graphical editor over any element and you will see its context

Thanx

Aamir

Message was edited by:

Ahmad Aamir

Former Member
0 Kudos

Thanks Ahmed I found it and it works.

XIer

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Is it that complicated, i guess it could be handled in message mappings itself.

Regards,

XIer