× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On Saturday, April 17, 2004, at 04:32 AM, mwalter@xxxxxxxxxxxxxxx wrote:


It would be nice to have some sort of 'CONSTRUCTOR' for Service Programs.

On Saturday, April 17, 2004, at 04:52 AM, Bob Cozzi wrote:


And a Destructor as well!

But you aren't constructing anything! Invoking a service program is not the same as creating a NEW object even if you think it is similar. What you are asking for is a function to be run automatically when a service program is invoked for the first time and a corresponding function to be invoked when the service program
ends. Tracking first invocation is easy enough but there is no way to determine when a service program ends except by ending the activation group.


It's not as if this is difficult to do. The tools already exist. Here is a module you can compile into a service program. It contains a constructor that is invoked 'automatically' on the first invocation. It also sets up a destructor which will be invoked automatically when the activation group ends. Although the producer must understand the magic it is hidden from the consumer thus providing the effect you desire.

H NOMAIN

/copy rpgleinc,leenv

     D function        PR
     D  parm1                        10I 0
     D  parm2                       100
     D constructor     PR              N
     D destructor      PR
     D   actGrpMark                        LIKE(UINT4_)
     D   reason                            LIKE(UINT4_)
     D   resultCode                        LIKE(UINT4_)
     D   userRtnCode                       LIKE(UINT4_)

D constructed S N INZ(*OFF)

     P function        B                   EXPORT
     D function        PI
     D  parm1                        10I 0
     D  parm2                       100

     C                   IF        NOT(constructed)
     C                   CALLP     constructor
     C                   ENDIF

      * Do function stuff
     C     'Function'    DSPLY

     C                   RETURN
     P function        E

     P constructor     B
     D constructor     PI              N

      * Do constructor stuff such as:
      * -- Open files
      * -- Allocate storage
      * -- etcetera

* Register activation group exit
C CALLP CEE4RAGE( %PADDR('DESTRUCTOR') : *OMIT )


     C                   EVAL      constructed = *ON
     C     'Constructor' DSPLY

     C                   RETURN    constructed
     P constructor     E

     P destructor      B
     D destructor      PI
     D   actGrpMark                        LIKE(UINT4_)
     D   reason                            LIKE(UINT4_)
     D   resultCode                        LIKE(UINT4_)
     D   userRtnCode                       LIKE(UINT4_)

      * Do destructor stuff
      * -- Close files
      * -- Clean up storage
      * -- etcetera

     C                   EVAL      constructed = *OFF
     C     'Destructor'  DSPLY

     C                   RETURN
     P destructor      E

Here is a trivial test program:

     D function        PR
     D  parm1                        10I 0
     D  parm2                       100

     D p1              S             10I 0
     D p2              S            100

C CALLP function( p1 : p2 )

     C                   RETURN
     C                   SETON                                        LR

Compile both modules, create a service program from the first module using EXPORT(*ALL), create a program from the second module and bind it to the service program using ACTGRP(*NEW), then call the program. You'll see that the constructor is invoked when function() is called, and the destructor is invoked when the program ends.

I don't see any need for compiler support to implement this all they will provide is the invocation mechanism. You still have to write the code to implement the so-called constructor and destructor. I see no practical difference between the above example and special *CONSTRUCTOR/*DESTRUCTOR procedures.

Regards,
Simon Coulter.
---------------------------------------------------------------------
Arterial Software
IBM Tower
Level 3, 60 City Road
Southgate Victoria 3006
Australia
http://www.arterialsoftware.com
+61 3 9421 5911 (Phone)
+61 3 9428 3729 (Fax)
---------------------------------------------------------------------
This message together with any attachment is intended for the use of
the person to whom it is addressed and contains information that is
privileged and confidential.  If you are not the intended recipient,
or the employee or agent responsible for its delivery to the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of it is strictly prohibited. Please notify us if you have
received it in error, and otherwise take all necessary steps to delete
it from any transient or permanent storage device or medium and notify
us by e-mail at "support@xxxxxxxxxxxxxxxxxxxx".

Any views expressed in this e-mail and any files transmitted with it
are those of the individual sender, except where the sender
specifically states them to be the views of Arterial Software.

Arterial Software does not represent or warrant that the attached files
are free from computer viruses or other defects. The user assumes all
responsibility for any loss or damage resulting directly or indirectly
from the use of any attached files.
----------------------------------------------------------------------



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.