number = QUEUED()
DO number
PULL element
SAY element
END
Exercise - Using the Data Stack
Write an exec that puts the letters T, S, O, E on the data stack in such a way that
they spell “TSOE” when removed. Use the QUEUED built-in function and the PULL
and SAY instructions to help remove the letters and display them. To put the letters
on the stack, you can use the REXX instructions PUSH, QUEUE, or a combination
of the two.
ANSWER
Possible Solution 1
/******************************** REXX *****************************/
/* This exec uses the PUSH instruction to put the letters T,S,O,E,*/
/* on the data stack in reverse order. */
/*******************************************************************/
PUSH 'E' /**************************/
PUSH 'O' /* Data in stack is: */
PUSH 'S' /* (fourth push) T */
PUSH 'T' /* (third push) S */
/* (second push) O */
number = QUEUED() /* (first push) E */
DO number /**************************/
PULL stackitem
SAY stackitem
END
Possible Solution 2
/******************************** REXX *****************************/
/* This exec uses the QUEUE instruction to put the letters T,S,O,E,*/
/* on the data stack in that order. */
/*******************************************************************/
QUEUE 'T' /***************************/
QUEUE 'S' /* Data in stack is: */
QUEUE 'O' /* (first queue) T */
QUEUE 'E' /* (second queue) S */
/* (third queue) O */
DO QUEUED() /* (fourth queue) E */
PULL stackitem /***************************/
SAY stackitem
END
Manipulating the Data Stack
138
z/OS V1R1.0 TSO/E REXX User’s Guide