TABLES:zsddest,DBCON,ZNTB2B01.
DATA:A_DSOURCE LIKE DBCON-CON_NAME,
B_DSOURCE LIKE DBCON-CON_NAME.
TYPES:BEGIN OF GTY_ITAB1,
NO TYPE C,
END OF GTY_ITAB1.
DATA: gs_itab1 TYPE gty_itab1,
gt_itab1 TYPE TABLE OF gty_itab1.
DATA: BEGIN OF ITAB2 OCCURS 1,
REPID TYPE ZNTB2B01-REPID,
CUSTOMER_ID TYPE ZNTB2B01-KUNAG,
FILE_NAME TYPE STRING,
END OF ITAB2.
START-OF-SELECTION.
CLEAR GS_ITAB1.
REFRESH GT_ITAB1.
GS_ITAB1-NO = ‘X‘.
APPEND GS_ITAB1 TO GT_ITAB1.
GS_ITAB1-NO = ‘Y‘.
APPEND GS_ITAB1 TO GT_ITAB1.
PERFORM CONNECT_B. "连接 B 库
* PERFORM CONNECT_A. "连接 A
LOOP AT GT_ITAB1 INTO GS_ITAB1.
* PERFORM CONNECT_B.
* 以下SET CONNECTION 是为了设置连接CONNB,否则在断开 A 时,会同时将B 断开
EXEC SQL.
SET CONNECTION ‘CONNB‘
ENDEXEC.
PERFORM GETDATA_B. "从 B 获取数据
PERFORM CONNECT_A. "连接 A
PERFORM DISCONNECT_A. "断开 A
* PERFORM CONNECT_A. "连接 A
ENDLOOP.
*PERFORM DISCONNECT_A. "断开 A
PERFORM DISCONNECT_B.
FORM CONNECT_A.
SELECT SINGLE CON_VALUE INTO A_DSOURCE FROM ZDBCON WHERE CON_NAME = ‘EDWN1_TEST‘.
IF A_DSOURCE IS INITIAL.
MESSAGE ‘NOT FOUND CONNECT_A.‘ TYPE ‘I‘.
EXIT.
ENDIF.
EXEC SQL.
CONNECT TO :A_DSOURCE AS ‘CONNA‘
ENDEXEC.
IF SY-SUBRC <> 0.
MESSAGE ‘CONNECT_A 连接失败‘ TYPE ‘I‘.
EXIT.
ELSE.
MESSAGE ‘CONNECT_A 连接成功‘ TYPE ‘I‘.
ENDIF.
ENDFORM.
FORM DISCONNECT_A.
EXEC SQL.
DISCONNECT ‘CONNA‘
ENDEXEC.
IF SY-SUBRC = 0.
MESSAGE ‘CONNECT_A 断开连接‘ TYPE ‘I‘.
ENDIF.
ENDFORM.
FORM CONNECT_B.
SELECT SINGLE CON_VALUE INTO B_DSOURCE FROM ZDBCON WHERE CON_NAME = ‘ESRDEV‘.
IF B_DSOURCE IS INITIAL.
MESSAGE ‘NOT FOUND CONNECT_B.‘ TYPE ‘I‘.
EXIT.
ENDIF.
EXEC SQL.
CONNECT TO :B_DSOURCE AS ‘CONNB‘
ENDEXEC.
IF SY-SUBRC <> 0.
MESSAGE ‘CONNECT_B 连接失败‘ TYPE ‘I‘.
EXIT.
ELSE.
MESSAGE ‘CONNECT_B 连接成功‘ TYPE ‘I‘.
ENDIF.
ENDFORM.
FORM DISCONNECT_B. ":B_DSOURCE
EXEC SQL.
DISCONNECT ‘CONNB‘
ENDEXEC.
IF SY-SUBRC =