Skip to Content
http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/webcontent/uuid/b82710ca-0b01-0010-63a1-bc5344103c45″ width=”235″/>

CSV File Lookup

This Weblog explains how to make a CSV File Lookup in XI Mapping.

The Mapping API which is available in SAP NetWeaver ’04 SPS13, does not extend its support to File Adapter. In such a case we can make Lookup to a CSV file possible by making use of JDBC Adapter. This may sound weird but it’s possible by means of  a driver that makes the flat file (here CSV file) to appear as a database table to the API. Then by making use of the Generic or Special Lookup API we can traverse the file and fetch data in a way we fetch data from the database tables.

Once we have the Driver we have to import that jar file in the Imported Archive area available in the Integration Repository.

image

Once we have imported this file now we can consider the CSV file as a Database table and access it in the Mapping program using a simple user-defined java program.

Here our csv file looks like this

image

Instead of using Mapping API for Lookup, we perform LookUp in an optimized way as given in Optimizing Lookup’s in XI

Code Snippet

I hope this Weblog has really made the CSV File Lookup possible.

To report this post you need to login first.

16 Comments

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

  1. Sravya Talanki
    You could have done the look up using file adapter and store it in intermediate tables of XI and use ABAP Mapping to access the data.You donot require any jdbc drivers etc.I feel that would be a better approach.
    (0) 
    1. Sundararamaprasad Subbaraman Post author
      Hi sravya,
      Thank you for the valuable comments.The approach you mention consists of two works,one storing in the tables and the second one then retreiving data from it.I think the procedure that i have mentioned is much easier to implement and straightforward.
      (0) 
      1. Sravya Talanki
        There is much more use when you store it in ABAP table dumps..than the JDBC drivers when you are accessing it very often..instead of using lookup API’s.
        (0) 
        1. Sravya Talanki
          And also XI files are written on SAP app server.You can access the file inside the RFC and get the data whatever is required from single point RFC.
          Your approach is new ..and good but might not be good while dealing frequent look ups.
          (0) 
          1. Sundararamaprasad Subbaraman Post author
            hi Sravya/Naveen,
            Sravya:
            The main advantage of this JDBC Driver is we can query for a particular record and process that record alone;this one looks better comparing to loading all the data into a dump place and loop it around and check if each data match ours or not .
            naveen:
            Thank you.
            (0) 
            1. Sravya Talanki
              You do not require any JDBC driver for accessing the file as data base lookups.
              You can use ABAP mapping and do the same kind of lookup there which is achievable in java using internal tables .It is similar to resultset in java.I hope the context is clear now.
              (0) 
              1. Sravya Talanki
                You do not require any JDBC driver for accessing the file as data base lookups.
                You can use ABAP mapping and do the same kind of lookup there which is achievable in ABAP using internal tables .It is similar to resultset in java.I hope the context is clear now. That approach is simple to do it.Connecting to ABAP stack in the runtime is better than connecting to java stack.
                Naveen ..was talking about XI database tables..so he is right on his point.
                (0) 
                1. Himadri Chakraborty
                  HI Sravya,

                  I am late coming to this blog..

                  Howvever I guess you might have appreciated the new approach, instead of arguing of the pros and cons… I am not sure when This will be good for me.. however I appreate the concept .. letting go my ego of course..

                  What I mean is First appreciate this and this was interesting and then brainstorm,……….

                  Cheers,
                  Himadi

                  (0) 
              2. Sundararamaprasad Subbaraman Post author
                Hi Sravya,
                Thank you for the alternate Suggestion(using ABAP Mapping). There are many ways in which a solution could be arrived.What I suggested is one of the ways.Consider the scenario where there is an implementation using Graphical mapping or Java Mapping,if we wanna make a lookup there,i dont think its advisable to  go for ABAP mapping for the sake of Lookup purpose alone;this solution (usage of JDBC Driver) will be handy even at such conditions.
                (0) 
                1. Sravya Talanki
                  If volumetric is not a criteria and you want to use java/Graphical mapping then definetly it z the case.But SAP XI providing ABAP and JAVA always rises a debate between ABAP and JAVA franatics..:)…Both stacks are very powerful!!
                  (0) 
      2. Hi prasad/sravya,

        More than ease of implementation, XI should nt be used to store application specific data. THis is strongly disencouraged by SAP.

        Sravya: even though you could load all the data into xi and do the lookup, this solution sounds hooky, because you now have to make sure the data in xi is always in synch with the actual file. This is an never ending debate on who will be responsible for the data synchronization.

        Prasad: In this scenario your approach is more appropiate.

        Cheers,
        Naveen

        (0) 
        1. Sravya Talanki
          Naveen let me put my views across.
          I guess lot of time look ups are performed on master files and they are not very dynamic and huge in nature.
          We need not store the data in XI tables also.
          Instead we can open the file from RFC using OPEN DATASET as it is on SAP app server and provide the look up incase you do not want to load it in temorary tables.
          I feel that is better approach than using any JDBC Adapters.How ever lot of trade off have to be taken depending on the scenario .
          I hope I didnot confuse.Please feel free to bounce if am going wrong anywhere.Debating is interesting when you really exchange good options and opinions..:)
          (0) 
  2. sandeep maurya
    Hello ,
    I have implemented your code in my scenario in a UDF and I am doing testing of the mapping at test tab.   but I am getting the below error message.

    java.lang.ClassNotFoundException: Class org.jdbc.Driver not found

    I have imported these two package also,
    1. java.util.*;
    2. java.sql.*;

    Please reply.

    Thamks,
    -Sandeep

    (0) 
    1. Sundararamaprasad Subbaraman Post author
      Hi Sandeep,
          Please make sure that you have included the proper Driver Jar file in the imported archive. Further, do not put the jar file inside any other folder structure, then zip that parent folder and include it here. That will definetlt cause problems.see to it you import the jar file as it is in the imported archive.
      Regards,
      Sundar
      (0) 
  3. Himadri Chakraborty
    It is bit late of me to come across your blog.
    The approach is preety interesting and new to me.

    Can u let me know what driver is needed for this?

    Many thaks for a Wonderful and most important interesting Blog….

    Cheers,
    Himadri

    (0) 

Leave a Reply