|
ODBC in Abap by ravi Sharma |
|
|
|
|
Written by Ravi Sharma
|
|
Thursday, 26 April 2007 |
An ODBC connectivity from ABAP to different Databases.
report zra_ODBC no standard page heading. *----------------------------------------------------------------------* INCLUDE ole2incl. *----------------------------------------------------------------------* DATA: con TYPE ole2_object, rec TYPE ole2_object, SQL(1023). DATA: BEGIN OF SPL OCCURS 0, VAL(1023), END OF SPL, sindx TYPE I. parameters: pemcode(5). tables: sscrfields. *----------------------------------------------------------------------* initialization. perform openconnection. *----------------------------------------------------------------------* at selection-screen. *----------------------------------------------------------------------* start-of-selection. * write: / 'Querry'. perform Get_Rec. *----------------------------------------------------------------------* end-of-selection. *----------------------------------------------------------------------* form openconnection. SQL = 'DSN=DSN_NAME;UID=USER_ID;PWD=PASSWORD'. IF con-header IS INITIAL OR con-handle = -1. CREATE OBJECT con 'ADODB.Connection'. IF NOT sy-subrc = 0. EXIT. ENDIF. CREATE OBJECT REC 'ADODB.Recordset'. IF NOT sy-subrc = 0. EXIT. ENDIF. ENDIF. CALL METHOD OF CON 'Open' EXPORTING #1 = SQL. endform. *----------------------------------------------------------------------* form closeconnection. free rec. free con. endform. *----------------------------------------------------------------------* form Get_Rec. * Paymast is a table created in another Database with the below fields concatenate 'select name,address from PAYMAST where empcode=' '''' pemcode '''' into SQL. * Query run ... CALL METHOD OF REC 'OPEN' EXPORTING #1 = SQL #2 = CON #3 = '1'. ** Query run ... do. CALL METHOD OF REC 'getstring' = SQL EXPORTING #1 = '2' "Do not modify! #2 = 1 "Do not modify! #3 = '|' "Do not modify! #4 = '|'. "Do not modify! if sy-subrc = 0. REFRESH SPL. CLEAR SPL. SPLIT SQL AT '|' INTO TABLE SPL. loop at SPL. write: / SPL-VAL. endloop. else. exit. endif. enddo. * Remember to close the connection perform close_connection. endform.
Related Items:
|
|
Last Updated ( Thursday, 26 April 2007 )
|