Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Practical RPG: Queueing, Part I: Data Queues

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Practical RPG: Queueing, Part I: Data Queues

    Back in the early 90's, I had a need to do depth-first and breadth-first searches on some data. These algorithms are relatively simple with recursion; not so much in iterative languages like RPG or COBOL. Wound up developing a way to use an array to simulate a stack, and came up with an iterative algorithm.

    Anyway, at the time I didn't know about data queues. A *LIFO data queue *is* a stack. Push and Pop are simply QDNDDTAQ and QRCVDTAQ. Even without recursion, using a data queue for the stack might have made for simpler code than what I came up with. Faster is debatable, but definitely simpler.

  • #2
    I used a data queue in As400 to communicate with a server computer running a Windows system.
    In windows i referenced the cwbx.dll in the ToolBox equipment of Client Access.
    In As400 I created a simple data queue.

    If you plan to use a data queue, please keep in mind:
    - the receiving machine could be slower than the sending one
    - the data queue has a maximum capacity

    So I want to highly recommend to insert a MONMSG CPF950A after each send data to a queue, followed by a waiting command and a retry.
    Otherwise you will experiment a loss of data.

    Here below is an example of a safe procedure to send data and receive data from the queue.
    I hope to have been helpful.


    PGM PARM(&FN)
    /* Simple sequential data queue */
    /* Queue name */
    DCL VAR(&QN) TYPE(*CHAR) LEN(10) VALUE('QUEUE')
    /* Library of the queue */
    DCL VAR(&QL) TYPE(*CHAR) LEN(10) VALUE('QTEMP')
    /* String lenghth to manage */
    DCL VAR(&FL) TYPE(*DEC) LEN(5 0) VALUE(80)
    /* Data to manage */
    DCL VAR(&FN) TYPE(*CHAR) LEN(80)
    /* Wait */
    DCL VAR(&WT) TYPE(*DEC) LEN(5 0)

    /* Create the data QUEUE with length = 80 */
    CHKOBJ OBJ(QTEMP/QUEUE) OBJTYPE(*DTAQ)
    MONMSG MSGID(CPF9801) EXEC(DO)
    CRTDTAQ DTAQ(QTEMP/QUEUE) MAXLEN(80)
    ENDDO
    /* Send data to the queue */
    DLY1: CALL PGM(QSNDDTAQ) PARM(&QN &QL &FL &FN)
    MONMSG MSGID(CPF9801) /* The queue doesn't exist */
    MONMSG MSGID(CPF950A) EXEC(DO)
    SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('The +
    queue is full. Please wait...') +
    TOPGMQ(*EXT) MSGTYPE(*STATUS)
    DLYJOB DLY(10) /* 10 seconds */
    GOTO CMDLBL(DLY1)
    ENDDO
    /* Receive data from the queue */
    OVER: CALL PGM(QRCVDTAQ) PARM(&QN &QL &FL &FN &WT)
    ENDPGM
    Last edited by Mirco Cortesi; 06-07-2012, 05:04 AM.

    Comment

    Working...
    X