MainframeSupports
tip week 21/2007:

Have you ever been in a situation where you wished to issue a TSO command from a COBOL or PL/I program? When such a wish arises it normally ends with a REXX program instead. So why do you wish to issue TSO commands from COBOL or PL/I? Well, I often wish to make a dynamic allocation of a dataset from within COBOL and PL/I. To do this many installations have coded an assembler program which uses SVC 99 to make dynamic allocations. These assembler programs are often limited to a specific task and do not have the flexibility of a TSO ALLOC command. If I can issue TSO ALLOC from COBOL or PL/I, what stops me from performing other TSO commands like DELETE. And suddenly you have a lot of new possibilities.

The road to TSO from compiling programming languages goes through the TSOLNK program also known as IKJEFTSR. How to call TSOLNK/IKJEFTSR from COBOL and PL/I is described in chapter 23 in the manual TSO/E Programming Services on the internet. This link is to a four years old manual, but the interface is rarely changed so it will work for both new and old installations. Probably there exists an "easy to call" edition of TSOLNK on your installation, but unfortunately such editions can be very hard to find. The person who made it has retired and no one else knowns what the name of the "easy to call" edition is or how you must call it. This is why I will give you examples of how you can call TSOLNK.

In COBOL you might code a call like this:

* WORKING STORAGE DECLARATIONS
 01  PARM1 PICTURE S9(9) COMP.
 01  PARM2 PICTURE X(80).
 01  PARM3 PICTURE S9(9) VALUE +80 COMP.
 01  PARM4 PICTURE S9(9) VALUE +0 COMP.
 01  PARM5 PICTURE S9(9) VALUE +0 COMP.
 01  PARM6 PICTURE S9(9) VALUE +0 COMP.

* STATEMENTS IN PROCEDURE DIVISIONS
     MOVE 261 TO PARM1
     MOVE 'ALLOC FI(MYDDNAME) DA(''MY.OWN.DATASET'') SHR' TO PARM2
     CALL 'TSOLNK' USING PARM1 PARM2 PARM3 PARM4 PARM5 PARM6
     IF RETURN-CODE NOT = 0
       DISPLAY 'ALLOC FAILED WITH TSO RETURN-CODE = ' RETURN-CODE
     END-IF

The variable PARM1 consists of a lot of flags which might be set in many different ways. I use the value 261 because it works fine for me. If you get into trouble when using this value or you are too curious you should consult the manual. PARM2 must contain the TSO command and PARM3 the length of the command. COBOL does not support varying length character variables, so you have to declare the PARM2 variable large enough to contain the longest TSO command you want to issue. In the example I use 80 as the length, but 43 will also work fine. Values below 43 in the example will fail, because TSOLNK will only consider the first PARM3 characters as being part of the TSO command. PARM4, PARM5 and PARM6 are different return codes, but the real TSO return code is returned in RETURN-CODE even though the manual does not inform you about this. If you want more informations regarding PARM4, PARM5 or PARM6, you must read in the manual.

In PL/I you might code the call like this:

DCL PARM1 FIXED BIN(31);
DCL PARM2 CHAR(80);
DCL PARM3 FIXED BIN(31);
DCL PARM4 FIXED BIN(31);
DCL PARM5 FIXED BIN(31);
DCL PARM6 FIXED BIN(31);
DCL TSOLNK EXT ENTRY OPTIONS(ASM INTER RETCODE);

PARM1 = 261;
PARM2 = 'ALLOC FI(MYDDNAME) DA(''MY.OWN.DATASET'') SHR';
PARM3 = 43;
CALL TSOLNK(PARM1, PARM2, PARM3, PARM4, PARM5, PARM6);
IF PLIRETV() ^= 0
THEN
  DISPLAY('ALLOC FAILED WITH TSO RETURN-CODE = ' !! PLIRETV());

The variables PARM1, PARM2 and PARM3 are declared in exactly the same way as in COBOL. Even though PL/I support varying length character strings you cannot use them when calling TSOLNK. In this example I have set PARM3 to 43, but 80 will also work. PARM4, PARM5 and PARM6 will contain exactly the same values after the call as they will after a call from COBOL and the real TSO return code is assigned to the PL/I variable PLIRETV() (which works just like RETURN-CODE in COBOL).

To make the examples work the programs have to be executed using the TSO command processor. If the program contains SQL statements then the TSO command processor is very likely to be invoked as DSN requires TSO in order to work. Otherwise you will have to create a TSO step in order to execute your program.

Previous tip in english        Sidste danske tip        Tip list