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 tableof t001.
data: ls_t001 type t001.
data: lv_filename type string value '/tmp/outfile.txt'.select*from t001 intotable 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).