SAP ERP系統(tǒng)如何使用中間數(shù)據(jù)庫與其它系統(tǒng)進(jìn)行數(shù)據(jù)交互?
當(dāng)前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
SAP軟件Webservice接口技術(shù)應(yīng)用中間數(shù)據(jù)庫作為系統(tǒng)間交互數(shù)據(jù)的基本機(jī)制使用中間數(shù)據(jù)庫作為系統(tǒng)間交互數(shù)據(jù)的優(yōu)缺點分析 SAP ERP系統(tǒng)如何使用中間數(shù)據(jù)庫 SAP ERP系統(tǒng)連接中間數(shù)據(jù)庫的配置下面通過一個例子來介紹下SAP如何對中間數(shù)據(jù)庫的數(shù)據(jù)進(jìn)行插入/更新/刪除等操作。 1.SAP取出未審批的PR數(shù)據(jù) TYPES : BEGIN OF TY_DATA, BANFN TYPE BANFN, "采購申請?zhí)?/p> BNFPO TYPE BNFPO, "采購申請項目 MATNR TYPE MATNR, "物料編碼 TXZ01 TYPE TXZ01, "物料描述 MENGE TYPE MENGE, "數(shù)量 MEINS TYPE MEINS, "數(shù)量單位 STATUS(1) TYPE C, "狀態(tài) 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.連接中間數(shù)據(jù)庫 *&---------------------------------------------------------------------* *& FRM_CONNECT_EXT_DB . *&---------------------------------------------------------------------* * 1.連接外部數(shù)據(jù)庫 *----------------------------------------------------------------------* 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數(shù)據(jù)推送至中間數(shù)據(jù)庫 *&---------------------------------------------------------------------* *& FRM_INSERT_EXT_DB *&---------------------------------------------------------------------* * 3.插入多條數(shù)據(jù)到外部數(shù)據(jù)庫 *----------------------------------------------------------------------* 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.更新中間數(shù)據(jù)庫的值 *&---------------------------------------------------------------------* *& FRM_UPDATE_EXT_DB *&---------------------------------------------------------------------* * 4.更新外部數(shù)據(jù)庫 *----------------------------------------------------------------------* 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的狀態(tài) 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.查詢中間數(shù)據(jù)庫到SAP程序內(nèi)表 *&---------------------------------------------------------------------* *& FRM_SELECT_EXT_DB_ALL *&---------------------------------------------------------------------* * 5.1.查詢數(shù)據(jù),查詢多條數(shù)據(jù)到內(nèi)表 *----------------------------------------------------------------------* 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.查詢數(shù)據(jù),查詢多條數(shù)據(jù)到內(nèi)表 *----------------------------------------------------------------------* FORM FRM_APPEND_DATA . APPEND GS_EBAN TO GT_EBAN. CLEAR GS_EBAN. ENDFORM. "FRM_APPEND_DATA 6.刪除中間數(shù)據(jù)庫 *&---------------------------------------------------------------------* *& FRM_APPEND_DATA. *&---------------------------------------------------------------------* * 6.刪除外部數(shù)據(jù)庫表數(shù)據(jù) *----------------------------------------------------------------------* 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.關(guān)閉連接 *----------------------------------------------------------------------* FORM FRM_DISCONNECT_EXT_DB . EXEC SQL. DISCONNECT :l_CON_NAME ENDEXEC. ENDFORM. "FRM_DISCONNECT_EXT_DB 該文章在 2024/3/14 9:58:17 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |