Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#28 AcuCobol feature: USE at PROGRAM {START} {END}

unclassified
pending
nobody
None
1
2014-10-20
2014-05-15
massimo
No

I propose this feature from Acucobol. It is very useful to have a clean way to code some "constructor" and "tear down" methods in a cobol program. These statements are coded in the DECLARATIVES section.
syntax: USE AT PROGRAM {START}{END }

Trivial example:

 Procedure Division.
  declaratives.  
   setup section.  use at program start.
      perform open-files.
   setup-ex.  exit.  
   tearDown section.  use at program end.    
      perform close-files.
   tearDown-ex.  exit.    
  end declaratives.

Acucobol manual excerpt:

When placed in a program's Declarative section, a Format 6 USE statement creates a START or END procedure for the program. Each program may contain no more than one START and one END procedure. Every program in a run unit may contain such procedures.
A START procedure executes immediately before the first normal COBOL statement in the Procedure Division when the program is in its initial state. The START procedure executes only once regardless of the number of times the program is entered, until the program is returned to its initial state (e.g. via CANCEL). A START procedure executes regardless of which entry point is used to start the program when a program contains multiple entry points (see the ENTRY statement).
An END procedure executes immediately before a program is placed into its initial state or it is about to leave memory, providing the program has been entered at least once. An END procedure executes before open files are closed as part of the shutdown process.
You can call the C$EXITINFO library routine from an END procedure to obtain information about the program exit. For example, you can determine if the exit is the result of a STOP RUN or a fatal error. Please refer to Appendix I in ACUCOBOL-GT Appendices for detailed information about this library routine.
It is normal for an END procedure to execute when the program that contains it is inactive. For example, if a program is canceled, its END procedure will execute when the program is otherwise inactive. For this reason, an END procedure should not reference data passed to the program through Linkage. This data will not be defined in many cases.
END procedures are executed during abnormal shutdown when possible. However, certain operating system errors (such as a fatal memory error) cannot be caught in some operating environments, and in these cases the END procedures will not be able to execute. If a fatal error occurs during an END procedure, that procedure stops, but other unprocessed END procedures execute where possible.
When multiple END procedures execute (e.g. STOP RUN when several programs are in memory), the order of their execution is arbitrary.

Related

Discussion: Introducing the ASSERT statement
Discussion: Introducing the ASSERT statement

Discussion

  • Simon Sobisch
    Simon Sobisch
    2014-05-20

    Valid request, patches are welcome.
    The first work can be found in [r268]. The sources currently compile with a warning, START and END procedures ARE NOT called at runtime.

    If anyone likes to do this (or you're getting/paying someone to code this) here is an "how-to":

    • little change to parser.y: add correct emit_entry calls
    • changes to codegen.c: call _START entry on first call if entry is available
    • changes to call.c: call _END entry before CANCEL (add "has_end_entry" in module structure)

    Simon

     

    Related

    Commit: [r268]