How to extract data from a SAP ABAP system?

Joshua1729 picture Joshua1729 · Feb 2, 2012 · Viewed 10.2k times · Source

I need to extract data from a SAP ABAP system in a format that can then be loaded into an Oracle database (xlsx,csv,dmp.. etc)

Once the data is extracted I'll use Pentaho to upload it into the Oracle database.

Is there a way to extract the data from SAP? I will also need to automate it (the extraction) but that is not too much of a problem right now, I can figure/worry about that part later.

If it is not possible to do so, an explanation why would be helpful!

Answer

mydoghasworms picture mydoghasworms · Feb 2, 2012

You have a number of options to do this.

If you are running SAP BW, there are many standard tools to help you do extractions and automate the processes.

Otherwise, you can write a simple ABAP program (type 1) to read data from tables and put it into a flat file.

Otherwise, you could write a remote-enabled function module (RFC) and call it using SAP's RFC library.

You could also wrap your RFC function with a web service and call it via SOAP/HTTP.

Lastly, if you have access to the database, you might even be able to write a script to extract the data you need.

A simple example of a program to extract something from a DB table:

report ZEXTRACT_EXAMPLE.

data: lt_t001 type table of t001.
data: ls_t001 type t001.
data: lv_filename type string value '/tmp/outfile.txt'.

select * from t001 into table lt_t001.

open dataset lv_filename for output in text mode encoding default.

loop at lt_t001 into ls_t001.
  transfer ls_t001-bukrs to lv_filename.
endloop.

close dataset lv_filename.

This is really primitive, but you get the idea. It selects data from a DB table into an internal table (in memory) and writes it to a file called /tmp/outfile.txt on the server, from where you can pick it up. (You would have to alter the output to be in your required format).

You could then schedule your program with SM36 to run periodically as a background job.