Archive Files with the File Receiver Communication Channel

Archive Files with the File Receiver Communication Channel

The File Sender Communication Channel is able to move processed file to an archive directory and append the current timestamp. The File Receiver Communication Channel lacks an parameter to archive files. This is okay in most cases. The receiving system should take care of the file after processing. But, what if the demand is to move a file to an archive directory on the receiving system before overwriting it?

Solutions:

  1. It is possible to use an (cc)BPM(N) which orchestrates the archiving and the creation of the new file. You would need a configuration, a File Sender Communication Channel, a File Receiver Communication Channel and dummy interfaces to grab the old file and move it to a new directory. After the archiving is done, you can use a second configuration to store the new file. In addition, a third configuration is necessary which receives the source file and triggers the ccBPM or BPM. One BPM and three configurations – a lot afford for a simple archive.
  2. The File Receiver Communication Channel has a parameter to run script or commands on the operating system before and after creating the file. A simple move command wil do the trick.
    If your SAP Process Integration / Process Orchestration runs on Unix, use

    mv test.xml archive/test_$(date +%Y-%m-%d).xml

    If your SAP Process Integration / Process Orchestration runs on Windows, use

    ren “test.xml” “test_%date:~10,4%%date:~7,2%%date:~4,2%.xml”

    Move command in File Receiver Communicaiton Channel
    Move command in File Receiver Communicaiton Channel

    In case you use dynamic filenames, you can use the following placeholders:

    Placeholder Description
    %F target file path
    %f target file name

    Unfortunately, this will only work in NFS mode. You could create a script which connects to the FTP server and archives the file and run this script with the Communication Channel, but I would highly advise against this.

To read more about the File Receiver Communication Channel, check out the SAP Documentation.

5 Replies to “Archive Files with the File Receiver Communication Channel”

  1. Hi Maximilian,
    The above os command didn’t work for me, I am using Linux machine. However when I just use mv % F % F_Test.xml its working but doesn’t work with timestamp. Could you please let me know what I need to do for adding timestamp.
    Thanks in advance

    Kind regards,
    Atif
    SAP PI

    1. Hello Atif,
      I could imagine that PI has an issue with % characters. You could try to use
      mv %F archive/test_$(date).xml
      Otherwise please create a shell script, which handles the renaming, with the following to lines:

      #!/bin/bash
      mv $1 archive/test_$(date +%Y-%m-%d).xml

      Inside the adapter please use it like this:
      your_script.sh %F

      Please make sure that your script can be executed by PI user.

  2. Hi Maximilian,
    Thanks for your reply.

    I tried everything you mentioned, Still getting the same error, I’ve created shell script and place it in a separate folder, when i executed my scenario i am getting the below error.
    Error executing OS command “/XXXX/XXXX/XXXX/script/rename.sh /mclaren/interfaces/file/testappl/Original/File.CSV File.CSV”
    below is my Shell Script
    #!/bin/bash#
    mv $1 /XXXX/XXXX/XXXX/file/testappl/OriArchive/%f_$(date +%Y-%m-%d).CSV

    Thanks,
    Atif

    1. Hello Atif,

      You are using %f in your script, which is not available in this scope. What you can to is creating a script which takes two input parameters.

      Please try to use the script below

      #!/bin/bash#
      mv $1/$2 /XXXX/XXXX/XXXX/file/testappl/OriArchive/$(date ‘+%Y%m%d’)_$2

      and execute it with:
      /XXXX/XXXX/XXXX/script/rename.sh %F %f

      Best Regards,
      Maximilian

  3. Hi Maximilian,

    I appreciate your prompt response.
    my issue is now resolved, I would like to add few things here.
    I have written below shell script for adding Time stamp before filename and placed it in a directory /xxxx/xxxx/xxxx/xxxxxx/Script/rename.sh with the filename rename.sh

    #!/bin/bash
    today=`date ‘+%Y%m%d-%H%M%S’`;#
    mv /xxxx/xxxx/xxxx/xxxxxx/OriArchive/$1 /xxxx/xxxxx/xxxx/xxxxx/OriArchive/$today-$1

    and executed with below command in “Run OS command after after message processing”:
    sh /xxxx/xxxx/xxxx/xxxxxx/Script/rename.sh %f

    Thanks,
    Atif

Leave a Reply

Your email address will not be published. Required fields are marked *