前言
SAP 连接外部数据库有多种方法,这里我们介绍DBCO 连接
DBCO
代码
DATA: OREF TYPE REF TO CX_ROOT,TXT TYPE STRING,M_WERKS TYPE WERKS_D,STRCDATE TYPE C LENGTH 10.
DATA:BEGIN OF T_ITEM OCCURS 0,
CDATE TYPE C LENGTH 10,
END OF T_ITEM.
M_WERKS = '3100'.
TRY.
"连接SQL
exec sql.
connect to 'DN16'
endexec.
"查找数据
EXEC SQL PERFORMING ProcessSQL.
SELECT [CDate] FROM 数据库A INTO :T_ITEM WHERE IIS = '0' AND Werks = :M_WERKS ORDER BY CDate ASC
ENDEXEC.
"插入数据
EXEC SQL.
INSERT INTO 数据库A ( CDate,CDate2) VALUES ( :STRCDATE, :STRCDATE )
ENDEXEC.
EXEC SQL.
COMMIT
ENDEXEC.
"更新数据
EXEC SQL.
UPDATE 数据库A SET CDate = :STRCDATE WHERE IIS = '0' AND Werks = :M_WERKS
ENDEXEC.
EXEC SQL.
COMMIT
ENDEXEC.
"删除数据
EXEC SQL.
DELETE FROM 数据库A WHERE Werks = :M_WERKS
ENDEXEC.
EXEC SQL.
COMMIT
ENDEXEC.
"释放SQL
EXEC SQL.
DISCONNECT 'DN16'
ENDEXEC.
CATCH CX_ROOT INTO OREF.
TXT = OREF->GET_TEXT( ).
MESSAGE S000(ZMSG_WU) WITH TXT .
EXIT.
ENDTRY.
FORM PROCESSSQL.
APPEND T_ITEM.
ENDFORM.