MainframeSupports
tip week 20/2008:

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:

01 irxexcom pic x(8) value 'IRXEXCOM'.

01 shvBlock.
02 ShvNext pic s9(9) binary.
02 ShvUser pic s9(9) binary.
02 ShvCode pic x(1).
02 ShvRet pic x(1).
02 X pic x(2).
02 ShvBufl pic s9(9) binary.
02 ShvNamA pointer.
02 ShvNamL pic s9(9) binary.
02 ShvValA pointer.
02 ShvValL pic s9(9) binary.

01 rexxVarName pic x(8).
01 rexxVarValue pic x(100).
01 rexxVarNameL pic s9(9) binary.
01 rexxVarValueL pic s9(9) binary.

01 nilValue pic s9(9) binary.
01 filler redefines nilValue.
02 nil pointer.

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.

move 0 to nilValue

move 'REXXVAR' to rexxVarName
move 7 to rexxVarNameL
move 'HI REXX FROM COBOL' to rexxVarValue
move 18 to rexxVarValueL

move 0 to ShvNext
move 0 to ShvUser
move 'S' to ShvCode
move x'00' to ShvRet
move x'0000' to X
move 0 to ShvBufl
set shvNamA to address of rexxVarName
move rexxVarNameL to shvNamL
set shvValA to address of rexxVarValue
move rexxVarValueL to shvValL

call irxexcom using irxexcom nil nil shvBlock

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.

Previous tip in english        Sidste danske tip        Tip list