In this blog, SAP PI UDF example is been provided for below functionalities:

  1. To read file contents of a file from sap application directory,
  2. here read only those files which names starts with some key words
  3. To archive same file to other sap application directory
  4. Post Archival, delete the file from source path

Java Imports required in UDF as

  • java.io.BufferedReader
    java.io.FileReader
    java.io.IOException

Java UDF Execution Type is “All Values of Queue”

Java UDF Code is as below:

public void file_Read_Move_Delete(ResultList result, Container container) throws StreamTransformationException{ String RequestDataStr = "XYZ"; //File Name Starting Key String FilePath_str = "/folder1/folder2/"; //File directory String FileArchival_Path = "/folder1/folder2/folder2/"; //File Archival Path String fileContentStr = ""; boolean StartsWithStr_Found = false; File[] dirFiles = new File(FilePath_str).listFiles(); if (dirFiles.length > 0){ //Check if Directory is not empty for (int i=0; i 0){ outStream.write(buffer, 0, length); } inStream.close(); outStream.close(); }catch(IOException e){ e.printStackTrace(); } inputFile.delete(); //Delete same file from Source Folder (i.e. FilePath_str) //End of Method-02 --------------- //End of File Archival (i.e. move file from one Folder to other folder ------------- }//End of "fileName check }// End of Folder for loop }// End of directory length check //If no file found if (StartsWithStr_Found = false){ result.addValue("File Not found !"); } }

 

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !