#42 Global variables

open
nobody
None
5
2011-04-04
2011-04-04
Anonymous
No

I learned REXX on IBM mainframes in the 80s. I have a problem. I'd like to read a file in an external subroutine and stuff what I've read in variables so that the calling routine can pick them up or possibly another routine. The doc mentions variable pools (1,2,3,..., SYSTEM and ENVIRONMENT). It states "It is therefore possible to get and set the value of a variable in a higher call level procedure from the current one without the need to EXPOSE the variable. " on page 122-123 of the manual. How do I do this? I see POOLID() and VALUE(). Can I use VALUE as an lvalue?
Also, can I invent my own pool name?

Thanks, Pierre.
prf51@videotron.ca

Discussion

  • Phil Downs
    Phil Downs
    2011-04-04

    Hi Pierre,
    Sounds to me like you may be best served by using an external stack. Depending on the volume of data you want to pass to another process you can create your stack ‘records’ as single fields or compress several elements into a single stack ‘record’.

    Here’s three functional code snippets, to demonstrate an external stack:
    (No housekeeping or error traps for clarity)

    A:
    /* ************** REXX ***********
    use exteranal queue named Rexx
    and say how many recs in it
    ******************************** */
    PrevQ=RxQueue('Set', 'Rexx@192.168.0.2:5757')
    say queued() 'elements in Q'
    Exit 0

    B:
    /* ************** REXX ***********
    use exteranal queue named Rexx
    and put something in it
    ******************************** */
    PrevQ=RxQueue('Set', 'Rexx@192.168.0.2:5757')
    do i=1 to 10
    queue 'number'||i
    end
    Exit 0

    C:
    /* ************** REXX ***********
    use exteranal queue named Rexx
    and read all recs
    ******************************** */
    PrevQ=RxQueue('Set', 'Rexx@192.168.0.2:5757')
    do i=1 to queued()
    pull info
    say i info
    end
    Exit 0

    A) This lets you know how many records are in the external queue called Rexx on 192.168.0.2 port 5757

    B) Puts 10 things into the stack

    C) Reads the stack, displays all records emptying the stack in the process

    The IP of the machine to put the stack on can be your local PC or a dedicated networked server if you’re using many large stacks.

    You can use any name you like for the stack, I used ‘Rexx’ in this example.

    If you run A, then B, then A, then C, then A – you’ll see the concept
    If you run A, then several B’s over a period, then a C – You’ll start to see the power of using external stacks.

    Read from page 191 in the manual for more info.

    Hope this helps a little.

    Phil.