Topic
5 replies Latest Post - ‏2014-12-02T15:40:29Z by Robin400
JustAFreeName
JustAFreeName
10 Posts
ACCEPTED ANSWER

Pinned topic Where to place "ON ENDFILE" within a PACKAGE?

‏2014-08-11T09:51:58Z |

Hi all.

I need an advice. Maybe someone can give a hint.

I coded a z/OS Batchprogramm using some files.

The coding pattern was "nested procedures", like this

PGM: PROCEDURE OPTIONS (MAIN)

DCL FILE...

ONE ENDFILE EOF = '1'B;

P1: PROCEDURE

END P1;

P2: PROCDURE

END P2;

END PGM;

OK. I studied the "Programming Guide" where I found the Topic "nested procedures vs. package"

I switched to the package style.

PKG: PACKAGE  EXPORTS( PGM )

DCL FILE...

ON ENDFILE EOF = '1'B;

PGM: PROCEDURE OPTIONS( MAIN)

END PGM;

P1: PROCEDURE

END P1;

P2: PROCDURE

END P2;

END PKG;

OK. The compiler was not happy. The "ON ENDFILE EOF = '1'B;" was flagged. => No executable statments outside a procedure.

I tried different alternative. The only working one was to place the ON ENDFILE as the first statement in the PROCEDURE PGM.

As I have total 4 files, each has ON UNDEFIED and ON ENDFILE, the placement of these ON-Blocks in the Code of my main procedure PGM

hurts my aesthetic feeling of code.

Can anyone give a hint where to plac file related ON Blocks when using PACKAGE()?

Thx for any feedback.

JustAFreeName 

 

 

 

 

 

 

 

 

  • PeteKidwell
    PeteKidwell
    6 Posts
    ACCEPTED ANSWER

    Re: Where to place "ON ENDFILE" within a PACKAGE?

    ‏2014-08-11T12:09:19Z  in response to JustAFreeName

    The "No executable statements outside a procedure" error is not new, and not related to the PACKAGE style of coding.  Even in your original example, the entire PGM block is itself a main procedure, and that is where all code, including the ON-blocks, resides.

    I would personally recommend keeping the ON ENDFILE blocks as close to the file I/O as possible.  If your file processing pervades your entire main program, then that is the perfect place for the ON ENDFILE block.  If you have all file I/O placed in a single (sub-) procedure, then put the ON ENDFILE code there.

  • PeteKidwell
    PeteKidwell
    6 Posts
    ACCEPTED ANSWER

    Re: Where to place "ON ENDFILE" within a PACKAGE?

    ‏2014-08-11T12:09:28Z  in response to JustAFreeName

    The "No executable statements outside a procedure" error is not new, and not related to the PACKAGE style of coding.  Even in your original example, the entire PGM block is itself a main procedure, and that is where all code, including the ON-blocks, resides.

    I would personally recommend keeping the ON ENDFILE blocks as close to the file I/O as possible.  If your file processing pervades your entire main program, then that is the perfect place for the ON ENDFILE block.  If you have all file I/O placed in a single (sub-) procedure, then put the ON ENDFILE code there.

    • JustAFreeName
      JustAFreeName
      10 Posts
      ACCEPTED ANSWER

      Re: Where to place "ON ENDFILE" within a PACKAGE?

      ‏2014-08-11T13:10:05Z  in response to PeteKidwell

      Hi Pete.

      Thx for the fast reply. I thought about your explanation, and your a right. Using the "nested pattern" the FILE declaration and the ON ENDFILE are within the outer most procedure.

      My current rating: the straight forward approach, simply copy parts from the "nested pattern" and add a PACKAGE declaration, doesnot result in a well structured package design. The common place "think first, code second" is still valid.

      Issue can be closed.

      Thx, JustAFreeName

       

       

        

    • brataj
      brataj
      7 Posts
      ACCEPTED ANSWER

      Re: Where to place "ON ENDFILE" within a PACKAGE?

      ‏2014-08-12T15:49:52Z  in response to PeteKidwell

      Hi folks,

      ON units are associated with a procedure's stack frame, being activated when the statement is encountered, and deactivated when the procedure returns.

      While the declarations inside the package but outside the procedures contained therein may under the covers be associated with an implicit procedure for the initialization of static fields which is called when the package is loaded, if the compiler did allow the ON statement, it would not be active afterwards.

      Bernie

  • Robin400
    Robin400
    31 Posts
    ACCEPTED ANSWER

    Re: Where to place "ON ENDFILE" within a PACKAGE?

    ‏2014-12-02T15:40:29Z  in response to JustAFreeName

    The usual place for and ON ENDFILE statement is  just before the

    GET or READ statement that reads data from the file.

     

    Incidentally, you need to specify the name of the file after the keyword ENDFILE.