Skip to Content
Technical Articles
Author's profile photo Adam Kiwon

How to check if a file exists with SAP PRO/SAP PI

Sometimes we have to check if a file has been written on a file system and perform actions based on that. With PI we usually poll a directory using the File Sender Adapter (e.g. in TEST mode if we can not delete the file). Here´s a smarter way:

  1. Schedule a Trigger that runs the File Check periodically (based on your requirement)
  2. Read the directory of the NFS/FTP/SFTP using the FileReader Adapter


Example Configuration

  • Sender: SOAP Message coming from WHINT MessageTrigger Job (of course you can use another trigger like a file sender polling in test mode with channel scheduling)
  • Receiver: FileReader Query using WHINT FileReader Adapter
  • Both sides use BusinessComponent “FileChecker” here


Create Business Component:FileChecker 1


Define iFlow/IntegratedConfiguration (SOAP to FileReader):FileChecker 2


Configure the FileReader Adapter Channel with the file name you look for:FileChecker 7


As the FileReader Adapter reads synchronously, we have to switch from Async to Sync using the RequestResponseBean and back to Async using the RequestOnewayBean:FileChecker 8


If the file is found, we need to have a second (Dummy) iFlow/ICO that is receiving the Response Message from the adapter but without processing it:FileChecker 9


Set up a MessageTriggerJob in NWA / Operations / Jobs according to your needs (the period is configurable very flexible: daily / every 10 minutes / …):FileChecker 4FileChecker 6


If the file can not be found, the message goes into error:FileChecker 5


VOILÁ – here is the message in error (System Error).
If you have defined alerting, an automatic E-Mail is triggered!


In case the file is found, no additional message is being generated. This behaviour can be changed if you change the routing of the Dummy iFlow.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Nicolas Pauwelyn
      Nicolas Pauwelyn

      Nice blog Adam!

      However, don't forget that SAP PI has the ability to start an interface by using a trigger file. This feature has been shipped with 7.31 SP19 and 7.50 SP04, see SAP note 2300326 - New feature: Using Trigger File in File Adapter.

      Author's profile photo Adam Kiwon
      Adam Kiwon
      Blog Post Author

      Thanks Nicolas, I remember it was released based on the customer influence program. However, it is "only" a way to launch a File Sender Channel based on a trigger. The solution I am highlighting shows an independent way of checking the existence of a file (e.g. to know if the month end closing report for finance has been written into). The example here is raising an error (and alert) if a certain file was NOT found, e.g. if every month on the 1st specific data is expected in a file...