cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for Total records

Former Member
0 Kudos

Hi

I have a scenario where sender is file. In file there is a field Total records.

I need to validate Total records field with the total records in the file using UDF..

Can any suggest me the how to write the cod efor this..

venkat

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member214364
Active Contributor
0 Kudos

Hi Venkatesh,

Do you want to do this validation in Message Mapping step?

if its invalid or valid, what action you want to take?

Cheers,

Jag

Former Member
0 Kudos

Hi

Yes i want to do that validation in message mapping , if the validation fails then i have to trigger an alert

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkatesh,

Could you pelase send Source structure and also element name in to which you are getting record count.

Cheers,

Jag

Former Member
0 Kudos

Hi Jagdish

My source structure is

DT_ AwardInformation

XXX_ACEAward

<b>Header</b>

PayDate

EndDate

<b>DetailRecord</b>

PersonnelNumber

Infotype

Subtype

Field3

Field4

Field5

<b>TrailerRecord</b>

TotalRecord

TotalAmount

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkatesh,

In your source structure should Detail Records count equal to Total Record Count?

if yes,just create <b>Context</b> UDF and pass the following 2 inputs

1. <b>DetailRecord</b> -> RemoveContext

2. <b>TotalRecord</b>

and inside UDF write java code for validation

suppose if your inputs are a[](DetailRecord) and b[](TotalRecord)

{

int scnt = a.length;

int tcnt = Integer.parseInt(b[0]);

if( scnt != tcnt)

{

//write code to trigger an alert(from the following weblog)

}

}

To Trigger alert from UDF just go through the following weblog

/people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function

Cheers,

Jag

Former Member
0 Kudos

Hi jagdish

I will try this if there is any errors i will let u know

I need one clarification like .. no need to import any java packages..

int scnt = a.length; this will do the length of the record or the total records..

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

a.length gives number of occurrences of <b>DetailRecord</b> count.

To trigger Alert from UDF you have to import following 2 packages

import com.sap.aii.mapping.lookup.*;

import java.io.*;

Cheers,

Jag

Former Member
0 Kudos

Thanks jagdish

I am new to alert configuration part...may be i need your help

venkat

Former Member
0 Kudos

Hi Jagdish

Even i have to whether header record is present or not ..If not then i have raise an alert

How can i check that ...

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

whats the occurrence of <b>Heade</b>r node?

Cheers,

Jag

Former Member
0 Kudos

Hi Jagdish

Header Occurrence 1..1

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

if you want to trigger Alert for Header node. you need one more UDF with one input

i.e <b>Header</b>-> <b>exists</b>(Node function) ->UDF

Input to UDF would be either <b>true</b> or <b>false</b>.so Inside UDF you have to write java code like if <b>false</b>(Header Not existing) trigger Alert.

Cheers,

Jag

Former Member
0 Kudos

Hi Jagdish

Could you be more specific on that...

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

what i mean is you have to create new UDF if you want to validate Header node.

UDF input is output of <b>exists</b>(it comes under Node functions) standard function.

This<b> exists</b> will return <b>true</b> if <b>Header</b> node occurred,

otherwise <b>false</b>.

so inside UDF you need to check for <b>true</b> or <b>false</b> values.

if its <b>false</b> it means header node didnt occurred then trigger Alert.

Header(from Source structure)->exists(Node function)->UDF

Cheers,

Jag

Former Member
0 Kudos

Hi Jagdish

I been trying the Bhavish Blog on Triggering an alert. I didnt not much of it

If u provide me the sample code in UDF for Triggering an Alert for Total records and header record.

venkat

Former Member
0 Kudos

Hi Jagdish

I am trying the Total Record count UDF

I want to do that validation in the source side only . if total records equal to Trailer total records then continue the process if not then abend the process and raise an alert.

how we do that

venkat

Former Member
0 Kudos

Hi Jagdish

I wrote the code like

public void TotalRecords(String[] TotalRecord,String[] DetailRecord,ResultList result,Container container){

{

int scnt = DetailRecord.length;

int tcnt = Integer.parseInt(TotalRecord[0]);

if( scnt != tcnt)

{

throw new RuntimeEception("Error in the Total Records field");

}

Is that right or need to do any modifications

Which java package i have to import for Runtime Exception

venkat

Former Member
0 Kudos

Hi Jagdish

Could u elaborate on UDF..for checking the Header record ..

While creating the UDF i have catch the value or queue ot cache

venkat