ABAP訪問外部SQL (轉)

sapkitty發表於2007-04-14
source is as follows[@more@]
這是一個ABAP訪問外部SQL的你可以參照一下: 首先:   下面將ABAP訪問外部SQL Server的做法完整貼出(已經測試透過) 首先在dbco中建立一個連線。 Connection name:Z_CONN DBMS :MSS User name :sa DB password : sa密碼 Conn. info :MSSQL_SERVER=伺服器名稱或IP地址 MSSQL_DBNAME=資料庫名稱 然後這是一個ABAP的測試例子: REPORT ZRPPTEST . DATA F1(40). TABLES dbcon. PARAMETERS: conexion LIKE dbcon-con_name. try. EXEC SQL. CONNECT TO :conexion ENDEXEC. EXEC SQL. SET CONNECTION :conexion ENDEXEC. CATCH cx_sy_native_sql_error. WRITE 'FALLUSE'. endtry. *DATA: BEGIN OF WA, * ContainerName(40), * END OF WA. *EXEC SQL. * SELECT ContainerName INTO :WA FROM Container *ENDEXEC. * try. * EXEC SQL. * CONNECT TO :p_dbconname * ENDEXEC. * EXEC SQL. * SET CONNECTION :p_dbconname * ENDEXEC. * * CATCH cx_sy_native_sql_error. * p_subrc = '99'. * ENDTRY. * IF sy-subrc = 0. WRITE 'ok'. ELSE. WRITE 'FALLUSE'. ENDIF. EXEC SQL. OPEN C1 FOR SELECT ContainerName FROM Container ENDEXEC. DO. EXEC SQL. FETCH NEXT C1 INTO :F1 ENDEXEC. IF SY-SUBRC <> 0. EXIT. ENDIF. WRITE: / F1. ENDDO. EXEC SQL. CLOSE C1 ENDEXEC. *EXEC SQL. *DO. * FETCH NEXT CURSOR C1 INTO wa. * IF SY-SUBRC <> 0. * CLOSE CURSOR C1. * EXIT. * ENDIF. * WRITE: / wa-ContainerName. * *ENDDO. *ENDEXEC.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8214011/viewspace-910684/,如需轉載,請註明出處,否則將追究法律責任。

相關文章