PL/I

PL/I

PL/I

 View Only
Expand all | Collapse all

DCL statements not allowed outside a procedure?

  • 1.  DCL statements not allowed outside a procedure?

    Posted Sun August 25, 2019 04:14 PM

    The LRM indicates that a PACKAGE can contain PROCEDUREs and DECLARATIONS; and in fact, this simple example appears to work just fine:

     

    *Process NUMBER;

     p: package;

     

     test: proc options(main);

       display("I'm TEST");

     end;

     

     t2: proc;

       display("Hey - I'm T2!!");

     end;

     

      /* declaration outside a PROC */

      declare x fixed bin(31); 

     

     end p;

     

     

     

    The LRM further says that if a PACKAGE statement is not present, one is effectively inserted after the first *PROCESS statement(although it doesn't make clear what is done if there is no *PROCESS statement, and does not provide the name that might be used for scoping of the PROCs/DCLs in that inserted PACKAGE statement.  From the LRM:

     

    "If the source contains a PACKAGE statement, there must be at most only one set of *PROCESS statements and those must be the first statements in the source. If the source contains no PACKAGE statement, the compiler effectively inserts one after the first set of *PROCESS statements and the source might contain multiple external procedures separated by groups of *PROCESS statements."

     

    Furthermore - regarding the package name, the LRM has this restriction:  "All PACKAGE names must be unique within a linked module."   So, if you have more than one compilation unit with the inserted PACKAGE statement, what name is used?  Do inserted PACKAGE statements have unique names because they have "no name"?

     

    The description of the inserted PACKAGE statement rather explicitly does not seem to allow for DECLARATION statements, only multiple EXTERNAL PROCEDURES.   So, if we have the same example with the PACKAGE statement removed, it does not compile:

     

    *Process NUMBER;

     

     test: proc options(main);

       display("I'm TEST");

     end;

     

     t2: proc;

       display("Hey - I'm T2!!");

     end;

     

      /* declaration outside a PROC */

      declare x fixed bin(31); 

     

    The compiler complains with:

     

    e.pli(12:2) : IBM1861I S All statements other than DECLARE, DEFAULT and PROCEDURE statements must be contained inside a PROCEDURE.

     

    I'm not quite sure I understand the difference in these two situations... especially if there is an inserted (but somehow different) PACKAGE statement in the second example?  Is it simply the case that the inserted PACKAGE statement only allows for multiple PROCEDURES and no DECLARATION statements?   Maybe because there is a missing package name?

     

     

    tdr


  • 2.  Re: DCL statements not allowed outside a procedure?

    Posted Tue September 24, 2019 05:27 PM

    The implicit package is just meant as an aid to understanding (which it seemingly hasn't done very well :). Maybe this would help clarify this:

     

    Without an explicit package, all statements other than *PROCESS statements must be inside PROC-END statements (as was true of the old PL/I compilers).

     

    If there is no explicit package statement, there is, conceptually, an implicit package statement that wraps all the PROC-END statements and that has the same name as the first PROC statement. This is the value that would be returned by the PACKAGENAME built-in function

    pelderon