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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |