SAP 中可以通过配置数据库的链接,来完成从SAP链接到外部的数据库中进行处理数据,具体操作如下:
1、先进入事务:DBCO,设置数据库链接。进入该事务后,如果系统已经有配置过类似链接则会出现在如下画面中,如图:
2.测试是否联通 ADBC_TEST_CONNECTION
如下代码测试:
data: g_errorstr(250) type c. data g_conexion like dbcon-con_name value ‘ZYUN‘. "ZYUN即DBCO中配置的数据库链接名称 data: exec_ref type ref to cx_sy_native_sql_error, error_text type string, cl_sqlerr_ref type ref to cx_sql_exception. perform sub_conndb using g_conexion. "调用模块,打开数据库链接 try. exec sql . ******根据OPEN SQL 编写SQL 语句 *例: SELECT ANLN, MCOA1, BUKRS, DZSX, AUFNR1 INTO :gw_out-ANLN, :gw_out-MCOA1, :gw_out-BUKRS, :gw_out-DZSX, :gw_out-AUFNR1 FROM ZZTLD_BASE_FI_SALEORDER_004 WHERE ZTYPE is NULL endexec. catch cx_sy_native_sql_error into exec_ref. g_errorstr = exec_ref->get_text( ). concatenate ‘读取数据出错,‘ g_errorstr into g_errorstr. write:/ g_errorstr. catch cx_sql_exception into cl_sqlerr_ref. if not g_errorstr is initial. clear g_errorstr. exec sql. rollback endexec. else. exec sql. COMMIT endexec. endif. endtry. * 关闭连接 exec sql. DISCONNECT :G_CONEXION endexec. *打开数据库链接模块编写 FORM sub_conndb USING conn LIKE dbcon-con_name. CLEAR g_errorstr. g_conexion = conn. TRY. "-- 连接SQL SERVER EXEC SQL. CONNECT TO :G_CONEXION ENDEXEC. CATCH cx_sy_native_sql_error INTO exec_ref. CONCATENATE ‘无法连接至SQL数据库 连接名:‘ g_conexion INTO g_errorstr. ENDTRY. ENDFORM.
exec sql performing pf_get_zz. SELECT AUFNR, KTEXT, BUKRS, DZSX INTO :gw_out-AUFNR, :gw_out-KTEXT, :gw_out-BUKRS, :gw_out-DZSX FROM ZZTLD_BASE_FI_SALEORDER_002 WHERE ztype is NULL endexec. form pf_get_zz. append gw_out to gt_out . clear: gw_out,gw_return. endform.
————————————————
版权声明:本文为CSDN博主「酒剑仙abc」的原创文章,感谢分享!
原文链接:https://blog.csdn.net/fengxin_/article/details/106238126