Skip to Content

Create Adapter module for picking file from Unix server

Hello SAP Gurus,

I have a file-to-file scenario .

The source file is provided in Unix server where once it gets written , the file is not getting renamed or deleted.

One more twist is that this file with content has a check if there is a similar file with ".OK" extension(which is empty).

Lets take an example :

Directory : /usr/interface/test has two files :

ABC.ok is without content

ABC is with content.

"ABC. ok" gets populated by ABAP program, in the end when the entire file is written , so that we do not have the possibility of picking the file in the middle.

Now i have to write a Adapter module to check following things :

1) if " ABC.OK " exists then pick up the actual file with content

2) Delete the "ABC.OK" file

3) Move the actual file to archive folder for future reference.

Could you please help in this .



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Jun 11, 2012 at 03:59 PM

    Hi Ravi,

    I have described working with trigger files in PI in one of my Wikis below, have a look and let me know if you still have some questions:



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 12, 2012 at 10:23 AM


    Even I had a similar requirement, I went to additional file option, where I check for ".ok" file existence in the folder and then pick the original file.

    Note: This option only works in NFS and does not work when you use FTP parameters.

    You may need a Adapter module when u use FTP option.


    Sainath Chutke

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Ravi,

      Are you open to making changes to the ABAP program that writes the file and the file.OK?

      Instead of writing a file.OK at the end of writing the original file, it can simple rename the original file right?

      like while writing the file, name it as temp.txt and atthe end, rename it to ABC.txt.

      This way you can do away with the adapter modules and java code.

      Best Regards,

      Ravikanth Talagana

  • Posted on Jun 11, 2012 at 05:21 PM

    Hi Ravi,

    I feel u can use shell scripts like this

    while [ 1 -gt 0 ] # infinite loop
    if [ -f "ABC.OK" ] ; then # check in current folder if ABC.Ok exists or not

    mv ABC /usr/interface/test/inbound #move the file ABC to /usr/interface/test/inbound folder
    rm -f ABC.OK #delete ABC.OK


    sleep 1h # sleep for one hour the Unix sleep command

    The script runs in infinite loop in folder /usr/interface/test. checks for abc.ok and puts ABC to inbound folder from where PI picks it up. Then abc.ok is deleted . script runs after every 1 hour.



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 11, 2012 at 07:17 PM

    I dont recommend Adapter module , handle using Schell scripts .

    Try Anupam Approach.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Ravi,

      Its possible to write a adapter module to put all functionality you have mentioned, though I never wrote one like this one earlier. While looking for solutions without adapter module I thought of this one

      1. use a sender communication channel to pick up file only with name ABC after regular intervals of time.

      2. Do an FCC if reqd and let the data flow into a mapping.

      3. In the mapping have an UDF as shown below. This UDF has following functions

      a. Check if there is a file (created on current date) in the same folder from where ABC has been

      picked up.

      b. Check if the name of the file in step a is ABC.ok or not.

      c. If answer to step b is "yes" process the file in further mappings. If answer step b is "no"

      then raise an exception to stop the mapping further.

      I feel this scenario is feasible to achieve. The way to stop a mapping is shown here in this article

      In case you do not want to stop the mapping with an exception then depending on the value returned by the UDF in step 3 (say 0-success,1- failure) , the second mapping will either execute or add error trace in sxmb_moni as shown in this thread .

      so interface is

      pick file ABC---->map1 with UDF---->check return value in map2 ----> add trace in sxmb_moni or

      proceed with creating the target file.



  • Posted on Jun 12, 2012 at 01:23 AM

    Just few cents... If your requirement is so generic and usable for different interfaces you might still consider creating adapter module. But IMO, since the requirement is just to make a call to OS and do the following things like list the files in a directory and check whether desired file exists or not, delete the files and moving the desired file to the specified directory. All these simple operations can be well handled with few lines of codes in script. So I would go for writing script for this case. If you need to write those commands you can search online for writing those unix commands.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.