07-22-2010 7:16 AM
Hi ,
I need ABAP program to read and write data on MS SQL server.
The SAP System is based on AIX system and Oracle DB.
The MS SQL is based on Windows Server System.
How to do this?
Thanks.
07-22-2010 7:33 AM
Hello,
First is crerate a connexion with the target MS SQL. Use the trasaction DBCO.
Next, You must use EXEC SQL instruction. I give to you an example for read that I use :
For writting, is the same think. The request SQL must change in update or insert
Thierry
DATA dbtype TYPE dbcon_dbms. "dbtype chaine de caractere
DATA wl_con_name TYPE dbcon-con_name.
DATA wl_info_con(3).
DATA wa_sytabix TYPE sy-tabix.
DATA matnr_temp TYPE mara-matnr.
DATA refart TYPE mara-matnr.
DATA consi TYPE zed_cons.
wl_con_name = 'CONN_SQL_DATAB'.
SELECT SINGLE dbms FROM dbcon INTO dbtype WHERE con_name = wl_con_name.
IF dbtype = 'MSS'.
TRY.
*Connexion a la base de donnée
EXEC SQL.
CONNECT TO :wl_con_name
ENDEXEC.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_sy_native_sql_error.
ELSE.
MESSAGE s258(zm) WITH wl_info_con.
ENDIF.
*Recupération des données
EXEC SQL.
OPEN WRECORDSET FOR SELECT Refart, consi FROM Articles
ENDEXEC.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_sy_native_sql_error.
ENDIF.
DO.
EXEC SQL.
FETCH NEXT WRECORDSET INTO :Refart, :Consi
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ENDIF.
CLEAR wa_comp.
CLEAR wa_sytabix.
READ TABLE wt_comp INTO wa_comp WITH KEY matnr = refart.
IF sy-subrc = 0.
wa_sytabix = sy-tabix.
IF consi = 'F'.
wa_comp-consi = 'Non'.
ELSE.
IF consi = 'T'.
wa_comp-consi = 'Oui'.
ELSE.
wa_comp-consi = ''.
ENDIF.
ENDIF.
MODIFY wt_comp INDEX wa_sytabix FROM wa_comp.
ELSE.
ENDIF.
ENDDO.
*on ferme tout
EXEC SQL.
CLOSE WRECORDSET
ENDEXEC.
EXEC SQL.
DISCONNECT :wl_con_name
ENDEXEC.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in Native SQL.` TYPE 'I'.
ENDTRY.
ENDIF.
07-22-2010 8:18 AM
According to note 178949 you must have at least one application server running on Windows in order to connect to SQL Server with MultiConnect mechanism you mentioned. See the note for details.
regards
07-22-2010 8:35 AM
Hello,
It s true, I forgotten that our administrator put DLL in that folder D:\usr\sap\REC\DVEBMGS00\exe on SAP system.
Thierry
07-22-2010 8:03 AM
Hello,
You can do this, but you must use external windows program and SAP RFC functunality
Sample,
1 - Write a small program that will reach the SQL server any win language.
2- Write Remote Enabled FM in a Abap for win program access
3 - When you want to reach the SQL server in a abap, shell win program and program getting access SQL server and collect data,
4 - After the program may send the information it collects to SAP using RFC consept.
This is may a little complicated. But it works. I do this for comport programming.
RFC FM
http://abaplovers.blogspot.com/2008/03/sap-rfc.html
Delphi Connection
I hope it will help you.
Regards
İrfan.
Edited by: Irfan MATAK on Jul 22, 2010 9:04 AM