cancel
Showing results for 
Search instead for 
Did you mean: 

Read File Content before to get it in File Adapter

Former Member
0 Kudos

Hi guys,

in one interface we have a requirement to monitor a Log File. The file is in NFS folder, and is the Log of a non-sap system process, and we have to monitor if the Log file contains the string 'Error' and in positive case take it and do another process.

We are using SAP PI 7.4, there is any possibility to do this check? Should I create an adapter module for this requirement? If the adapter module is required, how it is configured the File Adapter to take the file only when this string appears?

Many thanks,

Xavier.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Instead of doing at adapter level, i think u should try validating file content at mapping level.

I mean read file content and use extended RD concept where using Java mapping validate whether string is present or not and depending upon that route that message for further processing.

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

I thought to get the file anyway and after check if the string is present in the file, it will be a flat .txt file

But, there is any possibility to check if the string is in the file withouth getting it? And in case the string is not in the file no action would be taken.

Many thanks,

Xavier.

Former Member
0 Kudos

Hello,

>>But, there is any possibility to check if the string is in the file without
getting it?

AFAIK, i don't think so.

 

But having said that, why don't u ask ur sender system (if it's possible) which is generating these files to rename it something like fail/success.txt and then ur job would certainly be lot easier.

Thanks

Amit Srivastava

former_member184720
Active Contributor
0 Kudos

Hi Xavier- You might have to go for execute os commands before file processing option in the sender channel.

You can write some unix/java any code which will validate the log file.

If the string is present then you can move the file to your source directory(which is configured in the channel).

More Info on this functionality and some commands:

http://wiki.scn.sap.com/wiki/display/XI/SAP+XI+File+Adapter+OS+Command+Line+Feature

Former Member
0 Kudos

Hi Hareesh,

thanks for the answer. I have to talk with basis team, because I know that there is a script reading this file send an email in case of error. Now they want to monitor this process by SAP PI, but could be a possibility they change the script and move the file when the 'Error' string appears.

Many thanks,

Xavier.

former_member184720
Active Contributor
0 Kudos

Then i hope it makes your work easier

They just need to modify it to move it another folder instead of sending an email.

They can get rid of the scheduler too as i you can execute from the PI channel.

iaki_vila
Active Contributor
0 Kudos

Hi Xavier,

In this thread you have the batch code  to find a string in a file (for windows):

If you need to pick the files without the error string and to move to files with the error string to the error folder, in my opinion the best way is the mentioned by  Amit at first. You can do a File to File scenario. You could use file content conversion, the source could have one tag with all the log file, the target XML could be two tags, one with the log file and the other tag with the destination path.

The destination path can be calculated in the message mapping searching the error string. Finally, in the configuration you can use the condition editor in a receiver rule to read this destination tag and to send to one path or another path. Also, you can avoid the condition editor and to use ASMA file properties and to decide dynamically the destination in message mapping level () (Dynamic file name and directory in Receiver File Adapter - summary of possibilities - Process Integr...).

Regards.

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks to all guys.

They don't want to change the script, and my manager said that PI should be useful and do it ourselves.

I wanted to avoid to create an adapter module or a script, we don't have too much time, and the they don't want to put a script in his server.

Another proposal as Iñaki said is to get the file in one tag and check if the string 'Error' exists, in positive case do the next step, in case it doesn't exist, leave the file at the same folder again, I think it's not the best solution but this way we can avoid to write an adapter module or try to convince the client about solutions they don't want to use.

Many thanks,

Xavier.

Former Member
0 Kudos

Hi ,

Clean ways to handle your requirement is using custom module/OS level command/script.

Below blog tells you step by step procedure to develop custom module.

Custom Adapter Module Development - SAP PI 7.1 - Netweaver Technology - SCN Wiki

OS level command:Put the command in File adapter processing tab

OS level script Give the location of the script code file in File adapter processing tab.

Regards

Venkat