cancel
Showing results for 
Search instead for 
Did you mean: 

File access in UDF

Former Member
0 Kudos

Hi All,

I have some doubts regarding accessing file from PI application server. I am writing UDF which reads say "plant.txt" flat file from the PI application server. Is it possible to access file in UDF?

Below is the sample code I have wriiten in eclipse editor which is working fine. And tell where I need to keep this file.

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public

class CsvTest {

public void readFile() {

BufferedReader br = null;

try {

br = new BufferedReader(new FileReader("D://plant.txt"));

String line = null;

int totalElements=0;

while ((line = br.readLine()) != null) {

String[] values = line.split(",");

totalElements= totalElements + values.length;

for(int i=0;i<values.length;i++)

{ System.out.println(values<i>);

}

}

System.out.println(totalElements);

}

catch (FileNotFoundException ex) {

ex.printStackTrace();

}

catch (IOException ex) {

ex.printStackTrace();

}

finally {

try {

if (br != null)

br.close();

}

catch (IOException ex) {

ex.printStackTrace();

}

}

}

public static void main(String[] args) {

CsvTest test =

new CsvTest();

test.readFile();

}

}

Please help me out.

Thanks in Advance,

Nisha

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

We have 2 options.

1:) If you need to pick a file from file server using XI, then it has to be picked by the File adapter which needs all the required detials like IP address,folder name and file name,etc..

2:) If you need to pick it from IR, then you need to export it.But you need not require to mention the file path as you have mentioned.(D:
fileName).

Former Member
0 Kudos

Accessing a file in UDF/Mapping would be a very bad design approach. I would strictly recommend not doing this. If the file is important as per your interface, then you should be thinking about a BPM with a separate receive step to get the content of the file and not just access it via UDF.

Former Member
0 Kudos

If you are talking about the java code then you need to generate the Jar file and need to load into the IR (Imported archive section) and then make use at mapping..

If you are talking the file path then you can keep at NFS share of PI(i.e sap/global/sys/...) path

i.e there is one folder where application relation data can be kept(chk with basis for exact path)

Rajesh

former_member192295
Active Contributor
0 Kudos

Hi,

We can keep file in any folder(it should be read & write permission else will throw error while reading. Generally will keep D or F drive) in you current server, meanwhile we can access file from UDF. Better to keep file in restricted folder to prevent access from other one. But according to SAP PI standards it is not good practise to access file from UDF. According to your requirement choose RFC or JDBC lookups. I hope now clear