Examples

The following is an example of an assembler program using AXREXX to invoke a REXX exec to parse the output of DISPLAY JOBS to obtain the address of the ASTE of *MASTER*.
GETASTE  CSECT ,                                               
GETASTE  AMODE 31                                              
GETASTE  RMODE 31                                              
*                                                              
*  TITLE: GetAste                                              
*                                                              
*  Function:  Obtain the address of MASTER's aste by invoking  
*     an exec to parse the output of DISPLAY JOBS,*MASTER*.    
*     The following exec takes a jobname as an input argument  
*     and sets the variable OutAste@.                          
*                                                              
*                                                              
* NUMERIC DIGITS 25                                            
* ARG InJobname                                                
* MyCmd = 'D JOBS,' || Strip(InJobname);                       
* Result =  AXRCMD(MyCmd,OutputVar.,10);                       
* IF Result = 0 THEN                                           
*   DO;                                                        
*     OutAste@ = ' '                                           
*     DO LineNum = 1 TO OutputVar.0 WHILE(OutASTE@=' ');       
*       PARSE var OutputVar.LineNum 'ASTE=' OutAste@           
*     END;                                                     
*     IF OutAste@ = ' ' THEN                                   
*       DO;                                                    
*         MyRetcode = 8;                                       
*         OutAste@ = 0;                                        
*       END;                                                   
*     ELSE                                                     
*        MyRetcode = 0;                                        
*   END;                                                       
* ELSE                                                         
*   DO;                                                        
*     MyRetcode = 12;                                          
*     OutAste@ = 0;                                            
*   END;                                                       
* EXIT MyRetcode;     
*                                                                    
*                                                                    
*                                                                    
************************************************************
         BAKR  14,0                                                  
         USING GETASTE,12                                            
         LR    12,15                                                 
         MODID BR=YES                                                
         XC  MyArgLst,MyArgLst    Clear the ArgLst header            
         XC  MyVarLst,MyVarLst    Clear the VarLst header            
         XC  MyArgEn1,MyArgEn1    Clear the Arg entry                
         XC  MyVarEn1,MyVarEn1    Clear the Var entry                
         LA  2,MyArgLst                                              
         USING AxrArgLst,2                                           
         MVC AxrArgLstId,MyAxrArgLstAcro                             
         LA  5,AxrArgLstCurVer                                       
         ST  5,AxrArgLstVer       Initialize the version             
         LA  5,kNumArgs           Obtain the number of arguments     
         STH  5,AxrArgLstNumber   Store the number of arguments      
         DROP 2                                                      
         USING AxrArgEntry,2                                         
         LA  2,MyArgEn1          Addressability to first arg entry   
         LA  5,kMaster                                               
         ST  5,AXRARGADDRLOW      Store address of jobname (*master*)
         OI  Start of changeAXRARGINPUTFLGS1End of change,AXRARGINPUT Indicate input arg         
         LA  5,L'kMaster          Obtain length of arg               
         ST  5,AXRARGLENGTH       Store length of arg in entry       
         MVI AxrArgType,AxrArgTypeChar  Store type of arg            
         DROP 2                                                      
         LA  2,MyVarLst                                              
         USING AxrArgLst,2                                           
         MVC AxrArgLstId,MyAxrVarLstAcro       
         LA  5,AxrArgLstCurVer                                          
         ST  5,AxrArgLstVer       Initialize the version                
         LA  5,kNumVars           Obtain the number of variables        
         STH  5,AxrArgLstNumber   Store the number of variables         
         DROP 2                                                         
         USING AxrArgEntry,2                                            
         LA  2,MyVarEn1           Addressability to 1st var entry       
         LA  5,OutAste@                                                 
         ST  5,AXRARGADDRLOW      Store output argument                 
         LA  5,OutArgName                                               
         ST  5,AXRARGNameADDRLOW Store address of name of output var    
         MVI AxrArgNameLength,L'OutArgName                              
         OI  Start of changeAXRARGINPUTFLGS1End of change,AXRARGOutput   Indicate output var        
         MVI AxrArgType,AxrArgTypeHexString     Indicate hex string     
         LA  5,L'OutAste@         Obtain length (in bytes)              
         SLL 5,1       Mult by 2 - length is in hex digits (not bytes)  
         ST  5,AxrArgLength       Store length in var entry             
         DROP 2                                                         
         AXREXX REQUEST=EXECUTE,NAME=kEXECNAME,REXXARGS=MyArgLst,      *
               REXXVARS=MyVarLst,REXXDIAG=MyAxrDiag                     
         LTR   15,15                                                    
         JNZ   FailLabel                                                
         USING AxrDiag,2                                                
         LA    2,MyAxrDiag                                              
         TM    AxrDiagFlgs1,AxrDiagNoExecRetCode                        
         JNZ   FailLabel                                                
         L     15,AxrDiagExecRetCode                                    
         LTR   15,15                                                    
         JNZ   FailLabel                                                
*        Everything looks good.  Process OutAste@ here                  
FailLabel DS   0H                                                       
* Perform error checking                                                
* OutAste@ should contain Master's ASTE address                         
         PR                                                             
kNumArgs EQU   1
kNumVars EQU   1
         DS    0D
MyAxrArgLstAcro DC AL4(AxrArgLstAcro)
MyAxrVarLstAcro DC AL4(AxrVarLstAcro)                               
kExecName DC CL8'GETASTE '                                          
kMaster  DC CL8'*MASTER*'                                           
OUTArgName DC CL8'OUTASTE@'                                         
MyArgLst DS CL(AXRARGLST_LEN)                                       
MyArgEn1 DS CL(AXRARGENTRY_LEN)                                     
MyVarLst DS CL(AXRARGLST_LEN)                                       
MyVarEn1 DS CL(AXRARGENTRY_LEN)                                     
MyAxrDiag DS CL(AXRDIAG_LEN)                                        
OutAste@ DS A                                                       
         AXRZARG DSECT=YES,AXRARGLST=YES,AXRARGENTRY=YES,AXRDIAG=YES
         END                                                                              
The following shows an example of a program which sets up an extended MCS console to receive messages passed back from the exec. In this case, the exec sends back a portion of the output of a system command.
MCSOPER CSECT ,                                                       
MCSOPER AMODE 31                                                      
MCSOPER RMODE 31                                                      
*                                                                     
*  TITLE: MCSOPER                                                     
*                                                                     
*  Function:  Set up an EMCS console.  Invoke AXREXX, passing         
*     it the console name and pass 2 arguments to the exec:           
*     the command text to invoke and the number of lines of the       
*     output of the command return to the invoker's EMCS console.     
*                                                                     
*                                                                     
*  /* REXX */                                                         
* ARG InCmdText,InNumLines                                            
* AxrCmdRc = AXRCMD(InCmdText,Start of changeMsg.End of change,4);                                
* IF AxrCmdRc = 0 THEN                                                
*   DO;                                                               
*     ConnectId = 'FirstLine'                                         
*     CALL AXRMLWTO 'Start of cmd output','ConnectId','C'             
*     DO I = 1 TO InNumLines                                          
*       CALL AXRMLWTO Msg.i,'ConnectId','D'                           
*     END;                                                            
*     CALL AXRMLWTO  ,'ConnectId','E'     /* End line */              
*   END;                                                              
* EXIT AxrCmdRc                                                       
*                                                                     
*                                                                     
*                                                                     
**********************************************************************
         BAKR  14,0                                                   
         USING MCSOPER,12 
         LAE   12,0(12,0)                                            
         LR    12,15                                                  
         MODID BR=YES                                                 
         XC  MyArgLst,MyArgLst 
         XC  MyArgEn1,MyArgEn1                                          
         XC  MyArgEn2,MyArgEn2                                          
         LA  2,MyArgLst                                                 
         USING AxrArgLst,2                                              
         MVC AxrArgLstId,kAxrArgLstAcro                                 
         LA  5,AxrArgLstCurVer                                          
         ST  5,AxrArgLstVer       Initialize the version                
         L    5,kNumArgs           Obtain the number of arguments       
         STH  5,AxrArgLstNumber   Store the number of arguments         
         DROP 2                                                         
         USING AxrArgEntry,2                                            
         LA  2,MyArgEn1          Addressability to first arg entry      
         LA  5,kInCmdText                                               
         ST  5,AXRARGADDRLOW      Store address of jobname (*master*)   
         OI  Start of changeAXRARGINPUTFLGS1End of change,AXRARGINPUT Indicate input arg            
         LA  5,L'kINCmdText         Obtain length of arg                
         ST  5,AXRARGLENGTH       Store length of arg in entry          
         MVI AxrArgType,AxrArgTypeChar  Store type of arg               
         DROP 2                                                         
         USING AxrArgEntry,2                                            
         LA  2,MyArgEn2           Addressability to 2nd arg entry       
         LA  5,InNumLines                                               
         ST  5,AXRARGADDRLOW      Store number lines                    
         OI  Start of changeAXRARGINPUTFLGS1End of change,AXRARGInput    Indicate input arg         
         MVI AxrArgType,AxrArgTypeUnsigned      Indicate hex string     
         LA  5,L'InNumLines       Obtain length (in bytes)              
         ST  5,AxrArgLength       Store length in arg entry             
         DROP 2                                                         
         MODESET MODE=SUP                                               
         MCSOPER   REQUEST=ACTIVATE,CONSID=MyConsid,TERMNAME=kTERM,    *
               NAME=kConsname,MCSCSA=MyMcsCsa@,MCSCSAA=MyMcsCsaAlet,   *
               MsgEcb=MyMsgEcb                                          
         AXREXX REQUEST=EXECUTE,NAME=kEXECNAME,REXXARGS=MyArgLst,      *
               REXXDIAG=MyAxrDiag,CONSDATA=YES,CONSNAME=kConsName,     *
               CART=kCart                                               
         SAC 512                                                    
         SYSSTATE ASCENV=AR                                         
         MCSOPMSG  REQUEST=GETMSG,CONSID=MyConsid                   
*        Process the MDB pointed to Reg1/AR1                        
*        The MDB will contain the messages issued by the exec       
         SYSSTATE ASCENV=P                                          
         SAC 0                                                      
         MCSOPER   REQUEST=DEACTIVATE,NAME=kConsName                
         MODESET MODE=PROB                                          
         PR                                                         
kExecName DC CL8'MCSOPER '                                          
kConsname DC CL8'TEST1   '                                          
kTerm    DC  CL8'TEST1'                                             
kCart    DC F'1'                                                    
kNumArgs DC F'2'                                                    
kAxrArgLstAcro DC AL4(AxrArgLstAcro)                                
kInCmdText DC CL12'D JOBS,ALL  '                                    
InNumLines DC F'10'                                                 
MyConsid DS F                                                       
MyMsgEcb DS F                                                       
MyMcsCsa@ DS F                                                      
MyMcsCsaAlet DS F                                                   
MyAxrDiag DS CL(AXRDIAG_LEN)                                        
MyArgLst DS CL(AXRARGLST_LEN)                                       
MyArgEn1 DS CL(AXRARGENTRY_LEN)                                     
MyArgEn2 DS CL(AXRARGENTRY_LEN)                                     
         AXRZARG DSECT=YES,AXRDIAG=YES,AXRARGLST=YES,AXRARGENTRY=YES
         END