cancel
Showing results for 
Search instead for 
Did you mean: 

File record number in a Flat file

Former Member
0 Kudos

Hi Guys,

I am working on Idoc to file scenario and generating a file at the target.

at the file...for each line i have to add a line count.

i have 2 header and 5 detail records set..and details are repeating multiple times.

For Ex:

H1........001

H2....002

D1------003

D2----


004

D3----


005

D4-------006

D5----


007

Footer-----008

Could someone help me in resolving this issue?

Thanks

sahil

Accepted Solutions (1)

Accepted Solutions (1)

former_member518917
Participant
0 Kudos

Hi Sahil,

You can write UDF as follow

AbstractTrace trace= (AbstractTrace)container.getTrace();

GlobalContainer globalContainer = container.getGlobalContainer();

String str = (String) globalContainer.getParameter ("COUNTER");

if(str!=null){

int tempRowCounter =(new Integer (str)).intValue();

globalContainer.setParameter("COUNTER",tempRowCounter++);

return tempRowCounter+"";

}else{

globalContainer.setParameter("COUNTER", "1");

return "1";

}

Regards

Ritu

Former Member
0 Kudos

Hi Ritu,

Thanks for your help.

the given UDF working fine for header records..

Since i have details records as (o--unbounded), its throwing an exceptions.

any idea as to how i could resolve this.m new to UDF.

thanks

sahil

Former Member
0 Kudos

Hi Ritu,

Your Given UDF is working for the first 2 records only..for the rest it showing an error as

"Runtime exception when processing target-field mapping /ns0:ProductionOrderCreateChange_Async_V01/PoItem/FileRecordNum; root message: Exception:[java.lang.ClassCastException: class java.lang.Integer:null incompatible with class java.lang.String:null] in class".

can you please guide me as to what could be the problem is?

Thanks

sahil

former_member518917
Participant
0 Kudos

replace the code by

GlobalContainer globalContainer = container.getGlobalContainer();

String str = (String) globalContainer.getParameter ("COUNTER");

if(str!=null){

int tempRowCounter =(new Integer (str)).intValue();

tempRowCounter = tempRowCounter+1;

globalContainer.setParameter("COUNTER",tempRowCounter+"");

return tempRowCounter+"";

}else{

globalContainer.setParameter("COUNTER", "1");

return "1";

}

Former Member
0 Kudos

Thanks for your reply Ritu.

Its solved my problem...

Thanks a ton and you have made my day.

Thank you so very much

Thanks

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi.

You can make a module or you can add one element and in your mapping put as counter.

Former Member
0 Kudos

Hi guys,

Can this be handled using standard functions of PI?

Please reply

Sahil

former_member207622
Contributor
0 Kudos

You can create a mapping between detail node --- count( node function) --- target field

Check this in test tab of message mapping by duplicating the details , otherwise you need to write UDF

regards

Ninad

Former Member
0 Kudos

Hi Sahil

if you're using the Receiver File Adapter using the NFS mode (not FTP) you can think to write a very simple Operating System Command to be executed after message processing.

This script will calculate the number of records and write down the footer.

Francesco