标签:
INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(1,1111);
INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(2,2222);
INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(3,3333);
TEST-PB.
PERFORM BEGIN-TRAN THRU BEGIN-TRAN-EXIT.
MOVE 0 TO WS-AMOUNT.
MOVE SPACES TO WS-ORDER-NBR.
EXEC SQL
DECLARE GET_ORDERS CURSOR WITH HOLD FOR
SELECT ORDER_NBR, AMOUNT FROM
(DELETE FROM STREAM(SOS.ECUI.ORDERS)
FOR SKIP CONFLICT ACCESS) AS ORDERS
END-EXEC.
EXEC SQL
OPEN GET_ORDERS
END-EXEC.
ACCEPT WS-START FROM TIME.
MOVE 0 TO WS-TIME.
PERFORM PROCESS-ORDERS THRU PROCESS-ORDERS-EXIT
UNTIL WS-TIME >10000.
EXEC SQL
CLOSE GET_ORDERS
END-EXEC.
PERFORM END-TRAN THRU END-TRAN-EXIT.
TEST-PB-EXIT.
EXIT.
/
PROCESS-ORDERS.
ACCEPT WS-END FROM TIME.
COMPUTE WS-TIME = WS-END - WS-START.
IF WS-TIME >1000
GO TO PROCESS-ORDERS-EXIT.
EXEC SQL
FETCH GET_ORDERS INTO :WS-ORDER-NBR,:WS-AMOUNT
END-EXEC.
DISPLAY WS-ORDER-NBR, WS-AMOUNT.
PROCESS-ORDERS-EXIT.
EXIT.
$DATA01.ECSRC 138> RUN ECTEXE
00000000010000001111HAS BEEN PROCESSED
00000000020000002222HAS BEEN PROCESSED
00000000030000003333HAS BEEN PROCESSED
>>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(4,4444);
---1 row(s) inserted.
>>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(5,5555);
---1 row(s) inserted.
>>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(6,6666);
---1 row(s) inserted.
$DATA01.ECSRC 138> RUN ECTEXE
00000000010000001111HAS BEEN PROCESSED
00000000020000002222HAS BEEN PROCESSED
00000000030000003333HAS BEEN PROCESSED
00000000040000004444HAS BEEN PROCESSED
00000000050000005555HAS BEEN PROCESSED
00000000060000006666HAS BEEN PROCESSED
>>SELECT * FROM SOS.ECUI.ORDERS;
---0 row(s) selected.
>>SELECT * FROM SOS.ECUI.ORDERS;
ORDER_NBR AMOUNT STATUS
----------- ----------- ------
1 1111 N
2 2222 N
3 3333 N
---3 row(s) selected.
TEST-PB-UPDATE.
PERFORM BEGIN-TRAN THRU BEGIN-TRAN-EXIT.
MOVE 0 TO WS-AMOUNT, WS-ORDER-NBR.
EXEC SQL
DECLARE GET_ORDERS_UPD CURSOR WITH HOLD FOR
SELECT ORDER_NBR, AMOUNT FROM
(UPDATE STREAM(SOS.ECUI.ORDERS) SET STATUS =‘Y‘
WHERE STATUS =‘N‘) AS ORDERS
END-EXEC.
EXEC SQL
OPEN GET_ORDERS_UPD
END-EXEC.
ACCEPT WS-START FROM TIME.
MOVE 0 TO WS-TIME.
PERFORM PROCESS-ORDERS-UPD THRU PROCESS-ORDERS-UPD-EXIT
UNTIL WS-TIME >10000.
EXEC SQL
CLOSE GET_ORDERS_UPD
END-EXEC.
PERFORM END-TRAN THRU END-TRAN-EXIT.
TEST-PB-UPDATE-EXIT.
EXIT.
/
PROCESS-ORDERS-UPD.
ACCEPT WS-END FROM TIME.
COMPUTE WS-TIME = WS-END - WS-START.
EXEC SQL
FETCH GET_ORDERS_UPD INTO
:WS-ORDER-NBR,
:WS-AMOUNT
END-EXEC.
DISPLAY WS-ORDER-NBR, WS-AMOUNT," HAS BEEN PROCESSED".
PROCESS-ORDERS-UPD-EXIT.
EXIT.
$DATA01.ECSRC 44> RUN ECTEXE
00000000010000001111 HAS BEEN PROCESSED
00000000020000002222 HAS BEEN PROCESSED
00000000030000003333 HAS BEEN PROCESSED
>>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(4,4444);
---1 row(s) inserted.
>>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(5,5555);
---1 row(s) inserted.
>>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(6,6666);
---1 row(s) inserted.
$DATA01.ECSRC 44> RUN ECTEXE
00000000010000001111 HAS BEEN PROCESSED
00000000020000002222 HAS BEEN PROCESSED
00000000030000003333 HAS BEEN PROCESSED
00000000040000004444 HAS BEEN PROCESSED
00000000050000005555 HAS BEEN PROCESSED
00000000060000006666 HAS BEEN PROCESSED
>> SELECT * FROM SOS.ECUI.ORDERS;
ORDER_NBR AMOUNT STATUS
----------- ----------- ------
1 1111 Y
2 2222 Y
3 3333 Y
4 4444 Y
5 5555 Y
6 6666 Y
Using Publis/Subscribe function in COBOL
标签:
原文地址:http://www.cnblogs.com/ECNB/p/4611267.html