Monitoring a Local or Shared Folder for a File using PCo
This blog post explains about how to Monitor a Local or a Shared Folder for a file and process the contents of the File using SAP PCo and SAP MII. It uses an SAP PCo Agent called File Monitor Agent which is available in PCo 2.2 and above. It Works in both Notification and Query Mode
In PCo you define which folder is to be monitored. If the agent finds a file that meets the configuration criteria that you specified in the PCo, then it generates, for example, a notification message and sends it to the connected destination system. In this way you can transfer file contents to the destination system. You can also define specific actions to be done like Moving, Copying, Renaming the files.
Let us see step by step procedure using an example.
Creation of Source System
- Go to SAP PCo Management Console
- Click on Add New Source System.
- Choose the Source System type as FileMonitorAgent and create one
- After the Source System has been created, in the Settings Tab of the new Source System, Browse the folder you need to Monitor and enter the File Mask as needed, (in our case I am giving it as ‘*.csv’ to monitor csv files). default is “*.*”
- And choose one of the File Handling Actions from the below Dropdown, (Default is DoNothing). In Case of Move, Copy or Rename, you must choose a Destination Folder using the Folder Browse button
- You cannot choose a System Folder for Monitor and Destination,
- You can obviously monitor a Network Folder which is shared from another system or server as well. In that case you can give the shared folder path in the Folder to monitor like (\\Servername\SharedFolderPath)
- Check the Ignore unavailability of UNCFolders if you are using a network shared folder as, the network folder might be disconnected often which will stop the agent
- In case if Authentication is needed to access the Folder if it is a Shared Folder, you can give the credentials in the Authentication Tab. Click to Test the Connection
- Save the Changes
Creation of Destination System
- Add the MII System as a New Destination System
- Give SAP MII Server Details and Credentials and Save the Destination System
Creation of Agent Instance
- Create an Agent Instance and choose the Source System as the “MonitorFolder”.
- Once the Agent instance has been created, Go to Subscription Tab and add the tags to be monitored by following below steps
- Click on Browse and a Tag Browser opens
- Click on Browse again in the Browse Pop up so as to see the available Tags
- Select them and Click “Add Selected Items” and Click OK
- Now the Subscription items have been added
- Click on the Query ports Tab and Choose SAP MII as the Port Type and type an unused port of SAP MII Server from where the File Monitor Agent can be queried
- Save the Agent Instance
Creation of Notification
- Right Click on the Agent instance and Click on “Add Notification” and create a New Notification
- In the trigger tab, Keep the Trigger Type as Always and check the Enabled checkbox.
- In the Output Tab, click the Generate Expressions to generate all the subscription items of the Agent.
- Meanwhile in SAP MII, Destination System, Create a Simple Transaction with XML Saver which can save the XML input from PCo Notification
- In the Destinations Tab, Add the Already configured SAP MII Destination System
- In the Destination Tab, Browse the already created transaction in SAP MII and map the Input Parameter Name
- Save the Changes.
Testing the Notification
- Start the Agent
- Paste a CSV File in the folder which PCo is monitoring. As we are Moving the files, in few seconds we can see that the file is disappearing
- Now the Notification should have run automatically.
- Now we can go and check the Workbench for a newly saved XML file which we received from PCo Notification
- Now MII has received the File Content through PCo File Monitor Notification, Which an MII expert can parse and use it as necessary
- Create a PCo Dataserver in SAP MII.
- Choose the Connector type as PCo Connector and Click Next
- Enter PCo wsdl and Click Next and give credentials.
- All the PCo Agents will appear, Choose the appropriate Agent
- Click Finish, Enable and Save the Data server.
- Make sure that you have few files in the Folder which is being monitored by SAP PCo. Which means that it should not be in Move File Handling Action mode in the Source System
- Go to the SAP MII Workbench and create a PCo Query and choose the new Data Server
- Choose “Tag Retrieve Query” mode and go to Tag Retrieve Query tab. The available Files in the Monitored folder will appear and you can select the files as needed.
- Execute the Query and check the result, as the different file contents will appear in different Rowsets.
We can use other file types as also such as .txt, .log etc using File Monitor Agent