cancel
Showing results for 
Search instead for 
Did you mean: 

validation of some field in the incoming file using java code

Former Member
0 Kudos

Hi

I have an incoming file which contains a (Header, Details, Trailer) in which Details are repeating. for example:

H, X,123,...... --->(Header)

D, ABC, HYG,0009 --->(Details)

D,UHU,KKK,088

D,OOO,LOK,077

T,RecordCount,...--->(Trailer)

My need is I have to write a java code to count the number of Details records and compare it with the RecordCount field in the Trailer. After validation if it is true then

the Header and Trailer Records has to be removed and first record of the Details shud end with Y . For example the above file should look like this.

D, ABC, HYG,0009,Y

D,UHU,KKK,088

D,OOO,LOK,077

Can anyone please help me out this

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Here is some pseudo code o get you started

Use an Advanced user defined function

Input 1 -> Details record

Input 2-> Count Field in Trailer.

Inside UDF, have a for loop that will be like

int count= 0;

for(int i=0;i<Input1[].length;i++){

count = i ;

}

count= count +1;

If ( count == Input2) {

result.addValue("Y")

}

hope this helps

regards

krishna

Former Member
0 Kudos

Hi

I need to write a java program for that and not the UDF coz i need to execute it before going to the Integration engine

Former Member
0 Kudos

Hi

For that, you would have to know parsing XML files using JAVA like DOM or SAX. Sax is more preferable

It would be much easier to write the small UDF code inside XI.

regards

krishna

Former Member
0 Kudos

Actually the incoming file is a flat file

Former Member
0 Kudos

Oh k ..

Then try this pseudo code

public static byte[] getBytesFromFile(File file) throws IOException {

BufferedReader in = new BufferedReader(new FileReader("infilename"));

// Get the size of the file

long length = file.length();

String str;

int count;

int getcount;

while ((str = in.readLine()) != null) {

if (str.startsWith("D") {

count++;

}

if (str.startsWith("T") {

// write code to get the length of the count in the Trailer record and assign it to getcount variable

}

}

if ( count == getcount )

{

Then open up a Buffered writer to write a new file without the Records that start with "D",

}

regards

krishna

justin_santhanam
Active Contributor
0 Kudos

Hema,

How you designed the Data type, can u give us the structure?

Best regards,

raj.

Former Member
0 Kudos

Hi hemalatha,

You need to use a Advanced UDF - java program, where you are loading the entire payload in to the container in your program, so you will have the values of your header data also.

Regards,

Ramesh P