SAP ERP系统如何使用中间数据库与其它系统进行数据交互?
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
SAP软件Webservice接口技术应用中间数据库作为系统间交互数据的基本机制使用中间数据库作为系统间交互数据的优缺点分析 SAP ERP系统如何使用中间数据库 SAP ERP系统连接中间数据库的配置下面通过一个例子来介绍下SAP如何对中间数据库的数据进行插入/更新/删除等操作。 1.SAP取出未审批的PR数据 TYPES : BEGIN OF TY_DATA, BANFN TYPE BANFN, "采购申请号 BNFPO TYPE BNFPO, "采购申请项目 MATNR TYPE MATNR, "物料编码 TXZ01 TYPE TXZ01, "物料描述 MENGE TYPE MENGE, "数量 MEINS TYPE MEINS, "数量单位 STATUS(1) TYPE C, "状态 END OF ty_data. DATA : GT_EBAN TYPE TABLE OF TY_DATA, GS_EBAN TYPE TY_DATA. DATA :V_EXC_REF TYPE REF TO CX_SY_NATIVE_SQL_ERROR, V_ERRTXT TYPE STRING, V_SQLERR_REF TYPE REF TO CX_SQL_EXCEPTION. DATA:Z_CON_NAME TYPE CHAR40 ."VALUE 'BPM782'. Z_CON_NAME = 'BPM80'. "连接名称 CLEAR: GS_EBAN,GT_EBAN. SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_EBAN FROM EBAN WHERE WERKS = '171O'AND FRGKZ = 'X' AND LOEKZ <> 'X'. 2.连接中间数据库 *&---------------------------------------------------------------------* *& FRM_CONNECT_EXT_DB . *&---------------------------------------------------------------------* * 1.连接外部数据库 *----------------------------------------------------------------------* FORM FRM_CONNECT_EXT_DB . TRY. " 连接 EXEC SQL. CONNECT TO :Z_CON_NAME "连接名称 ENDEXEC. CATCH CX_SY_NATIVE_SQL_ERROR INTO V_EXC_REF. V_ERRTXT = V_EXC_REF->GET_TEXT( ). CATCH CX_SQL_EXCEPTION INTO V_SQLERR_REF. IF V_SQLERR_REF->DB_ERROR = 'X'. V_ERRTXT = V_SQLERR_REF->SQL_MESSAGE. ELSE. V_ERRTXT = V_SQLERR_REF->INTERNAL_ERROR. ENDIF. ENDTRY. IF V_ERRTXT IS NOT INITIAL. E_STATUS = 'E'. E_MESSAGE = V_ERRTXT. ELSE. E_STATUS = 'S'. E_MESSAGE = '连接成功!'. ENDIF. ENDFORM. 3.将取出PR数据推送至中间数据库 *&---------------------------------------------------------------------* *& FRM_INSERT_EXT_DB *&---------------------------------------------------------------------* * 3.插入多条数据到外部数据库 *----------------------------------------------------------------------* FORM FRM_INSERT_EXT_DB . TRY. LOOP AT GT_EBAN INTO GS_EBAN. EXEC SQL. INSERT INTO ZPR_EBAN_DATA ( BANFN, BNFPO, MATNR, TXZ01, MENGE, MEINS, STATUS ) VALUES ( :GS_EBAN-BANFN, :GS_EBAN-BNFPO, :GS_EBAN-MATNR, :GS_EBAN-TXZ01, :GS_EBAN-MENGE, :GS_EBAN-MEINS, :GS_EBAN-STATUS ) ENDEXEC. IF SY-SUBRC = 0. EXEC SQL. COMMIT ENDEXEC. ELSE. EXEC SQL. ROLLBACK ENDEXEC. ENDIF. ENDLOOP. ENDTRY. ENDFORM. 4.更新中间数据库的值 *&---------------------------------------------------------------------* *& FRM_UPDATE_EXT_DB *&---------------------------------------------------------------------* * 4.更新外部数据库 *----------------------------------------------------------------------* FORM FRM_UPDATE_EXT_DB USING P_VBELN P_BNFPO . TRY. EXEC SQL. UPDATE ZPR_EBAN_DATA SET STATUS = 1 WHERE BANFN = :P_BANFN AND BNFPO = :P_BNFPO "更新表ZPR_EBAN_DATA中PR的状态 ENDEXEC. COMMIT WORK AND WAIT. CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. ERROR_TEXT = EXC_REF->GET_TEXT( ). EXEC SQL. DISCONNECT :L_CON_NAME ENDEXEC. MESSAGE E006(Z001) WITH ERROR_TEXT. ENDTRY. ENDFORM. "FRM_UPDATE_EXT_DB 5.查询中间数据库到SAP程序内表 *&---------------------------------------------------------------------* *& FRM_SELECT_EXT_DB_ALL *&---------------------------------------------------------------------* * 5.1.查询数据,查询多条数据到内表 *----------------------------------------------------------------------* FORM FRM_SELECT_EXT_DB_ALL . TRY. EXEC SQL PERFORMING FRM_APPEND_DATA. SELECT BANFN, BNFPO, MATNR, TXZ01, MENGE, MEINS, STATUS INTO :GS_EBAN FROM ZPR_EBAN_DATA ENDEXEC. ENDTRY. ENDFORM. "FRM_SELECT_EXT_DB_ALL *&---------------------------------------------------------------------* *& FRM_APPEND_DATA. *&---------------------------------------------------------------------* * 5.2.查询数据,查询多条数据到内表 *----------------------------------------------------------------------* FORM FRM_APPEND_DATA . APPEND GS_EBAN TO GT_EBAN. CLEAR GS_EBAN. ENDFORM. "FRM_APPEND_DATA 6.删除中间数据库 *&---------------------------------------------------------------------* *& FRM_APPEND_DATA. *&---------------------------------------------------------------------* * 6.删除外部数据库表数据 *----------------------------------------------------------------------* FORM FRM_DELETE_DB . TRY. EXEC SQL. DELETE ZPR_EBAN_DATA. ENDEXEC. IF SY-SUBRC = 0. EXEC SQL. COMMIT ENDEXEC. ELSE. EXEC SQL. ROLLBACK ENDEXEC. ENDIF. CATCH CX_SY_NATIVE_SQL_ERROR INTO V_EXC_REF. V_ERRTXT = V_EXC_REF->GET_TEXT( ). CATCH CX_SQL_EXCEPTION INTO V_SQLERR_REF. IF V_SQLERR_REF->DB_ERROR = 'X'. V_ERRTXT = V_SQLERR_REF->SQL_MESSAGE. ELSE. V_ERRTXT = V_SQLERR_REF->INTERNAL_ERROR. ENDIF. ENDTRY. ENDFORM. "FRM_DELETE_DB *&---------------------------------------------------------------------* *& FRM_DISCONNECT_EXT_DB . *&---------------------------------------------------------------------* * 7.关闭连接 *----------------------------------------------------------------------* FORM FRM_DISCONNECT_EXT_DB . EXEC SQL. DISCONNECT :l_CON_NAME ENDEXEC. ENDFORM. "FRM_DISCONNECT_EXT_DB 该文章在 2024/3/14 9:58:17 编辑过 |
关键字查询
相关文章
正在查询... |