Back in week 17/2006 I wrote about calling load modules from REXX. One of the tricky details were that you must convert REXX variables into structures suitable for the load module. It would be far more elegant to communicate using the REXX variables themselves. And of course this is possible although the interface is a bit clumsy. Fortunately the clumsy details may be hidden away in a submodule. Here is a working example of how to create a REXX variable in COBOL to be used in the REXX program after calling the COBOL program.
All communication with REXX variables from other programming languages is done using the module IRXEXCOM. This module requires some pretty cryptical parameters which you may read all about here. To make it work from COBOL you must use the following declarations in the COBOL working-storage section:
The use of all these variables is documented in the following piece of code which must be placed i procedure division. Please forgive me for the missing indentations.
The first move statement needs to be executed only once in each program execution. The following four move statements must be repeated for each REXX variable you want to create. RexxVarName is assigned the the name of the REXX variable, rexxVarNameL is assigned the length of the REXX variable name, rexxVarValue is assigned the value of the REXX variable and rexxVarValueL is assigned the number of characters in the assigned value. Please notice that only alphanumeric values may be used. Binary or packed values will fail miserably as they will be interpreted byte by byte into their alphanumeric equivalent. REXX will translate numeric character strings into numeric REXX variables when the rules for numeric values in REXX are fulfilled. So do not forget to convert packed or binary values into a string of readable numeric characters before assignment to a REXX variable.
The rest of the move statements I will recommend you to execute before each call to IRXEXCOM because IRXEXCOM may change the value of the assigned variables. The last four moves before executing the call are the most interesting since it is here the creation or update of the REXX variable is prepared.
The last statement is the call to IRXEXCOM. It is on purpose I have used a variable to hold the name of the called module. In this manner you do not need to link IRXEXCOM into your COBOL load module because it is called dynamically. Another important detail is the use of the variable nil. If you replace nil with the COBOL word NULL the call to IRXEXCOM will fail according to different sources I have read on the internet. It does not say anything about this in the IBM documentation about IRXEXCOM.
IRXEXCOM is able to do a lot more than updating REXX vaiables. It may also be used to read and remove REXX variables and a lot of other stuff. Please find out for yourself how to implement those other features. Now you are aware of the main ingredients and know where you can find additional documentation. If you love PL/I more than COBOL I hope you are able to translate the COBOL code into a general purpose PL/I procedure. Have fun.