Search code examples
db2mainframezosrexx

Obtain output in REXX from DB2 Command


I would like to use Rexx capture the output from the following commands:

QUEUE "-DIS DATABASE(*) SPACENAM(*) RESTRICT(CHKP,COPY)"
QUEUE "END"                                             
ADDRESS TSO "DSN SYSTEM(DB2D)"

Is there any way to obtain the name of tables output by the above commands that are displayed into a variable or some other construct so the data can be manipulated programmatically?

Regards


Solution

  • The OUTTRAP function should trap output from the DSN command. OUTTRAP is designed to TRAP the OUTput of most TSO commands. Output is placed in a variable (normally a stem variable) that you supply. (Certain TSO commands cannot be trapped; this is discussed elsewhere in the TSO/E REXX Reference.)

    Taking your code as supplied above, we can cobble together this:

    ORC = OUTTRAP('O.')             /* preserve prior setting of OUTTRAP */
    QUEUE "-DIS DATABASE(*) SPACENAM(*) RESTRICT(CHKP,COPY)"
    QUEUE "END"                                             
    ADDRESS TSO "DSN SYSTEM(DB2D)"
    CALL OUTTRAP ORC                /* restore OUTTRAP setting */
    DO #O = 1 TO O.0                /* The 0 entry by convention has the number of records */
      /* You can PARSE, analyze, or do whatever here */
      SAY "O."'#O "='"O.#O"'"         /* example */
    END #O                          /* end the loop */
    

    OUTTRAP is a very powerful function when writing scripts in TSO/E REXX.