Using Publis/Subscribe function in COBOL

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

来自为知笔记(Wiz)

时间: 2024-10-11 13:25:58

Using Publis/Subscribe function in COBOL的相关文章

javascript设计模式——Publish/Subscribe

我们先引出问题的所在,这里使用一个订单系统: 在一个电子商务系统中,现在我们有订单模块,和信息模块两个主要模块,当下单成功时,我们用要发送订单信息的给客户. 下面是一个简单的解决办法,我们在一个类中调用另一个类的方法. // 订单类,存储订单的所有变量和函数 function Order( goods ){ this.goods = goods; } Order.prototype = { done: function(){ // 订单完成代码 this.sendSuccessMsg(); },

多个 ng-app 中 Controllers & Services 之间的通信

原文发布在个人独立博客上,链接:http://pengisgood.github.io/2016/01/31/communication-between-multiple-angular-apps/ 通常情况下,在 Angular 的单页面应用中不同的 Controller 或者 Service 之间通信是一件非常容易的事情,因为 Angular 已经给我们提供了一些便利的方法:$on,$emit,$broadcast. 在这里用一个简单的例子来演示一下这三个方法的用途,完整版代码也可以参考这里

javascript设计模式

javascript设计模式 阅读目录 什么是设计模式 单体模式: 工厂模式: 单例模式 观察者模式(发布订阅模式) 策略模式 模板模式 代理模式 外观模式 设计模式太多了,貌似有23种,其实我们在平时的工作中没有必要特意去用什么样的设计模式,或者你在不经意间就已经用了设计模式当中的一种.本文旨在总结平时相对来说用的比较多的设计模式. 回到顶部 什么是设计模式 百度百科: 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用设计模式是

[RxJS] Observables can complete

The Observer object has the functions next() and error(). In this lesson we will see the other (and last) function available on observers, complete(), and its purpose. Completion is an important concept, as we will see later on. Imagine if you want t

app.listen(3000)与app是不一样的

前者是server代码如下 Server { domain: null, _events: { request: { [Function] domain: undefined, _events: [Object], _maxListeners: undefined, setMaxListeners: [Function: setMaxListeners], getMaxListeners: [Function: getMaxListeners], emit: [Function: emit],

Javascript设计模式之观察者模式

首先说一下观察者模式的应用场景 观察者的使用场合就是:当一个对象的改变需要同时改变其它对象,并且它不知道具体有多少对象需要改变的时候,就应该考虑使用观察者模式.(Tom大叔) 具体说一下这个观察者模式,就是一个发报纸的过程.我们订阅了报纸,在报社的数组里加上我们的名字(不仅是名字了是一个带我们名字的处理函数),这是订阅事件:报社才不管你订没订报纸,他只管给他数组里的人发报纸:我们在编码的时候只监听发报纸的事件,订不订报纸,谁订报纸,都是你的事,就不在放在监听的事件里了,于是就有了减少监听的优化:

KnockoutJS-监控属性(observables)

ko基于以下核心特性: 监控属性(observables)和依赖跟踪(dependency tracking) 声明式绑定(declarative bingdings) 模板(templating) MVVM MVVM(Mode-View-ViewModel)是一种构建UI交互的设计模式,将复杂的UI 交互分为三个部分: 模型(Model):应用的存储数据模型.该模型表征业务领域的对象和操作,且独立于UI.使用ko时通常通过ajax请求服务器端来读写存储数据模型. 视图模型(ViewModel)

《javascript 设计模式》 第15章 观察者模式 -- 学习笔记

定义: 在事件驱动的环境中,比如浏览器这种持续寻求用户关注的环境中,观察者模式(又名发布者-订阅者 “publisher-subscriber" 模式) 是一种管理人与其任务之间的关系(确切的讲,是其对象及其行为和状态之间的关系 )的得力工具.用javascript的 话来说,这种模式的实质 就是你可以程序中某个对象的状态进行观察并且在其发生改变时能够得到通知. 观察者API: var Publisher=function(){ this.subscribers=[]; } //推送方法 Pub

【读书笔记】读《JavaScript设计模式》之观察者模式

一.定义 在事件驱动的环境中,比如浏览器这种持续寻求用户关注的环境中,观察者模式(又名发布者-订阅者(publisher-subscripber)模式)是一种管理人与其任务之间的关系(确切地讲,是对象及其行为和状态之间的关系)的得力工具.用JavaScript的话来说,这种模式的实质就是你可以对程序中某个对象的状态进行观察,并且在其发生改变时能够得到通知. 二.例子 我们需要一个发布者的构造函数,它为该实例定义了一个类型为数组的属性,用来保存订阅者的引用. function Publisher(