MainframeSupport tip about Calling LOAD modules from REXX MainframeSupportstip week 17/2006:REXX is the favourite for many TSO programmers worldwide, because it is easy andfast to write a REXX program. REXX integrates beautiful with ISPF and TSO and manysoftware products has REXX interfaces. These interfaces make it possible to accessDB2, MQ and many other software products from REXX. In this tip I will tell you aboutdifferent methods of calling a LOAD module from REXX. These LOAD modules typically arethe result of compiling programs written in PL/1, COBOL, VAG, C, assembler or otherlanguages requiring a compilation.You can use three different methods to call a LOAD module in REXX.
You can executean ADDRESS LINK 'LMODNAME'. Replace LMODNAME with the name of the LOAD module you wantto execute and REXX will immediately execute this LOAD module. You can transfer parametersto the LOAD module with ADDRESS LINK, but they will not be understood by 99% of all LOADmodules made for MVS.
Therefore I recommend you not to use ADDRESS LINK if you wantto transfer parameters to your LOAD module.The second method is invoked using ADDRESS LINKMVS 'LMODNAME PARM'. Please replaceLMODNAME with your LOAD module name and replace PARM with the name of the REXX variablecontaining the parameter you want to transfer to the LOAD module. An example:/.
Syntax errors to syserr mostly. The first S10-syntax does not halt the COBOL program, but it does spew REXX errors to syserr. The second is properly trapped, by the signal on instruction, but uses interpret. The third and fourth are back to spewing to syserr.This is because top-level scripts can't really be trapped, as they need to generate valid tokenized code for the REXX engine. We were thinking the trigger could point to a REXX exec that would. 'call' the COBOL program to complete an update on another table.
REXX./MYPARM = 'HELLO WORLD'ADDRESS LINKMVS 'MYPGM MYPARM'This piece of REXX code works in exactly the same way asEXEC PGM=MYPGM,PARM='HELLO WORLD' works in JCL.The third method is activated using ADDRESS LINKPGM 'LMODNAME PARM1 PARM2 PARM3.' Andis the recommended method of calling all kinds of LOAD modules that are in compliance withthe MVS standard linkage convention. All COBOL LOAD modules are in compliance as well asmost LOAD modules for MVS software. Unfortunately PL/1 does not comply unless you dosomething special. If you want to call MQ directly from REXX it can be done using ADDRESSLINKPGM.
Let me illustrate the use of ADDRESS LINKPGM with a COBOL example:IDENTIFICATION DIVISION.PROGRAM-ID. MYCOBPGM.LINKAGE SECTION.77 PARM1 PIC X(8).77 PARM2 PIC S9(4) BINARY.PROCEDURE DIVISION USING PARM1, PARM2.You can call this COBOL program from REXX in the following way:/. REXX./PARM1 = 'FIRSTVAL'PARM2 = D2C(1000,2)ADDRESS LINKPGM 'MYCOBPGM PARM1 PARM2'The variable PARM1 is easy to transfer because a character string in REXX is build inthe same way as in COBOL, but it is important to use the same number of bytes in REXXas the varable occupies in COBOL. The variable PARM2 is a so-called halfword (SMALLINT inDB2, FIXED BIN(15) in PL/1). A halfword occupies two bytes, therefore you must build acharacter string of two bytes in REXX containing the value you want to transfer. This isdone by using the REXX built in function D2C.
If PARM2 were a fullword in the example,you had to use D2C(1000,4) instead. By using ADDRESS LINKPGM it is very easy to createdrivers in REXX that calls programs written in other programming languages.The three methods of calling a LOAD module from REXX each has a sister called ATTACHinstead of LINK which becomes ATTACH, ATTACHMVS and ATTACHPGM. ATTACH. creates a new TCBfor the LOAD module to be executed in instead of executing it in the callers TCB.I have not tried ATTACH. so I cannot explain exactly how it works. In MVS terms ATTACH isthe method used to execute more than one LOAD module in parallel in the same address spacethough I am pretty sure that REXX will not execute anything in parallel.
When you useATTACH. or LINK. the REXX variable RC will contain the return-code set by the calledLOAD module.