cancel
Showing results for 
Search instead for 
Did you mean: 

How to do File Comparison in SAP PI

Former Member
0 Kudos

Hi All,

I have another requirement.

I have two text files, both containing a list of materials. I want to compare file A with file B and add the materials from file B that are not in file A.

For example

Input: File A

15-G

12-B

18-A

18-D

Input: File B

15-J

12-B

19-C

Output: Updated File A

15-G

12-B

18-A

18-D

15-J

19-C

As you can see the material 12-B already exists in file A so it isnu2019t copied across but 15-J and 19-C were copied across. Do you know how I could do this?

Any suggestion.

Thanks,

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member184681
Active Contributor
0 Kudos

Hi,

You can also try without additional DB, but this might require complicated mapping logic. Read both files in sender file adapter, use ABAP mapping (should be much easier than graphical one, as some quite complicated logic is required to detect and delete duplicates) and write the results to target file with File Construction Mode = Create in receiver CC.

Hope this helps,

Greg

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

1. set up a small DB (any)

2. use FILE - DB with update on the DB

3. send both files via this interface

4. get the updated list of records from the DB

nice and smooth

Regards,

Michal Krawczyk

Former Member
0 Kudos

HI Michal,

Thanks for your quick answer.

I am wondering is there any other alternative available in case of no database.

Thanks,

Iqbal

Former Member
0 Kudos

Dear Iqbal

You can try command level arguments, following should be the approach

1. Put both the incoming files in a folder

2. run as os level command in the communication channel to compare and write the result in a third file

diff FILE1 FILE2 >>FILE3

3. The FILE3 will only have those values which are not in FILE2.

4. Now you can merge the two files (FILE1 and FILE3) in whatever way you like.

Regards

Sourabh

Former Member
0 Kudos

You can always use a bpm. By changing the collect pattern you can have more than two files added to the same update.

Every new file adds just the information that is not already in the container.

this might help [http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2034] [original link is broken] [original link is broken]; it's for idocs but you can change it for files

baskar_gopalakrishnan2
Active Contributor
0 Kudos

There are several possible ways for file comparison. You might want to see the feasiblity at your end. Using os command to compare the files is simpler approach. I would recommend it. Also if you good at java programming, you can write the file1 in the file3 and load the file1 data in list object and check with file2 data and then save the records that are not existing in the file3. This is another approach. I think you should handle without pi for this.

former_member184681
Active Contributor
0 Kudos

Hi,

The easiest approach is to do as I described above:

Read both files in sender file adapter, use ABAP mapping (should be much easier than graphical one, as some quite complicated logic is required to detect and delete duplicates) and write the results to target file with File Construction Mode = Create in receiver CC.

And use the Additional File(s) feature of the sender channel to get multiple files, as described here in Q4 and Q5:

http://wiki.sdn.sap.com/wiki/display/XI/SenderFileAdapterFrequentlyAsked+Questions

Hope this helps,

Greg

Ryan-Crosby
Active Contributor
0 Kudos

Hi,

I would absolutely agree with Baskar regarding the approach here. There is no reason to overly complicate such a simple file comparison scenario by involving PI. A java program could be written in a matter of minutes to do this file comparison and update.

Regards,

Ryan Crosby

Former Member
0 Kudos

Dear Sourabh,

Thanks for your nice idea.

Can you please tell me how to merge the files.

That is the only approach which looks easy as compare to other.

Thanks,

anupam_ghosh2
Active Contributor
0 Kudos

Hi Muhammad,

To suggest complete solution to the problem certain informations are required

1. what is the Operating system of the PI server.

2. You need a script here either batch file or shell script depending on your answer to first question.

3. How will the script determine when to compare two file contents and which files to choose to comapre?

4. In what manner files are arriving in the server? is it only two files at a time or multiple files may arrive in any order?

Regards

Anupam