連接名稱 任意輸入
DBMS MSS "以MS SQL為範例
使用者名稱 ******
資料庫密碼 ******
連結資訊 MSSQL_SERVER=主機名稱或IP MSSQL_DBNAME=資料庫名稱
*********************************************************************************
FORM connet_ext_db .
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
CONNECT TO :'連接名稱'
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
ENDFORM. " CONNET_EXT_DB
*********************************************************************************
FORM select_into_structure.
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
SELECT 外部欄位
INTO :內部欄位
FROM 外部表格
WHERE 外部欄位 = :內部欄位
and 外部欄位 = :內部欄位
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
IF error_text IS INITIAL.
WRITE: / 執行成功.
ELSE.
WRITE: / 執行失敗.
ENDIF.
ENDFORM. " SELECT_INTO_STRUCTURE
*********************************************************************************
FORM update_rows.
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
UPDATE 外部表格
SET 外部欄位 = :內部欄位,
外部欄位 = :內部欄位
WHERE 外部欄位 = :內部欄位
AND 外部欄位 = :內部欄位
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
IF error_text IS INITIAL.
WRITE: / 執行成功.
ELSE.
WRITE: / 執行失敗.
ENDIF.
ENDFORM. " UPDATE_ROWS
*********************************************************************************
FORM insert_rows.
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
INSERT INTO 外部表格
( 外部欄位, 外部欄位 )
VALUES
( :內部欄位, :內部欄位 )
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
IF error_text IS INITIAL.
WRITE: / 執行成功.
ELSE.
WRITE: / 執行失敗.
ENDIF.
ENDFORM. " INSERT_ROWS
*********************************************************************************
FORM disconnet_ext_db .
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
commit work
ENDEXEC.
EXEC SQL.
DISCONNECT '連接名稱'
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
ENDFORM. " DISCONNET_EXT_DB