MainframeSupports
tip week 18/2012:

Recently I thought of an old trick in PL/I concerning parameter transfer. My first thought was that the trick must be documented in the manuals, but I could not find any description of it. The PL/I language reference is far away from being easy to read and use, but I suspect the trick is described somewhere. My next step was to try it. And it still works just as I remembered it.

And here is what the trick is all about:

DCL a CHAR(1);
a = 'A';
CALL aProc(a);
PUT SKIP LIST('A=''' !! a !! '''');
a = 'A';
CALL aProc((a));
PUT SKIP LIST('A=''' !! a !! '''');

aProc: PROC(parm);
  DCL parm CHAR(1);

  parm = 'X';

END aProc;

The result of executing the above piece of code looks like this:

A='X'
A='A'

The first call to APROC looks quite ordinary and A is as expected changed to the value X by APROC. After the second call A has not been changed. By putting a CALL parameter in parenthesis, PL/I creates a so-called dummy argument and the value of the parameter is transferred instead of the address of the parameter. If you are familiar with COBOL you will notice that putting a parameter in paranthesis is the same as writing BY VALUE after a parameter in a COBOL CALL.

Previous tip in english        Forrige danske tip        Tip list