cancel
Showing results for 
Search instead for 
Did you mean: 

count no of lines in a text file..using File adapter

Former Member
0 Kudos

Is that do-able..?

if so how..

Accepted Solutions (1)

Accepted Solutions (1)

former_member181962
Active Contributor
0 Kudos

where do you want this value ?

If you are using a message mapping, you can use teh count function on the RECORD node(Which repeats itself for each record).

Regards,

Ravi

Answers (3)

Answers (3)

GabrielSagaya
Active Contributor
0 Kudos

In Message Mapping you can find a function Counter you can make use of it. This Counter will generate the number of record per message if you want to consolidate all the record then from sourse side with the help of variant you can handle it with this counter function.

otherwise

just write a UDF for this,set the context to root node and increase the counter by 1 each time a new records comes in

Former Member
0 Kudos

Hi,

Input is a text file, and when it leaves the adapter its in XML format, i need to count the lines in the input text file..not nodes/records in xml..How..is that possible with a UDF..or anything

Vs

GabrielSagaya
Active Contributor
0 Kudos

You just need to write one liner code in function.

public void count(String[[]] a,ResultList result,Container container){

result.addValue(Integer.toString(a.length));

}

and change context to root.

Former Member
0 Kudos

Hi,

By using the UDF it should be done.

Text file should have some new line separator, based on that we count the number of lines,

if new line separator is 'nl', check for this condition if occurs increment the counter(initialized to 0) variable, finally add 1 to the counter(because last line doesn't have lend end separator) that is your final output.

Former Member
0 Kudos

Hi Venkat ,

Do you require no of lines counter in atext file before sending the file content to SAP XI ?

It will be better if you can explain your requirement in detail in the forum .

regards,

kishore

Former Member
0 Kudos

Hi,

I need to count the number of lines in a text file which i am converting to an xml document using the fcc..So all functions in mapping are of no avail..as by the time it reahes mapping..its already in xml format...........

WHat do you suggest

VS

Former Member
0 Kudos

As really there is no meaning to write UFD if you are going to count the no. of lines from Text File(Not XML).

Why not Java mapping or XSLT , you can convert the XML file as well as count the no. of lines.

Thanks

Farooq.

0 Kudos

Did you try using counter in the mapping and map the source node to target element Counter.

For every iteration of the node Counter is incremented.

When mapping is done you will get the last value populated in the element and thats the count

Cheers

Former Member
0 Kudos

Hi,

In the message mapping by writing the UDF we can handle the total number of lines.

Former Member
0 Kudos

Hi ,

Yes you can count no of lines in file adapter configuration.

Please let us know your requirement and when and where you want to use no of lines counter .

Regards,

Kishore