Sender File Adapter Frequently Asked Questions
Many questions arise in SDN about some popular capabilities of the Sender File Adapter in SAP PI. I have decided to collect them in a single FAQ blog to give answers to all the users that require some help with common problems with this adapter. In addition to reading this blog, make sure that you refer to SAP Help for this adapter whenever you have questions about a certain parameter:
- I want to access a certain directoryI want to access a certain directory from SAP PI as a source for my interface. Neither is it an FTP server, nor a local directory on PI's server. How should I proceed?
- I want to make sure my file is completely written before PI starts processing it. How can I do this?
- I want to put my file into an archive directory once it is processed. What should I do?
- My sender system creates a simple trigger files once it is done writing to the interface basic file. How can I work with trigger files in PI?
- My sender system creates multiple source files for different levels of data structure. What are PI capabilities to processed the normalized data from several flat files?
- It sometimes happens that my sender file adapter gets blocked, because it finds an erronous file. How can I have other files processed, even if one particular file causes a processing error?
- Can I use a single sender file communication channel to collect files from multiple directories?
Q1: I want to access a certain directory from SAP PI as a source for my interface. Neither is it an FTP server, nor a local directory on PI's server. How should I proceed?
A: Do not be fooled by the name of Transport Protocol in the Communication Channel ("File Transfer Protocol - FTP"). You can use the "File Transfer Protocol (FTP)" of the file adapter not only to connect to external FTP servers, but for any external server you need to collect files from. All the settings are just similar to connecting to an FTP server: type your server's IP address or domain name, the required port (21 by default) and security settings, if required. Remember to make sure your server is accessible (in terms of network connectivity) from PI's server and your port is open in the firewall. See this blog from Michal Krawczyk for a few ways to test the connection for your desired source server:
Q2: I want to make sure my file is completely written before PI starts processing it. How can I do this?
A: Whenever using the sender file adapter, you need to make sure that you only collect files that are already completely written by the sender system. In the simplest case (from PI's point of view), your sender system can write a temporary file under a temporary file name, and change the name once it is done writing to it. But what if your sender system cannot ensure it going that way? You can use the "Msecs to Wait Before Modification Check" parameter of sender file adapter. It means that PI waits some time from first finding the file, until reading and processing it later, and the file is only processed if it had not changed over the waiting period. For instance, set the parameter like below if you want PI to wait 5 seconds and then make sure the file is complete:
Q3: I want to put my file into an archive directory once it is processed. What should I do?
A: Use the "Archive" Processing Mode on the Processing tab page of your sender channel, then type your desired Archive Directory. When using the "File Transfer Protocol (FTP)", it is crucial to mark the "Archive Files on FTP Server" checkbox. If the indicator is not set, the files are archived in the Adapter Engine file system, so you will not see them in your FTP server once they are processed. The use of "Add Time Stamp" checkbox is intuitive - PI will add processing timestamp to the name of your file.
Q4: My sender system creates a simple trigger files once it is done writing to the interface basic file. How can I work with trigger files in PI?
A: In most cases, setting the "Msecs to Wait Before Modification Check" parameter of sender file adapter should be enough to make sure that sender file is done writing to a file (see Q2). But what if you cannot set a proper value for this parameter, because you do not want to wait for ages, but on the other hand your sender writes the file slowly? Have no fear, if only the sender system can create a trigger file. The trigger file is a simple (sometimes even empty) file that indicates that the original file is written completely and can be processed further. Usually it has an identical file name as the original file, except for the extension.
Working with trigger files is quire simple, there are just three steps to follow:
- Define an additional file in File List parameter, let us call it "TriggerFile".
- Specify the part of your file name that needs to be replaced to get the name of the trigger file as the value of TriggerFile.namePart parameter. For instance, assuming your original file's extension is .csv and trigger file's extension is .trg, use the value ".csv"=".trg". Both files must be placed in the same directory and have their names almost identical (except for the part you define here).
- Set the TriggerFile.optional parameter value to NO. Thanks to this, your message will not be processed if the trigger file does not exist.
Note that you can have access to the trigger file content during message mapping (although this might not necessarily be required in your case). You also need to be aware that every time your original file starts to be processed, but no trigger file exists yet, message processing will be canceled with an error message.
Q5: My sender system creates multiple source files for different levels of data structure. What are PI capabilities to processed the normalized data from several flat files?
A: You can use the "Additional File(s)" checkbox and the details box that appears once you mark the checkbox on the "Source" tab page of your sender communication channel. First, specify the list of additional files in the "File List" field. For instance, you can have Items and Conditions files in addition to Header (main) file. The names you specify here are only some identificators that you use while defining parameters in the box below. There, you can for example make certain files obligatory or optional, or set their encoding.
As a result, you will get access to contents of all your files in the message mapping. For further details, see this help document:
Q6: It sometimes happens that my sender file adapter gets blocked, because it finds an erroneous file. How can I have other files processed, even if one particular file causes a processing error?
A: Have your erroneous files moved to an archive directory. Once they are moved there, other files will be processed, so your scenario will not get blocked with a single faulty file. On the Processing tab page of your sender CC, mark the Archive Faulty Source Files checkbox and provide an archive directory location in the "Directory for Archiving Files with Errors". You can additionally mark the "Add Timestamp" checkbox if you want to append processing timestamp to your file names.
Q7: Can I use a single sender file communication channel to collect files from multiple directories?
A: Of course you can, and this is really simple. On the Source tab page of your sender channel, in addition to typing the "Source Directory" and "File Name", mark the "Advanced Selection For Source File" checkbox. Then, in the details box that appears, type a directory and file name scheme in each line, as required. The settings depicted in the screenshot below will result in files being collected from root directory, as well as "one" and "two" folders. Files with .txt extension will be processed in each case.
Remember that all your files from all locations need to conform to the same file structure to be processed correctly.