SAP HCP-IS [ SAP HCI ] How to set Target Filename and Directory dynamically in SFTP Adapter
Introduction:
Being SAP PI consultant we all know how Dynamic Configuration works with File adapter and how to set the target filename dynamically.Now we have started with SAP HCI era and need to find how to achieve the same.Here is the blog which showcase the same by using Apache Camel File Processing Parameters in Content Modifier.
Lets discuss various use cases in detail.
1. How to set Source File Name to Target File Name
Create integration Project like below
Step 1: Configure the Sender SFTP Channel
Step 2: Configure Content Modifier to set the source file name to target file name.
CamelFileName: Parameters which holds File Name in Apache Camel Framework (Upon which SAP HCI-PI is built on).
file:onlyname.noext: Holds the filename text without considering Extension.
There are also other parameters which can utilized( See the below table )
Expression | Returns |
---|---|
file:name | HCI\InputFile.xml |
file:name.ext | xml |
file:name.noext | HCI\InputFile |
file:onlyname | InputFile.xml |
file:onlyname.noext | InputFile |
file:ext | xml |
Step 3:Configure the receiver SFTP Channel like below
Go ahead and deploy the integration project.Now you will have a file in the target SFTP folder with filename same as source filename.
2. How to set target filename dynamically based on key field from incoming message.
Configuration: Create integration project similar to Use Case 1 and repeat the Steps 1 and 3 .
Step 2: Content Modifier configuration
Below are parameters used in the content modifier.
${date:now:yyyyMMdd}: Captures current date of file processing.
${header.User}, ${header.Group}: Captures values from incoming file.
Go ahead and deploy the integration project.Now you will have a file in the target SFTP folder with dynamic filename based on input file.
3. How to set target filename and target folder structure directly (By leaving the Directory and FileName Blank)
Configuration: Create integration project similar to Use Case 1 and repeat the Step1
Step2:
${date:now:yyyyMMdd}: Captures current date of file processing.
${header.RecordCount}: Holds number of records in the input file.
${header.User}, ${header.Group}: Captures values from incoming file.
Step3:
Go ahead and deploy the integration project.Now you will have a file in the target SFTP server with dynamic filename based on input file and in the target folder which is set in the content modifier step.
Conclusion:
Hope this blog helped beginners to dynamically set filename and target folder in SAP HCI using Content Modifier.
Reference:
[1] Content Modifier:
SAP HANA Cloud Integration (Internal, SAP HCI OEM)
[2] SFTP Adapter:
SAP HANA Cloud Integration (Internal, SAP HCI OEM)
[3] Apache Camel File Configuration:
Regards,
Sriprasad Shivaram Bhat
Hi Sriprasad,
thanks a lot for the awesome blog. I have made my life easy. I was looking for that badly.
Thanks,
Apu
Hi Sriprasad
Thanks for sharing this. It is indeed useful reference especially as PI/PO developers get themselves familiar with Apache Camel.
May I suggest that you include a link to the appropriate Apache Camel resource which lists the various parameter reference available?
Regards
Eng Swee
Hello Eng Swee,
Updated blog with references.
Regards,
Sriprasad Shivaram Bhat
Hi Sriprasad,
Thanks for sharing this,blog.
Simply super
Hi Sriprasad,
Thanks for sharing this info. Really helpful ...
Regards,
Satish
Absolutely informative and clear info about setting filename in SFTP adapter.
Thanks Sri.
Hi Sriprasad,
Thanks for sharing this functionality, really useful.
BR's,
Aravind
Thanks for sharing Shivaram !!!!
This is good information
Hi Sriprasad,
Good stuff, thanks for sharing..
B R Raghavendra
This is nice piece of information Sri.
Useful info. Thanks for sharing
Hi Sriprasad,
I want to pick current date file from SFTP server , in File name i am giving as abc${date:now:yyyyMMdd}.txt but it is not working.
Can you Please help me on this.
Regards,
Aditya
Hi Aditya,
Your expression is trying to capture the current date of file processing so if i am right first you need to capture the last modification date of the file and then try to compare it with current date which could be done with the help of any scripting code.
In order to capture the last modification date a file then modify your expression with help of below :
https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
Also try to match your consumer folder date format something like MM/dd/yyyy HH:mm and if any luck works let me know the result.
Cheers!
Chandan
Hi Sriprasad,
I need to pick the latest file from SFTP server. My file name looks like ABC-2019-05-21-042724.csv
I am using the SFTP Sender adapter and giving the file name as ABC-${date:now:yyyy-MM-dd}-*.csv
But it is not picking up the file. Could you please help in how to achieve this.
Note: We don't have archiving
Regards,
Imran
Hi Sriprasad,
Hope you are doing good.
I have a requirement to read the sftp sender directory details dynamically and pass into mapping as an input for one of the filed in CPI.
could you please guide me the camel expression to fetch the folder details dynamically from the source SFTP.
Thanks in advance!
-Avinash
Hi Shivaram,
For AS2 sender adapter CamelFileName added with value "${file:onlyname}" to get the same file name but it is not working as expected.
We have AS2 to SFTP pass through scenario and need the same file name store on SFTP server which sent by partner and at partner side AS2 file name also configured.
Note that Partner is sending .CSV files.
Could you please help me on this.
Thanks,
Khaja S.
Hi Sriprasad,
Thanks for the excellent blog.
I have a requirement where I am receiving a file from an SFTP resource and need to dynamically modify the name of the file inside CPI.
For example, if the name of the input file is Test123, I would like to dynamically change the name of the input file inside CPI as : 'Test-123'. Could you let me know how the same can be done.
Thanks,
Sushanth
HI All,
I tried to implement this but not getting the value from the Sender or receiver xml structure.
not sure if CPI has updated the logic in 4 years,that is why its not picking the value ?
Hello Pooja,
Appreciate if you can create question with the scenario you are looking for.
Regards,
Sriprasad shivaram Bhat
Hi Sriprasad,
This is indeed a excellent blog with good explanation.
I have one query related to the directory in Method:3 , Does the Same Parameter "CamelFilename" is used for fetching directory also during runtime!!?
I'm mainly worried how to tell the system which is filename and which is directory if we are giving both in same parameter. Do we have certain character to segregate both like Underscore etc?
Take your Example itself , We have CamelFilename = "/HCI/Inbound/Output_${header.User}_${header.Group}_${header.RecordCount}_${date:now:yyyyMM}.xml"
Here , Could you tell me on what basis CPI is segrating this value into Directory and File Name please?
Thanks,
Dinesh
Thanks for the excellent blog.
I have a requirement where I have to only pick the extension from the file name tag, which I am receiving in a XML file from a GET API call and set as dynamic filename at SFTP receiver.
For example, if the name of the tag in the input file is:
abc.pdf
werty.jpej
1234567678.pdf
I need extension only (i.e. pdf/jpej/so on..) from the above examples. So I can append with CamelFileName. Could you let me know how the same can be done.
Current configuration in CM, under header: ${header.tag1}_${header.tag2}_${date:now:yyyyMMddHHMMSS}.
After '.' i have to add the above extension.
Thanks,
Amit