码迷,mamicode.com
首页 > 其他好文 > 详细

Using Publis/Subscribe function in COBOL

时间:2015-06-30 19:58:05      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

Publis/Subscribe function in COBOL

>> Embeded Delete

1. Use table SOS.ECUI.ORDERS.

  1. INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(1,1111);
  2. INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(2,2222);
  3. INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(3,3333);
2. In COBOL program
This program will declare a cursor, and then disply it. if all the records processed, it will wait for the new added record, until 1minute.
  1.        TEST-PB.
  2.  
  3.            PERFORM BEGIN-TRAN        THRU BEGIN-TRAN-EXIT.
  4.  
  5.            MOVE 0 TO WS-AMOUNT.
  6.            MOVE SPACES TO WS-ORDER-NBR.
  7.  
  8.            EXEC SQL
  9.            DECLARE GET_ORDERS CURSOR WITH HOLD FOR
  10.            SELECT ORDER_NBR, AMOUNT FROM
  11.            (DELETE FROM STREAM(SOS.ECUI.ORDERS)
  12.            FOR SKIP CONFLICT ACCESS) AS ORDERS
  13.            END-EXEC.
  14.  
  15.            EXEC SQL
  16.            OPEN GET_ORDERS
  17.            END-EXEC.
  18.  
  19.            ACCEPT WS-START FROM TIME.
  20.            MOVE 0 TO WS-TIME.
  21.            PERFORM PROCESS-ORDERS THRU PROCESS-ORDERS-EXIT
  22.                                  UNTIL WS-TIME >10000.
  23.  
  24.            EXEC SQL
  25.            CLOSE GET_ORDERS
  26.            END-EXEC.
  27.  
  28.            PERFORM END-TRAN          THRU END-TRAN-EXIT.
  29.  
  30.        TEST-PB-EXIT.
  31.            EXIT.
  32.  
  33.       /
  34.        PROCESS-ORDERS.
  35.  
  36.            ACCEPT WS-END FROM TIME.
  37.  
  38.            COMPUTE WS-TIME = WS-END - WS-START.
  39.            IF WS-TIME >1000
  40.               GO TO PROCESS-ORDERS-EXIT.
  41.  
  42.            EXEC SQL
  43.            FETCH GET_ORDERS INTO :WS-ORDER-NBR,:WS-AMOUNT
  44.            END-EXEC.
  45.  
  46.            DISPLAY WS-ORDER-NBR, WS-AMOUNT.
  47.  
  48.        PROCESS-ORDERS-EXIT.
  49.            EXIT.

3. Compile it and exec it

  1. $DATA01.ECSRC 138> RUN ECTEXE
  2. 00000000010000001111HAS BEEN PROCESSED
  3. 00000000020000002222HAS BEEN PROCESSED
  4. 00000000030000003333HAS BEEN PROCESSED
4. Insert more records into table
  1. >>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(4,4444);
  2.  
  3. ---1 row(s) inserted.
  4. >>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(5,5555);
  5.  
  6. ---1 row(s) inserted.
  7. >>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(6,6666);
  8.  
  9. ---1 row(s) inserted.

5. In the program session, the new added records can be processed.

  1. $DATA01.ECSRC 138> RUN ECTEXE
  2. 00000000010000001111HAS BEEN PROCESSED
  3. 00000000020000002222HAS BEEN PROCESSED
  4. 00000000030000003333HAS BEEN PROCESSED
  5. 00000000040000004444HAS BEEN PROCESSED
  6. 00000000050000005555HAS BEEN PROCESSED
  7. 00000000060000006666HAS BEEN PROCESSED
6. check the table
  1. >>SELECT * FROM SOS.ECUI.ORDERS;
  2.  
  3. ---0 row(s) selected.
 

>> Embeded Update

1. Table ORDERS, STATUS is "N"

  1. >>SELECT * FROM SOS.ECUI.ORDERS;
  2.  
  3. ORDER_NBR    AMOUNT       STATUS
  4. -----------  -----------  ------
  5.  
  6.           1         1111  N
  7.           2         2222  N
  8.           3         3333  N
  9.  
  10. ---3 row(s) selected.
2. In COBOL Program
  1.        TEST-PB-UPDATE.
  2.  
  3.            PERFORM BEGIN-TRAN        THRU BEGIN-TRAN-EXIT.
  4.  
  5.            MOVE 0 TO WS-AMOUNT, WS-ORDER-NBR.
  6.  
  7.            EXEC SQL
  8.            DECLARE GET_ORDERS_UPD CURSOR WITH HOLD FOR
  9.            SELECT ORDER_NBR, AMOUNT FROM
  10.            (UPDATE STREAM(SOS.ECUI.ORDERS) SET STATUS =‘Y‘
  11.            WHERE STATUS =‘N‘) AS ORDERS
  12.            END-EXEC.
  13.  
  14.            EXEC SQL
  15.            OPEN GET_ORDERS_UPD
  16.            END-EXEC.
  17.  
  18.            ACCEPT WS-START FROM TIME.
  19.            MOVE 0 TO WS-TIME.
  20.            PERFORM PROCESS-ORDERS-UPD THRU PROCESS-ORDERS-UPD-EXIT
  21.                                  UNTIL WS-TIME >10000.
  22.  
  23.            EXEC SQL
  24.            CLOSE GET_ORDERS_UPD
  25.            END-EXEC.
  26.  
  27.            PERFORM END-TRAN          THRU END-TRAN-EXIT.
  28.  
  29.        TEST-PB-UPDATE-EXIT.
  30.            EXIT.
  31.  
  32.       /
  33.        PROCESS-ORDERS-UPD.
  34.  
  35.            ACCEPT WS-END FROM TIME.
  36.            COMPUTE WS-TIME = WS-END - WS-START.
  37.  
  38.            EXEC SQL
  39.            FETCH GET_ORDERS_UPD INTO
  40.                 :WS-ORDER-NBR,
  41.                 :WS-AMOUNT
  42.            END-EXEC.
  43.  
  44.            DISPLAY WS-ORDER-NBR, WS-AMOUNT,"  HAS BEEN PROCESSED".
  45.  
  46.        PROCESS-ORDERS-UPD-EXIT.
  47.            EXIT.
Notice that:
*** ERROR[4001] Column "N" is not found.  Tables in scope: SOS.ECUI.ORDERS.  Def
ault schema: SOS.ECUI.
 
*** WARNING[4104] If a character literal was intended, you must use the single q
uote delimiter: ‘N‘. The use of double quotes causes SQL/MX to interpret "N" as
a delimited identifier column name.
 

3. Run program

  1. $DATA01.ECSRC 44> RUN ECTEXE
  2. 00000000010000001111  HAS BEEN PROCESSED
  3. 00000000020000002222  HAS BEEN PROCESSED
  4. 00000000030000003333  HAS BEEN PROCESSED
4. Insert more records into the table
  1. >>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(4,4444);
  2.  
  3. ---1 row(s) inserted.
  4. >>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(5,5555);
  5.  
  6. ---1 row(s) inserted.
  7. >>INSERT INTO ORDERS(ORDER_NBR,AMOUNT) VALUES(6,6666);
  8.  
  9. ---1 row(s) inserted.
5. In program session, we can see the new added records
  1. $DATA01.ECSRC 44> RUN ECTEXE
  2. 00000000010000001111  HAS BEEN PROCESSED
  3. 00000000020000002222  HAS BEEN PROCESSED
  4. 00000000030000003333  HAS BEEN PROCESSED
  5. 00000000040000004444  HAS BEEN PROCESSED
  6. 00000000050000005555  HAS BEEN PROCESSED
  7. 00000000060000006666  HAS BEEN PROCESSED
6. Check the STATUS, it has been updated to "Y"
  1. >> SELECT * FROM SOS.ECUI.ORDERS;
  2.  
  3. ORDER_NBR    AMOUNT       STATUS
  4. -----------  -----------  ------
  5.  
  6.           1         1111  Y
  7.           2         2222  Y
  8.           3         3333  Y
  9.           4         4444  Y
  10.           5         5555  Y
  11.           6         6666  Y
 
 





Using Publis/Subscribe function in COBOL

标签:

原文地址:http://www.cnblogs.com/ECNB/p/4611267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!