Skip to Content

Using DynamicConfigurationBean with variable substitution to rename file in receiver SFTP adapter.

Overview:

Dynamic configuration parameters can be used to modify the filename, path and other parameters on the receiver side. This is generally achieved via UDF / Java mapping. However SAP has provided this functionality through a standard bean. This enables us to do modify these parameters without writing any code.

Requirement:

PI Version : 7.3 dual stack

Our requirement was to transfer file using SFTP adapters from source fileserver to target file system.  No mapping required. Additionally, the file also has to be written to an “AUDIT” directory in zip format.

The name of the file in output directory and the name of zip file in AUDIT directory have to be same as source file.

So if the source file name is AB_YYYYMMDD_HHMMSS.txt, then the output file also has to be –
AB_YYYYMMDD_HHMMSS.txt and zip file name in audit directory has to be AB_YYYYMMDD_HHMMSS.zip

For achieving the zip functionality, we used PayloadZipBean.

However the zip file was named as AB_YYYYMMDD_HHMMSS.txt (instead of .zip extension) because ASMA was enabled in receiver adapter.

If we unchecked the ASMA on receiver channel for zip file, then we had to provide a static name in “File name” parameter like “AB.zip” and then use the “Append Timestamp” option. But this did not satisfy our requirement of having zip file name same as source file name.

Also since it was a pass through scenario, we wanted to avoid any kind of graphical / java mapping.

Using OS command option was the last resort, however we wanted to try if we could fulfill this requirement using standard bean.

Solution:

We were able to achieve our business requirement by using combination of variable substitution and Dynamic configuration bean as below.

  1. Enable ASMA option in sender file adapter.
  2. Enable variable substitution in receiver adapter which creates zip file and provide a variable name. In the reference field assign it value of message:interface_name.
  3. Ensure that ASMA option is disabled in the receiver adapter because, ASMA has higher priority and hence the file will be named as .txt irrespective of all other configurations.

IMG-1.jpg

  4.  Mention the variable used in step 2 in Filename parameter and appends “.zip” as extension.

IMG-2.jpg

5. In the module tab, add Dynamic configuration and payload zip bean as shown below.

IMG-3.jpg

The write option of dynamic configuration bean, writes the name of source file in the header field – message.interface. This is then substituted in Filename parameter using variable substitution and also since we have “.zip” extension already hardcoded. So we now get a zip file with .zip extension.

Log from communication channel –

IMG-4.jpg.png

IMG-5.png

Related content

http://scn.sap.com/thread/3562745

http://scn.sap.com/people/stefan.grube/blog/2009/06/19/unknown-use-case-of-dynamicconfigurationbean-store-file-name-to-jms-header-without-mapping

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Ankit Mishra

    Nice Blog.

     

    I’m working for the first time on SAP SFTP adapter. I worked on Advantco’s SFTP adapter. Now we are moving to SAP’s SFTP adapter & I need to know few things if you could help. I’ve used Java Mapping for Dynamic File name. In advantco I used * in file name, but if I use the same in SAP SFTP it gives an error “Exception caught by adapter framework: 4: Putting /outbound/* failed.”

    Also, under ASMA, it’s giving me “Filename Attribute Name” field. What needs to be filled here?

    (0) 

Leave a Reply