Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392536
  • 博文数量: 66
  • 博客积分: 1235
  • 博客等级: 少尉
  • 技术积分: 694
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-05 12:24
文章分类

全部博文(66)

文章存档

2010年(66)

分类:

2010-04-19 13:23:46

1.先在SAP底层ORACLE数据库编辑TNS文件,一般由BASIS配置完成.配置完成后我们可以用事务码:AL11查看配置是否正确,路径:DIR_ORAHOME->network->admin->tnsnames.ora查看对应的TNS是否配置正确,如:

MDORA92.WORLD=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.81.2) (PORT = 1521))
)
(CONNECT_DATA =
(SID = mdora92)
(SERVER = DEDICATED)
)
)


2.在SAP中用DBCO配置,如下:

 

在连接信息中加入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

阅读(8553) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

安何2010-04-30 14:11:55

安何2010-04-29 21:52:53