NEWSTACK and DELSTACK in OPSREXX
search cancel

NEWSTACK and DELSTACK in OPSREXX

book

Article ID: 259710

calendar_today

Updated On:

Products

OPS/MVS Event Management & Automation

Issue/Introduction

We are working on a conversion from Opera to OPS/MVS.  In working with one of the REXX programs we run under Opera, it fails with a RC=20 on commands NEWSTACK and DELSTACK.  However, the default stack seems to work.  I can do an EXECIO into the stack and pull from it.  

 

NEWSTACK and DELSTACK are not documented as an incompatible with OPS/REXX.  Should they work?  We can convert the program to use stem variables as a substitute for the stack.  Are there any other options?

Environment

OPS/MVS

Resolution

Unfortunately, NEWSTACK and DELSTACK will not work in an OPS/REXX environment.

In an OPS/REXX environment, a "new" private stack with visibility only to the current REXX is created by default each time a command is issued that generates output or when a QUEUE instruction is issued to push data onto the stack manually. This would be equivalent to the NEWSTACK instruction.

The DELSTACK equivalent can be accomplished by using the OPSCLEDQ() function described here:

https://techdocs.broadcom.com/us/en/ca-mainframe-software/automation/ca-ops-mvs-event-management-and-automation/14-0/reference-information/command-and-function-reference/ops-rexx-built-in-functions/opscledq-function.html

The following OPS/REXX program demonstrates:

/* PUSH DATA TO THE STACK */                                      
QUEUE 'LINE 1'                                                    
QUEUE 'LINE 2'                                                    
QUEUE 'LINE 3'                                                    
                                                                  
SAY 'NUMBER OF LINES QUEUED IS 'QUEUED() /* LINES ON STACK IS NOW 3 */
                                                                  
SAY ''                                                            
                                                                  
/* PULL AND DISPLAY LINES */                                      
                                                                  
DO QUEUED()                                                       
 PULL X                                                           
 SAY X                                                            
END                                                               
                                                                  
/* STACK IS NOW EMPTY - ADD THREE MORE LINES TO THE STACK... */   
                                                                  
SAY ''                                                            
                                                                  
QUEUE 'LINE A'                                                    
QUEUE 'LINE B'                                                    
QUEUE 'LINE C'                                                    
                                                                  
SAY 'NUMBER OF LINES QUEUED IS 'QUEUED() /* 3 LINES BACK ON STACK */                       
                                                                  
SAY ''                                                            
                                                                  
/* CLEAR (DELETE) THE STACK CONTENTS USING OPSCLEDQ() FUNCTION */ 
                                                                  
X = OPSCLEDQ()                                                    
                                                                  
SAY 'NUMBER OF LINES QUEUED IS 'QUEUED()      
                                                 
/* THE STACK HAS BEEN CLEARED, 0 LINES ON THE STACK NOW */                

Here is the output from the OPS/REXX program execution:

OPS0996I NUMBER OF LINES QUEUED IS 3
OPS0996I                            
OPS0996I LINE 1                     
OPS0996I LINE 2                     
OPS0996I LINE 3                    
OPS0996I                            
OPS0996I NUMBER OF LINES QUEUED IS 3
OPS0996I                            
OPS0996I NUMBER OF LINES QUEUED IS 0

When using the same stack multiple times within the same OPS/REXX program, care should be taken to issue the OPSCLEDQ() function between each use to ensure the stack is cleared of any leftover data from the prior invocation.

If the REXX is executed as a TSO REXX rather than as an OPS/REXX, then NEWSTACK/DELSTACK should still work, but the recommendation is to use OPS/REXX as demonstrated above to take advantage of its efficiency.