Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to pull data from sql server ( Seperate server) & upload it into sap

Former Member
0 Likes
616

Hi All,

I have a SQL Server database in System1,

data base name DB1

Table name TB1

I want pull data from TB1 & upload the same into ztable in SAP.

How I can I achive this in ABAP.

Thanks in Advance

Appropriate points will be rewarded.

Arun kumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
553

Hi Arun,

You have to do the following:

1. Create an entry in Trxn DBCA for SQL Server in SAP, you are creating a database connection for the SQL server in SAP.

2. You use this connection, and write Native SQL stmnts...between EXECSQL...ENDEXEC to fetch the data..and then normal ABAP statements to put that data into your ztable.

Regards,

Raj

For eg:

TABLE DBCON Entry can be like this...depends on your External database..

CON_NAME Raj Logical name for connection

DBMS MSS Microsoft SQL Server

USER_NAME <User name> For SQL Serve

PASSWORD <password> " "

CON_ENV MSSQL_SERVER=<server> MSSQL_DBNAME=<database name>

DB_RECO Availability type for an open database connect

FUNCTION z_houston_connect.

*"----


""Local interface:

*"----


EXEC SQL.

CONNECT TO 'RAJ' AS 'V'

ENDEXEC.

EXEC SQL.

SET CONNECTION 'V'

ENDEXEC.

*- Get the data from MS-SQL Server

EXEC SQL.

open C1 for

select

l.loc_id,

l.loc_name,

a.acc_id,

a.acc_name,

d.person

from ho_loc_mast as l

inner join snd_acc_mast as a on l.loc_id = a.loc_id

inner join snd_acc_addr as d on a.loc_id = d.loc_id and

a.acc_id = d.acc_id

where l.loc_id = '001'

ENDEXEC.

DO.

EXEC SQL.

FETCH NEXT C1 into :wa-c_locid, :wa-c_locname, :wa-c_acc_id, :wa-c_acc_name, :wa-c_person

ENDEXEC.

IF sy-subrc = 0.

PERFORM loop_output.

ELSE.

EXIT.

ENDIF.

ENDDO.

EXEC SQL.

CLOSE C1

ENDEXEC.

ENDFUNCTION.

3 REPLIES 3
Read only

sourabhshah
Product and Topic Expert
Product and Topic Expert
0 Likes
553

hi,

SAP systems are DB independant.When a table is created in ABAP dictionary and activated a corresponding table is created in the database.Hence if you know the table in ABAP Dictinary you dont have to worry about the DB. Just write a open SQL statement 'select' and populate the ztable.

Regards,

Sourabh

Read only

Former Member
0 Likes
554

Hi Arun,

You have to do the following:

1. Create an entry in Trxn DBCA for SQL Server in SAP, you are creating a database connection for the SQL server in SAP.

2. You use this connection, and write Native SQL stmnts...between EXECSQL...ENDEXEC to fetch the data..and then normal ABAP statements to put that data into your ztable.

Regards,

Raj

For eg:

TABLE DBCON Entry can be like this...depends on your External database..

CON_NAME Raj Logical name for connection

DBMS MSS Microsoft SQL Server

USER_NAME <User name> For SQL Serve

PASSWORD <password> " "

CON_ENV MSSQL_SERVER=<server> MSSQL_DBNAME=<database name>

DB_RECO Availability type for an open database connect

FUNCTION z_houston_connect.

*"----


""Local interface:

*"----


EXEC SQL.

CONNECT TO 'RAJ' AS 'V'

ENDEXEC.

EXEC SQL.

SET CONNECTION 'V'

ENDEXEC.

*- Get the data from MS-SQL Server

EXEC SQL.

open C1 for

select

l.loc_id,

l.loc_name,

a.acc_id,

a.acc_name,

d.person

from ho_loc_mast as l

inner join snd_acc_mast as a on l.loc_id = a.loc_id

inner join snd_acc_addr as d on a.loc_id = d.loc_id and

a.acc_id = d.acc_id

where l.loc_id = '001'

ENDEXEC.

DO.

EXEC SQL.

FETCH NEXT C1 into :wa-c_locid, :wa-c_locname, :wa-c_acc_id, :wa-c_acc_name, :wa-c_person

ENDEXEC.

IF sy-subrc = 0.

PERFORM loop_output.

ELSE.

EXIT.

ENDIF.

ENDDO.

EXEC SQL.

CLOSE C1

ENDEXEC.

ENDFUNCTION.

Read only

Former Member
0 Likes
553

Hi Arun,

In addition, You can try this approach also,

Create a Flat File from the Non-SAP system(.txt Tab limited or .xls) and Upload it to the Z table through BDC Concept..

Cheers...

Santosh.