在连接信息中加入MDORA92.WORLD为底层配置的名称,
:ZHS16GBK是为了避免产生乱码
3.编写程序实现SAP访问外部ORACLE数据库,下面的例子是个连接外部数据库过程:
REPORT ZMM_BFS_DATABASE_CONNECT.
INCLUDE .
************************************************************************
* Parameters and Select Options
************************************************************************
PARAMETERS:
CON_NAME TYPE DBCON-CON_NAME OBLIGATORY.
************************************************************************
* Global variables
************************************************************************
DATA:
SQLERR_REF TYPE REF TO CX_SQL_EXCEPTION,
CON_REF TYPE REF TO CL_SQL_CONNECTION,
DEV_FILE(10) TYPE C.
************************************************************************
START-OF-SELECTION.
************************************************************************
TRY.
CON_REF = CL_SQL_CONNECTION=>GET_CONNECTION( CON_NAME ).
CATCH CX_SQL_EXCEPTION INTO SQLERR_REF.
WRITE:'无法打开数据库连接,连接名:', CON_NAME, '.'.
IF SQLERR_REF->UNKNOWN_CONNECTION = 'X'.
WRITE:/ CON_NAME, '没有定义在表DBCON,请用事务DBCO维护'.
ELSEIF SQLERR_REF->DB_ERROR = 'X'.
WRITE:/ 'SQL ERROR', SQLERR_REF->SQL_CODE, 'OCCURED:',
/ SQLERR_REF->SQL_MESSAGE.
ELSE.
PERFORM GET_TRACE_FILE USING DEV_FILE.
WRITE:/ 'DBI ERROR', SQLERR_REF->INTERNAL_ERROR, 'OCCURED.',
/ 'SEE TRACE FILE FOR FURTHER INFO:',
ICON_READ_FILE AS ICON HOTSPOT, DEV_FILE.
ENDIF.
RETURN.
ENDTRY.
WRITE:/ CON_NAME, '成功连接'.
CON_REF->CLOSE( ).
************************************************************************
END-OF-SELECTION.
************************************************************************
************************************************************************
AT LINE-SELECTION.
************************************************************************
* Display the trace file
IF NOT DEV_FILE IS INITIAL.
CALL FUNCTION 'STRC_DISPLAY_WP_TRACE'
EXPORTING
FILE = DEV_FILE
EXCEPTIONS
OTHERS = 4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form GET_TRACE_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_DEV_FILE text
*----------------------------------------------------------------------*
FORM GET_TRACE_FILE USING P_DEV_FILE TYPE C.
DATA:WP_NO TYPE WPINFO-WP_NO.
* get the number of the current WP and append it to 'dev_w'
P_DEV_FILE = 'DEV_W'.
CALL FUNCTION 'TH_GET_OWN_WP_NO'
IMPORTING
WP_NO = WP_NO.
P_DEV_FILE+5 = WP_NO.
ENDFORM. "get_trace_file